Skip to content

Commit 2d60d0c

Browse files
authored
Async Version (#51)
This pull request introduces asynchronous support for the `aurora-data-api` library, enabling developers to perform non-blocking database operations. Key changes include the addition of an asynchronous client and cursor implementation, updated documentation, and minor refactoring of error handling imports. This fixes #50 ### Asynchronous Support * **New Async Client and Cursor**: Added `AsyncAuroraDataAPIClient` and `AsyncAuroraDataAPICursor` classes in `aurora_data_api/async_.py` to provide asynchronous database interaction using `aiobotocore`. These include methods for executing queries, managing transactions, and handling paginated results. * **Async Connection Function**: Introduced a `connect` function in `aurora_data_api/async_.py` to create instances of the async client. ### Documentation Updates * **Async Installation Instructions**: Updated `README.rst` to include installation instructions for async support (`pip install aurora-data-api[async]`). * **Async Usage Examples**: Added examples for async database operations, including query execution and iteration, to help developers integrate async functionality. [[1]](diffhunk://#diff-7b3ed02bc73dc06b7db906cf97aa91dec2b2eb21f2d92bc5caa761df5bbc168fR73-R85) [[2]](diffhunk://#diff-7b3ed02bc73dc06b7db906cf97aa91dec2b2eb21f2d92bc5caa761df5bbc168fR94-R102) ### Codebase Refactoring * **boto3 to botocore**: Refactored using botocore instead of boto3 to keep the sync version (with botocore) and async version (with aiobotocore) comparable. This should not cause any issues as this library uses only the raw level API from boto3, which is actually botocore. * **Error Handling Imports**: Refactored imports in `aurora_data_api/exceptions.py` to align with updated module names (`error_codes_mysql` and `error_codes_postgresql`).
1 parent ef6208e commit 2d60d0c

File tree

11 files changed

+1191
-477
lines changed

11 files changed

+1191
-477
lines changed

README.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Installation
77

88
pip install aurora-data-api
99

10+
For async support using aiobotocore::
11+
12+
pip install aurora-data-api[async]
13+
1014
Prerequisites
1115
-------------
1216
* Set up an AWS
@@ -66,6 +70,19 @@ the standard main entry point, and accepts two implementation-specific keyword a
6670
cursor.execute("select * from pg_catalog.pg_tables")
6771
print(cursor.fetchall())
6872
73+
For async usage (requires ``aurora-data-api[async]``)::
74+
75+
.. code-block:: python
76+
77+
import aurora_data_api.async_ as aurora_data_api_async
78+
79+
cluster_arn = "arn:aws:rds:us-east-1:123456789012:cluster:my-aurora-serverless-cluster"
80+
secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:rds-db-credentials/MY_DB"
81+
async with await aurora_data_api_async.connect(aurora_cluster_arn=cluster_arn, secret_arn=secret_arn, database="my_db") as conn:
82+
async with await conn.cursor() as cursor:
83+
await cursor.execute("select * from pg_catalog.pg_tables")
84+
print(await cursor.fetchall())
85+
6986
The cursor supports iteration (and automatically wraps the query in a server-side cursor and paginates it if required):
7087

7188
.. code-block:: python
@@ -74,6 +91,15 @@ The cursor supports iteration (and automatically wraps the query in a server-sid
7491
for row in cursor.execute("select * from pg_catalog.pg_tables"):
7592
print(row)
7693
94+
For async iteration::
95+
96+
.. code-block:: python
97+
98+
async with await conn.cursor() as cursor:
99+
await cursor.execute("select * from pg_catalog.pg_tables")
100+
async for row in cursor:
101+
print(row)
102+
77103
Motivation
78104
----------
79105
The `RDS Data API <https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html>`_ is the link between the

0 commit comments

Comments
 (0)