Add native asyncio cursor support (Phase 1)#666
Merged
laughingman7743 merged 4 commits intomasterfrom Feb 20, 2026
Merged
Conversation
Implement AioCursor and AioDictCursor that use asyncio.sleep() for polling and asyncio.to_thread() for boto3 calls, keeping the event loop free. This replaces the ThreadPoolExecutor-based approach used by the existing AsyncCursor for users who need true asyncio support. New files: - pyathena/aio/ package (util, common, result_set, cursor, connection) - tests/pyathena/aio/ (conftest, test_cursor with 16 tests) - pyathena.aconnect() entry point Closes #662 (Phase 1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rename AioResultSet -> AthenaAioResultSet, AioDictResultSet -> AthenaAioDictResultSet to match existing AthenaResultSet naming - Use multiple inheritance (AthenaDictResultSet, AthenaAioResultSet) to eliminate duplicated _get_rows method in AthenaAioDictResultSet Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add Google-style docstrings to AioCursor properties and methods matching the sync Cursor docstring patterns - Add docstrings to AthenaAioResultSet fetch methods - Fix _poll log message to match sync: "Query canceled by user." Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_description_initial: verify description is None before execution - test_bad_query: verify DatabaseError on invalid SQL - test_query_id: verify query_id is UUID v4 format - test_query_execution_initial: verify all WithResultSet properties are in correct initial state before any query execution - test_cancel_initial: verify ProgrammingError on cancel without query - test_executemany: verify async executemany with INSERT - test_executemany_fetch: verify result set cleared after executemany - test_execute_with_callback: verify on_start_query_execution callback - Add execute_many_aio table to test SQL template Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 20, 2026
laughingman7743
added a commit
that referenced
this pull request
Feb 21, 2026
Add comprehensive documentation for the native asyncio cursor implementations added in PRs #666, #667, #668. This includes a new docs/aio.md overview page, AioCursor sections in each specialized cursor page, API reference for the aio module, and an async example in the README. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 21, 2026
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
AioCursorandAioDictCursorthat use nativeasyncioinstead ofThreadPoolExecutorasyncio.sleep()for polling andasyncio.to_thread()for boto3 calls, keeping the event loop freepyathena.aconnect()async entry point andAioConnectionwith async context managerAioResultSetwithasync create()factory pattern (cannotawaitin__init__)Motivation
Closes #662 (Phase 1). The existing
AsyncCursorusesThreadPoolExecutorwhich blocks threads duringtime.sleep()polling. Native asyncio support allows proper integration with async frameworks (FastAPI, aiohttp, etc.).Scope (Phase 1 only)
This PR covers the core cursor types only:
AioCursor/AioDictCursorAioResultSet/AioDictResultSetAioBaseCursor/AioConnectionDeferred to Phase 2: Specialized cursors (pandas, arrow, polars, s3fs, spark) and metadata operations (
list_databases,list_table_metadata, etc.).Key design decisions
asyncio.to_thread(retry_api_call, ...)async create()classmethodawaitin__init__Aioprefix (AioCursor)Asyncprefix already taken by thread-based cursorasyncio.CancelledErrorKeyboardInterrupt)BaseCursor_build_*methods,__init__, constantsUsage
Test plan
make fmtpassesmake chk(ruff + mypy) passestests/pyathena/aio/test_cursor.py)🤖 Generated with Claude Code