Add AsyncClient wrapper and docs#419
Merged
Merged
Conversation
Introduce AsyncClient: a lightweight wrapper that makes existing synchronous synology-api classes awaitable by dispatching calls to the event loop's thread-pool (using loop.run_in_executor). Export async_client from the package, add README snippet and a new detailed getting-started async documentation page showing usage, concurrent calls, and async context-manager cleanup (auto-logout). No new dependencies required; aimed at enabling easy async usage of existing APIs.
Mark AsyncClient as finished in docs_status.yaml and expand inline documentation in synology_api/async_client.py. Added detailed docstrings for _make_async_callable, the AsyncClient class, and its __getattr__, __aenter__, and __aexit__ methods (parameters, returns, and behavior). No functional logic changes—these edits improve readability and debugging/tracing context.
Refactor and expand inline documentation in synology_api/async_client.py. Adds a full docstring to the async wrapper returned by _make_async_callable (including parameters and return), documents AsyncClient.__init__ (describing the sync instance), tightens class/docstring wording, clarifies __getattr__ summary, and expands __aenter__/__aexit__ docstrings with return/parameter details. These are documentation/formatting changes only and do not alter runtime behavior.
Owner
Author
|
@joeperpetua do you think is a good idea in first place? I know is not pure async but the easiest way to integrate... I think |
Collaborator
|
yeah why not, I will try to take a look today 😁 |
joeperpetua
approved these changes
Jun 30, 2026
Collaborator
|
Looks good! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗃️ Summary
Add an async client wrapper (
AsyncClient) that makes all existing synology-api classes awaitable without duplicating any business logic — a single 80-line module.🚀 Motivation & Problem Statement
synology-api currently uses synchronous
requestsfor all HTTP calls. Users building async applications (FastAPI, Telegram bots, Home Assistant integrations, etc.) cannot make non-blocking calls or run parallel API requests.Duplicating all API modules with
aiohttpwould create a maintenance nightmare — every new method would need to be written twice.This PR introduces a zero-duplication approach: a thread-pool wrapper that makes every existing sync method awaitable automatically.
🔧 Implementation Details
New files:
synology_api/async_client.py—AsyncClientclass. Wraps any sync class instance and intercepts all public method calls via__getattr__, dispatching them toloop.run_in_executor().Modified files:
synology_api/__init__.py— Addedasync_clientto module imports.README.md— Added "Async Client (beta)" section with usage examples.documentation/docs/getting-started/async.md— Full async documentation page with quick-start, concurrent calls, and cleanup examples.No dependencies added — uses only
asynciofrom the standard library.Tested against real NAS not all modules:
asyncio.gatherachieve ~3x speedup vs serial🏁 Checklist
tests/).pytest).black,flake8, etc.).pre-commitand addressed any linting issues.📝 Related Issue
new feature
🔨 Additional Notes
Known limitations:
run_in_executor), not nativeaiohttp. Adds ~1ms overhead per call. For applications making thousands of parallel requests, a future native async transport can be added without changing the API.AsyncClientinstance wraps one sync instance. For optimal performance, reuse the wrapped instance or enable shared sessions.Performance:
get_file_listcalls: 0.43s vs ~1.29s serial → ~3x speedup.Future work:
aiohttptransport as an opt-in backend (sameAsyncClientinterface, just swap the executor).😎 Test & Build Status
Tested against real Synology NAS (DSM 7.3.2):
👀 Screenshots / Media
none
Thank you for contributing! 🙏