Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Native asyncio is also supported:

```python
import asyncio
from pyathena import aconnect
from pyathena import aio_connect

async def main():
async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor()
await cursor.execute("SELECT 1")
Expand Down
40 changes: 20 additions & 20 deletions docs/aio.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PyAthena has two families of async cursors:
|---|---|---|
| **Concurrency model** | `concurrent.futures.ThreadPoolExecutor` | Native `asyncio` (`await` / `async for`) |
| **Event loop** | Blocks a thread per query | Non-blocking |
| **Connection** | `connect()` (sync) | `aconnect()` (async) |
| **Connection** | `connect()` (sync) | `aio_connect()` (async) |
| **execute()** returns | `(query_id, Future)` | Awaitable cursor (self) |
| **Fetch methods** | Sync (via `Future.result()`) | `await cursor.fetchone()` for streaming cursors |
| **Iteration** | `for row in result_set` | `async for row in cursor` |
Expand All @@ -29,22 +29,22 @@ from synchronous code.

## Connection

Use the `aconnect()` function to create an async connection.
Use the `aio_connect()` function to create an async connection.
It returns an `AioConnection` that produces `AioCursor` instances by default.

```python
from pyathena import aconnect
from pyathena import aio_connect

conn = await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
conn = await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2")
```

The connection supports the async context manager protocol:

```python
from pyathena import aconnect
from pyathena import aio_connect

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor()
await cursor.execute("SELECT 1")
Expand All @@ -59,10 +59,10 @@ AioCursor is a native asyncio cursor that uses `await` for query execution and r
It follows the DB API 2.0 interface adapted for async usage.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.cursor import AioCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor()
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -74,9 +74,9 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The cursor supports the `async with` context manager:

```python
from pyathena import aconnect
from pyathena import aio_connect

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -86,9 +86,9 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
You can iterate over results with `async for`:

```python
from pyathena import aconnect
from pyathena import aio_connect

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -99,9 +99,9 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Execution information of the query can also be retrieved:

```python
from pyathena import aconnect
from pyathena import aio_connect

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -121,9 +121,9 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
To cancel a running query:

```python
from pyathena import aconnect
from pyathena import aio_connect

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -137,10 +137,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
AioDictCursor is an AioCursor that returns rows as dictionaries with column names as keys.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.cursor import AioDictCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioDictCursor)
await cursor.execute("SELECT * FROM many_rows LIMIT 10")
Expand All @@ -152,10 +152,10 @@ If you want to change the dictionary type (e.g., use OrderedDict):

```python
from collections import OrderedDict
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.cursor import AioDictCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioDictCursor, dict_type=OrderedDict)
await cursor.execute("SELECT * FROM many_rows LIMIT 10")
Expand Down
2 changes: 1 addition & 1 deletion docs/api/aio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Connection
----------

.. automodule:: pyathena
:members: aconnect
:members: aio_connect

.. autoclass:: pyathena.aio.connection.AioConnection
:members:
Expand Down
24 changes: 12 additions & 12 deletions docs/arrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ Unlike AsyncArrowCursor which uses `concurrent.futures`, this cursor uses
keeping the event loop free.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor)
table = (await cursor.execute("SELECT * FROM many_rows")).as_arrow()
Expand All @@ -507,10 +507,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Support fetch and iterate query results:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -520,10 +520,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
```

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -534,10 +534,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The `as_polars()` method converts the result to a Polars DataFrame:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -547,10 +547,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The unload option is also available:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor, unload=True)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -560,10 +560,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
AioArrowCursor also supports S3 timeout configuration:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.arrow.cursor import AioArrowCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioArrowCursor, connect_timeout=10.0, request_timeout=30.0)
await cursor.execute("SELECT * FROM many_rows")
Expand Down
16 changes: 8 additions & 8 deletions docs/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,10 @@ Unlike AsyncPandasCursor which uses `concurrent.futures`, this cursor uses
keeping the event loop free.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.pandas.cursor import AioPandasCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPandasCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -793,10 +793,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Support fetch and iterate query results:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.pandas.cursor import AioPandasCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPandasCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -806,10 +806,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
```

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.pandas.cursor import AioPandasCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPandasCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -820,10 +820,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The unload option is also available:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.pandas.cursor import AioPandasCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPandasCursor, unload=True)
await cursor.execute("SELECT * FROM many_rows")
Expand Down
20 changes: 10 additions & 10 deletions docs/polars.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,10 @@ Unlike AsyncPolarsCursor which uses `concurrent.futures`, this cursor uses
keeping the event loop free.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.polars.cursor import AioPolarsCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPolarsCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -600,10 +600,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Support fetch and iterate query results:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.polars.cursor import AioPolarsCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPolarsCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -613,10 +613,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
```

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.polars.cursor import AioPolarsCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPolarsCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -627,10 +627,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The `as_arrow()` method converts the result to an Apache Arrow Table:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.polars.cursor import AioPolarsCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPolarsCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -640,10 +640,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
The unload option is also available:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.polars.cursor import AioPolarsCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioPolarsCursor, unload=True)
await cursor.execute("SELECT * FROM many_rows")
Expand Down
12 changes: 6 additions & 6 deletions docs/s3fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ Since `AthenaS3FSResultSet` lazily streams rows from S3 via a CSV reader,
fetch methods are async and require `await`.

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.s3fs.cursor import AioS3FSCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioS3FSCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -395,10 +395,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Async iteration is supported:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.s3fs.cursor import AioS3FSCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioS3FSCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand All @@ -409,10 +409,10 @@ async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
Execution information of the query can also be retrieved:

```python
from pyathena import aconnect
from pyathena import aio_connect
from pyathena.aio.s3fs.cursor import AioS3FSCursor

async with await aconnect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
async with await aio_connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
region_name="us-west-2") as conn:
cursor = conn.cursor(AioS3FSCursor)
await cursor.execute("SELECT * FROM many_rows")
Expand Down
Loading