Python Client: Is set_auth() thread-safe for concurrent requests?
Context:
I'm building a FastAPI backend that serves multiple concurrent users. To optimize Convex WebSocket connection overhead (~400-600ms per
new connection), I want to reuse a single ConvexClient instance across requests and call set_auth(user_token) per-request.
Current Setup:
Question:
Is ConvexClient.set_auth(token) thread-safe in the Python client (v0.7.0)?
Specifically:
• If Request A calls set_auth(token_A) followed by Request B calling set_auth(token_B) before A's query executes, will A's query use the
correct token?
• Does set_auth() mutate shared connection-level state, or is auth tracked per-query somehow?
What I'm seeing:
• Per-request clients work but have high latency (965ms per query)
• Shared client would reduce latency, but I need to confirm data isolation between users
What I'd like:
Either confirmation that shared client + per-request set_auth() is safe, OR recommended approach for connection pooling in multi-threaded
Python environments.
Thanks!
──────────────────────────────────────────
• Python client: 0.7.0
• Python: 3.13
2 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
It is crucial blocker for my app development. Can someone from convex team please guide?