Skip to content

Add sync wrapper, examples, and tests#7

Merged
gregsvo merged 2 commits into
mainfrom
feature/sync-wrapper
Jun 8, 2026
Merged

Add sync wrapper, examples, and tests#7
gregsvo merged 2 commits into
mainfrom
feature/sync-wrapper

Conversation

@gregsvo

@gregsvo gregsvo commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
  • Adds postmark.sync — a synchronous wrapper around the async clients, so the SDK can be used without async/await
  • Reorganizes all examples into examples/async/ and examples/sync/
  • 31 additional tests: tests/test_sync_client.py

The library is async-first, but users in scripts, Flask apps, and Jupyter notebooks often want a simpler synchronous API. The new postmark.sync module provides this without duplicating any business logic.

How it works: A single daemon thread with a persistent asyncio event loop is started on first import. Each sync call submits a coroutine to that loop via asyncio.run_coroutine_threadsafe() and blocks the calling thread until it completes. The underlying httpx.AsyncClient stays alive between calls, so HTTP connections remain pooled.

@gregsvo gregsvo self-assigned this Jun 8, 2026
Comment thread tests/test_sync_client.py Dismissed
Comment thread examples/sync/outbound_messages/send_outbound_simple.py Fixed
Comment thread examples/sync/outbound_messages/send_sync_batch.py Fixed
Comment thread tests/test_sync_client.py Dismissed
@gregsvo gregsvo merged commit daccede into main Jun 8, 2026
7 checks passed
@gregsvo gregsvo deleted the feature/sync-wrapper branch June 8, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant