@@ -88,15 +88,14 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
8888# Synchronous Example
8989from clerk_backend_api import Clerk
9090
91- s = Clerk(
91+ with Clerk(
9292 bearer_auth = " <YOUR_BEARER_TOKEN_HERE>" ,
93- )
93+ ) as s:
94+ res = s.email_addresses.get(email_address_id = " email_address_id_example" )
9495
95- res = s.email_addresses.get(email_address_id = " email_address_id_example" )
96-
97- if res is not None :
98- # handle response
99- pass
96+ if res is not None :
97+ # handle response
98+ pass
10099```
101100
102101</br >
@@ -108,13 +107,14 @@ import asyncio
108107from clerk_backend_api import Clerk
109108
110109async def main ():
111- s = Clerk(
110+ async with Clerk(
112111 bearer_auth = " <YOUR_BEARER_TOKEN_HERE>" ,
113- )
114- res = await s.email_addresses.get_async(email_address_id = " email_address_id_example" )
115- if res is not None :
116- # handle response
117- pass
112+ ) as s:
113+ res = await s.email_addresses.get_async(email_address_id = " email_address_id_example" )
114+
115+ if res is not None :
116+ # handle response
117+ pass
118118
119119asyncio.run(main())
120120```
@@ -365,19 +365,18 @@ Certain SDK methods accept file objects as part of a request body or multi-part
365365``` python
366366from clerk_backend_api import Clerk
367367
368- s = Clerk(
368+ with Clerk(
369369 bearer_auth = " <YOUR_BEARER_TOKEN_HERE>" ,
370- )
371-
372- res = s.users.set_profile_image(user_id = " usr_test123" , file = {
373- " file_name" : " example.file" ,
374- " content" : open (" example.file" , " rb" ),
375- " content_type" : " <value>" ,
376- })
370+ ) as s:
371+ res = s.users.set_profile_image(user_id = " usr_test123" , file = {
372+ " file_name" : " example.file" ,
373+ " content" : open (" example.file" , " rb" ),
374+ " content_type" : " <value>" ,
375+ })
377376
378- if res is not None :
379- # handle response
380- pass
377+ if res is not None :
378+ # handle response
379+ pass
381380
382381```
383382<!-- End File uploads [file-upload] -->
@@ -392,12 +391,11 @@ To change the default retry strategy for a single API call, simply provide a `Re
392391from clerk.utils import BackoffStrategy, RetryConfig
393392from clerk_backend_api import Clerk
394393
395- s = Clerk()
396-
397- s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" ,
398- RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
394+ with Clerk() as s:
395+ s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" ,
396+ RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
399397
400- # Use the SDK ...
398+ # Use the SDK ...
401399
402400```
403401
@@ -406,13 +404,12 @@ If you'd like to override the default retry strategy for all operations that sup
406404from clerk.utils import BackoffStrategy, RetryConfig
407405from clerk_backend_api import Clerk
408406
409- s = Clerk(
407+ with Clerk(
410408 retry_config = RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ),
411- )
412-
413- s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
409+ ) as s:
410+ s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
414411
415- # Use the SDK ...
412+ # Use the SDK ...
416413
417414```
418415<!-- End Retries [retries] -->
@@ -443,26 +440,25 @@ When custom error responses are specified for an operation, the SDK may also rai
443440``` python
444441from clerk_backend_api import Clerk, models
445442
446- s = Clerk(
443+ with Clerk(
447444 bearer_auth = " <YOUR_BEARER_TOKEN_HERE>" ,
448- )
449-
450- res = None
451- try :
452- res = s.clients.verify(request = {
453- " token" : " jwt_token_example" ,
454- })
455-
456- if res is not None :
457- # handle response
458- pass
459-
460- except models.ClerkErrors as e:
461- # handle e.data: models.ClerkErrorsData
462- raise (e)
463- except models.SDKError as e:
464- # handle exception
465- raise (e)
445+ ) as s:
446+ res = None
447+ try :
448+ res = s.clients.verify(request = {
449+ " token" : " jwt_token_example" ,
450+ })
451+
452+ if res is not None :
453+ # handle response
454+ pass
455+
456+ except models.ClerkErrors as e:
457+ # handle e.data: models.ClerkErrorsData
458+ raise (e)
459+ except models.SDKError as e:
460+ # handle exception
461+ raise (e)
466462```
467463<!-- End Error Handling [errors] -->
468464
@@ -475,13 +471,12 @@ The default server can also be overridden globally by passing a URL to the `serv
475471``` python
476472from clerk_backend_api import Clerk
477473
478- s = Clerk(
474+ with Clerk(
479475 server_url = " https://api.clerk.com/v1" ,
480- )
481-
482- s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
476+ ) as s:
477+ s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
483478
484- # Use the SDK ...
479+ # Use the SDK ...
485480
486481```
487482<!-- End Server Selection [server] -->
@@ -582,13 +577,12 @@ To authenticate with the API the `bearer_auth` parameter must be set when initia
582577``` python
583578from clerk_backend_api import Clerk
584579
585- s = Clerk(
580+ with Clerk(
586581 bearer_auth = " <YOUR_BEARER_TOKEN_HERE>" ,
587- )
588-
589- s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
582+ ) as s:
583+ s.miscellaneous.get_interstitial(frontend_api = " frontend-api_1a2b3c4d" , publishable_key = " pub_1a2b3c4d" )
590584
591- # Use the SDK ...
585+ # Use the SDK ...
592586
593587```
594588<!-- End Authentication [security] -->
0 commit comments