@@ -31,16 +31,16 @@ import postmark
3131from dotenv import load_dotenv
3232
3333load_dotenv()
34- client = postmark.ServerClient(os.environ[" POSTMARK_SERVER_TOKEN" ])
3534
3635async def main ():
37- response = await client.outbound.send({
38- " sender" : " sender@example.com" ,
39- " to" : " recipient@example.com" ,
40- " subject" : " Hello from Postmark" ,
41- " text_body" : " Sent with the Postmark Python SDK." ,
42- })
43- print (f " Sent: { response.message_id} " )
36+ async with postmark.ServerClient(os.environ[" POSTMARK_SERVER_TOKEN" ]) as client:
37+ response = await client.outbound.send({
38+ " sender" : " sender@example.com" ,
39+ " to" : " recipient@example.com" ,
40+ " subject" : " Hello from Postmark" ,
41+ " text_body" : " Sent with the Postmark Python SDK." ,
42+ })
43+ print (f " Sent: { response.message_id} " )
4444
4545asyncio.run(main())
4646```
@@ -55,8 +55,16 @@ asyncio.run(main())
5555``` python
5656import postmark
5757
58- client = postmark.ServerClient(os.environ[" POSTMARK_SERVER_TOKEN" ])
59- account = postmark.AccountClient(os.environ[" POSTMARK_ACCOUNT_TOKEN" ])
58+ # Use as async context managers to ensure connections are closed
59+ async with postmark.ServerClient(os.environ[" POSTMARK_SERVER_TOKEN" ]) as client:
60+ ...
61+
62+ async with postmark.AccountClient(os.environ[" POSTMARK_ACCOUNT_TOKEN" ]) as account:
63+ ...
64+
65+ # Or call close() explicitly when done
66+ client = postmark.ServerClient(os.environ[" POSTMARK_SERVER_TOKEN" ])
67+ await client.close()
6068```
6169
6270## Development
0 commit comments