Skip to content

Add Async support with AsyncClient and AsyncOauthClient #5#14

Open
Deadpool2000 wants to merge 4 commits intoopenapi:mainfrom
Deadpool2000:fix-issue-25-3-new
Open

Add Async support with AsyncClient and AsyncOauthClient #5#14
Deadpool2000 wants to merge 4 commits intoopenapi:mainfrom
Deadpool2000:fix-issue-25-3-new

Conversation

@Deadpool2000
Copy link
Copy Markdown
Contributor

This PR addresses the issue where the SDK was blocking the event loop in async frameworks like aiohttp or FastAPI. I've added full asynchronous support and improved resource management across the board.

What's new?

  • Async Clients: Introduced
  1. AsyncClient
  2. AsyncOauthClient . These use httpx.AsyncClient under the hood to handle non-blocking I/O.
  • Context Manager Support: All clients (both sync and async) now support context managers (with and async with). This ensures that the underlying connection pool is properly closed after use, preventing resource leaks.

  • Simplified Imports: You can now import clients directly from the package root: from openapi_python_sdk import Client, AsyncClient

  • Better Tests: Added a new test suite for the async implementation using IsolatedAsyncioTestCase (standard in Python 3.10+).

Quick Usage Example

from openapi_python_sdk import AsyncClient
async with AsyncClient(token="YOUR_TOKEN") as client:
    data = await client.request(
        method="GET",
        url="https://api.example.com/endpoint"
    )

Verification

  • Ran existing 10 sync tests (all passing).
  • Added 4 new async tests covering authentication and generic requests (all passing).
  • Total coverage: 14/14 tests passing.

Updated the README.md with these usage examples to help users get started.

Let me know if you have any feedback!

@francescobianco
Copy link
Copy Markdown
Member

Thanks @Deadpool2000 , is it possible here

https://github.com/openapi/openapi-python-sdk/pull/14/changes#diff-5a9e4531489d6a691db89b4bd98d9cbb5fade7dbcd4719fa01e13a0198f81527

split all classes into different files based on files standard names?
class OauthClient:
class AsyncOauthClient:
class AsyncClient:

in a way to have more smallest files instead a single large file for code

@Deadpool2000
Copy link
Copy Markdown
Contributor Author

Thanks for the great suggestion! I completely agree that splitting the classes is a much cleaner approach.

I've just pushed an update where I refactored the code to extract the classes into their own separate files based on their standard names:

  • oauth_client.py for OauthClient
  • async_oauth_client.py for AsyncOauthClient
  • async_client.py for AsyncClient

To make sure this doesn't break any existing functionality or user implementations, I updated __init__.py to export everything exactly as it was before. I also left backward-compatibility imports inside the original client.py file to ensure that anyone explicitly importing directly from openapi_python_sdk.client won't experience any breaking changes.

Let me know if this looks good to you or if you need any further adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants