Skip to content

Add asyncio support to the Python SDK#57

Draft
kvz wants to merge 26 commits into
py310-v2from
asyncio-v2
Draft

Add asyncio support to the Python SDK#57
kvz wants to merge 26 commits into
py310-v2from
asyncio-v2

Conversation

@kvz
Copy link
Copy Markdown
Member

@kvz kvz commented May 20, 2026

Why

Issue #9 asks for a Pythonic asyncio surface without changing sync callers. This PR adds a separate AsyncTransloadit API on top of the v2 runtime/security branch (#56) so async users can opt in without affecting the existing synchronous client.

This branch is also the first SDK companion for the API2 contract generator work in https://github.com/transloadit/api2/pull/7928. Low-level endpoint methods that the current Python transport can honestly express are generated from API2 endpoint contracts and verified byte-for-byte from API2.

What changed

  • Added transloadit.async_client.AsyncTransloadit with async versions of the existing client helpers.
  • Added async request/assembly/template helpers and a shared Response wrapper that works for both sync and async responses.
  • Added async context manager cleanup plus explicit aclose()/close().
  • Kept the sync Transloadit API compatible with existing callers.
  • Added generated low-level sync and async endpoint methods for the non-blocked API2 contract operations: Assembly create/replay/notifications, Template create/builtin/full helpers, priority job slot listing, and Template Credential CRUD/type/OAuth validation helpers. These methods live inside marked api2-generated-endpoints blocks so API2 can rewrite them directly.
  • Regenerated the endpoint blocks after API2 removed its separate Python SDK plan/snippet file. The generator now reads endpoint contracts directly, including endpoint-local compatibility hints for existing Python method names.
  • Hardened sync Assembly edge cases found by council review: non-resumable retries rewind seekable files or reject non-seekable streams, wait/resumable paths reject unexpected non-JSON responses when they cannot safely proceed, polling stays pinned to the original Assembly URL, and repeated poll rate limits are capped.
  • Made same-service API URL signing compare hostnames case-insensitively.

TUS/resumable tradeoff

  • Non-resumable uploads use aiohttp directly.
  • Resumable uploads still delegate to the existing tuspy uploader, but through asyncio.to_thread() so the event loop is not blocked. That keeps the implementation straightforward and honest about the sync TUS path.
  • TUS protocol endpoints are intentionally not generated as normal low-level methods yet; they need a richer transport surface for custom verbs, headers, binary bodies, and response-header capture.

Testing

  • Added high-level async tests for GET/list/cancel/template flows, non-resumable assembly upload, wait=True polling with mocked asyncio.sleep, async context-manager cleanup, and resumable upload delegation.
  • Added sync and async tests proving the generated low-level endpoint methods call the existing request primitives with quoted path params and without surfacing auth-only params.
  • Added sync Assembly regression tests for retry rewinding, non-seekable retry rejection, non-JSON response handling, poll URL pinning, and capped poll rate limits.
  • Added a same-service mixed-case hostname signing regression test.
  • Verified locally with:
    • poetry run pytest
    • From API2: api2/bin/cli.ts contracts sdks --no-motd --platform python --include-generated --sdk-root ../python-sdk-asyncio --compare-existing
    • From API2: api2/bin/cli.ts contracts sdks --no-motd --platform python --sdk-root ../python-sdk-asyncio --rewrite-sdk --compare-existing

This PR is intentionally based on #56 and targets base branch py310-v2.

@kvz kvz self-assigned this May 20, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 20, 2026

Codecov Report

❌ Patch coverage is 96.40387% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.58%. Comparing base (89a52c3) to head (0c4c974).

Files with missing lines Patch % Lines
transloadit/assembly.py 87.50% 12 Missing ⚠️
transloadit/async_request.py 95.67% 7 Missing ⚠️
transloadit/api_url.py 92.85% 2 Missing ⚠️
transloadit/response.py 93.93% 2 Missing ⚠️
transloadit/async_assembly.py 99.28% 1 Missing ⚠️
transloadit/client.py 98.64% 1 Missing ⚠️
transloadit/request.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           py310-v2      #57      +/-   ##
============================================
+ Coverage     86.60%   96.58%   +9.98%     
============================================
  Files             7       14       +7     
  Lines           209      849     +640     
  Branches         19      107      +88     
============================================
+ Hits            181      820     +639     
- Misses           28       29       +1     
Flag Coverage Δ
unittests 96.58% <96.40%> (+9.98%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kvz
Copy link
Copy Markdown
Member Author

kvz commented May 21, 2026

Setting this back to draft while we expand the feature scope: the v2 PR should also cover the full Transloadit API endpoint surface before we treat it as ready. I added a matching @todo to the 2.0.0 CHANGELOG section so the release notes get updated once the endpoint coverage is complete.

@kvz kvz marked this pull request as draft May 21, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants