Synchronous Usage
This page documents the optional synchronous API provided by SyncMondayClient and the top-level helpers sync(), run_sync(), and to_sync().
When to use
You are not using
asynciobut want to call the async Monday API client.You prefer a blocking API surface while preserving the same service design.
What it provides
SyncMondayClient: mirrorsMondayClientservices but executes coroutine-returning methods on a dedicated background event loop.sync(): convenience factory that returns aSyncMondayClient.run_sync(): run a single coroutine to completion without managing an event loop.to_sync(): wrap anasync deffunction so you can call it synchronously.
Quick start
from monday import sync
client = sync(api_key='your_api_key')
items = client.items.query(item_ids=[123]) # blocking call
with client.use_api_key('another_token'):
board = client.boards.query(board_ids=[456])
client.close()
Header override contexts
use_headers(): Synchronous context manager that applies temporary headers to awaited calls made inside thewithblock.use_api_key(): Synchronous shorthand for overriding theAuthorizationheader.Contexts are stackable; later (inner) overrides take precedence on key conflicts.
with client.use_headers({'X-Trace': 'outer', 'Authorization': 'Bearer A'}):
# headers include X-Trace=outer, Authorization=Bearer A
with client.use_api_key('B'):
# headers include X-Trace=outer, Authorization=Bearer B
...
# back to Authorization=Bearer A
Performance and threading notes
Each
SyncMondayClientinstance owns a dedicated background event loop running in a daemon thread.Prefer reusing a single instance rather than repeatedly constructing/destroying clients.
The facade is intended for non-async callers. Avoid calling it from within an event loop running on the same thread.
Top-level helpers
from monday import run_sync, to_sync
async def compute(x):
return x * 2
assert run_sync(compute(21)) == 42
compute_sync = to_sync(compute)
assert compute_sync(21) == 42
Testing guidance
When writing tests for code using
SyncMondayClient, mock or stubAiohttpAdapter.post(orHttpxAdapter.post) to avoid real network calls.Use nested
use_headers()contexts to test header propagation and override precedence.
API reference
- class SyncMondayClient(config=None, *, api_key=None, url='https://api.monday.com/v2', version=None, headers=None, max_retries=4, transport='aiohttp')[source]
Bases:
objectSynchronous facade for MondayClient.
This class constructs an underlying async MondayClient and exposes the same services, but methods can be called synchronously. Internally, calls are executed on a background asyncio event loop.
- Parameters:
- __exit__(exc_type, exc, tb)[source]
Close the client when leaving a context manager block.
- Return type:
- post_request(query, variables=None)[source]
Execute a GraphQL request synchronously and return the response.
- use_api_key(api_key)[source]
Synchronous context manager to temporarily override Authorization header for calls inside the with block.
- sync(config=None, **kwargs)[source]
Create a synchronous Monday client.
This is a convenience factory for
SyncMondayClientfor users not using asyncio.- Parameters:
- Return type:
- Returns:
A ready-to-use
SyncMondayClientinstance.
- run_sync(awaitable)[source]
Run a coroutine/awaitable to completion in a temporary background loop.
Useful for one-off calls when you have an async function but are in a synchronous context.
Example
>>> async def fetch(): ... return 42 >>> run_sync(fetch()) 42
Note
If you need to call multiple async functions efficiently, prefer constructing a
SyncMondayClientand reusing its background loop, as this helper spins up a fresh loop each time.