🚀 Feature: Native Asyncio Support for Python SDK
🔖 Feature description
I propose implementing native asyncio support for the Python SDK using a Unified Client architecture. Instead of introducing a separate AsyncClient or a package.aio submodule (which stalled previous attempts like PR #453), asynchronous capabilities should be integrated directly into the existing Client and Service classes.
Core Implementation:
- A single
Clientobject handles both workflows. - Every service method is generated in a "Dual-Mode" pair directly alongside each other:
- Synchronous:
def list(self, ...): - Asynchronous:
async def list_async(self, ...):
- Synchronous:
- We transition the underlying HTTP engine from
requeststohttpx, which natively supports both synchronous and asynchronous operations using an identical API shape, making the dual-mode generator templates trivial to maintain.
🎤 Pitch
The community has requested native Python async support for over two years (Issue #26). Implementing a unified "Dual-Mode" pattern solves the architectural friction that halted previous PRs:
- Maintainer Alignment: It addresses the exact feedback provided by core contributors in PR #453, who requested that async methods live alongside sync methods without requiring users to instantiate a whole new
AsyncClientclass. - Modern Developer Experience: Frameworks like FastAPI, Starlette, and Sanic are now standard. Developers must be able to
await client.users.list_async()natively without blocking the event loop or hacking togetherThreadPoolExecutors. - Zero Maintenance Drift: By utilizing Twig
parameterDispatchBlockfilters in the generator (similar to the new dual-mode C++ SDK), the synchronous and asynchronous methods are generated from the exact same spec source. They will never fall out of sync as the API evolves. - 100% Backwards Compatible: Existing code using
requestssemantics remains totally unaffected since standarddefmethods will work exactly as they did before.
👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [x] I have read the Code of Conduct
@bhardwajparth51 modern async io in python was introduced with php 3.5, which is quite breaking isnt it?
@ChiragAgg5k I checked pyproject.toml and it already requires python 3.9+, so we're well past the 3.5 introduction of asyncio. The dual-mode approach also keeps the exact same synchronous methods intact, so no existing code breaks.
@bhardwajparth51 got it, yes we can work on it then