Draft: Async refactor with aiohttp core and sync wrapper#583
Draft
kaya70875 wants to merge 7 commits intojdepoix:masterfrom
Draft
Draft: Async refactor with aiohttp core and sync wrapper#583kaya70875 wants to merge 7 commits intojdepoix:masterfrom
kaya70875 wants to merge 7 commits intojdepoix:masterfrom
Conversation
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.
Overview
This draft PR proposes a major refactor of the YouTube Transcript API library to:
aiohttpfor asynchronous HTTP handling.YouTubeTranscriptAsyncApi.YouTubeTranscriptApiusingasyncio.run()internally for backward compatibility.The goal is to modernize the library and make it fully async-capable while still supporting users who want synchronous usage.
Key Changes
1. Async core API (
YouTubeTranscriptAsyncApi)aiohttp.ClientSessioninternally.async withensures sessions are always closed properly.ClientSessionor proxy configuration.2. Sync wrapper (
YouTubeTranscriptApi)asyncio.run()for fetch and list.requests.Note: sync wrapper should not be called from an existing async event loop; use async API in that case.
3. Private async helpers
_fetch_async/_list_asyncfor internal use.4. Breaking changes
requestsis removed; any code relying on the old sync-only HTTP client will break.YouTubeTranscriptAsyncApi.5. Tests
Additional Notes on Proxies and Retry Logic
The old sync implementation used requests with manual retry logic and mounted
HTTPAdapterfor handling 429 Too Many Requests responses.In the new async core (
aiohttp):aiohttpdoes not require the same adapter pattern.session.proxies.prevent_keeping_connections_aliveis still respected by passing Connection: close headers.This simplifies the API and reduces internal complexity, but it is a breaking change for any users relying on the old requests retry/mount behavior.