https://github.com/awslabs/aurora-dsql-sqlalchemy
Aurora DSQL dialect for SQLAlchemy
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.9%) to scientific vocabulary
Keywords
Repository
Aurora DSQL dialect for SQLAlchemy
Basic Info
Statistics
- Stars: 5
- Watchers: 6
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Amazon Aurora DSQL dialect for SQLAlchemy
Introduction
The Aurora DSQL dialect for SQLAlchemy provides integration between SQLAlchemy ORM and Aurora DSQL. This dialect enables Python applications to leverage SQLAlchemy's powerful object-relational mapping capabilities while taking advantage of Aurora DSQL's distributed architecture and high availability.
Sample Application
There is an included sample application in examples/pet-clinic-app that shows how to use Aurora DSQL with SQLAlchemy. To run the included example please refer to the sample README.
Prerequisites
- Python 3.10 or higher
- SQLAlchemy 2.0.0 or higher
- One of the following drivers:
- psycopg 3.2.0 or higher
- psycopg2 2.9.0 or higher
Installation
Install the packages using the commands below:
```bash pip install aurora-dsql-sqlalchemy
driver installation (in case you opt for psycopg)
DO NOT use pip install psycopg-binary
pip install "psycopg[binary]"
driver installation (in case you opt for psycopg2)
pip install psycopg2-binary ```
Dialect Configuration
After installation, you can connect to an Aurora DSQL cluster using SQLAlchemy's create_engine:
The connection parameter auroradsql+psycopg specifies to use the auroradsql dialect with the driver psycopg (psycopg3).
To use the driver psycopg2, change the connection parameter to auroradsql+psycopg2.
```python from sqlalchemy import create_engine from sqlalchemy.engine.url import URL
url = URL.create(
"auroradsql+psycopg",
username=
engine = createengine(
url,
connectargs={"sslmode": "verify-full", "sslrootcert": "
Note: Each connection has a maximum duration limit. See the Maximum connection duration time limit in the Cluster quotas and database limits in Amazon Aurora DSQL page.
Best Practices
Primary Key Generation
SQLAlchemy applications connecting to Aurora DSQL should use UUID for the primary key column since auto-incrementing integer keys (sequences or serial) are not supported in DSQL. The following column definition can be used to define an UUID primary key column.
python
Column(
"id",
UUID(as_uuid=True),
primary_key=True,
default=text('gen_random_uuid()')
)
gen_random_uuid() returns an UUID version 4 as the default value.
Dialect Features and Limitations
- Column Metadata: The dialect fixes an issue related to
"datatype json not supported"when calling SQLAlchemy's metadata() API. - Foreign Keys: Aurora DSQL does not support foreign key constraints. The dialect disables these constraints, but be aware that referential integrity must be maintained at the application level.
- Index Creation: Aurora DSQL does not support
CREATE INDEXorCREATE UNIQUE INDEXcommands. The dialect instead usesCREATE INDEX ASYNCandCREATE UNIQUE INDEX ASYNCcommands. See the Asynchronous indexes in Aurora DSQL page for more information.
The following parameters are used for customizing index creation
auroradsql_include- specifies which columns to includes in an index by using theINCLUDEclause:python Index( "include_index", table.c.id, auroradsql_include=['name', 'email'] )Generated SQL output:
sql CREATE INDEX ASYNC include_index ON table (id) INCLUDE (name, email)auroradsql_nulls_not_distinct- controls howNULLvalues are treated in unique indexes:python Index( "idx_name", table.c.column, unique=True, auroradsql_nulls_not_distinct=True )Generated SQL output:
sql CREATE UNIQUE INDEX idx_name ON table (column) NULLS NOT DISTINCT- Index Interface Limitation:
NULLS FIRST | LAST- SQLalchemy's Index() interface does not have a way to pass in the sort order of null and non-null columns. (Default:NULLS LAST). IfNULLS FIRSTis required, please refer to the syntax as specified in Asynchronous indexes in Aurora DSQL and execute the corresponding SQL query directly in SQLAlchemy. - Psycopg (psycopg3) support: When connecting to DSQL using the default postgresql dialect with psycopg, an unsupported
SAVEPOINTerror occurs. The DSQL dialect addresses this issue by disabling theSAVEPOINTduring connection.
- Index Interface Limitation:
Developer instructions
Instructions on how to build and test the dialect are available in the Developer Instructions.
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.
Owner
- Name: Amazon Web Services - Labs
- Login: awslabs
- Kind: organization
- Location: Seattle, WA
- Website: http://amazon.com/aws/
- Repositories: 914
- Profile: https://github.com/awslabs
AWS Labs
GitHub Events
Total
- Create event: 9
- Release event: 2
- Watch event: 4
- Delete event: 7
- Member event: 1
- Issue comment event: 1
- Push event: 23
- Public event: 1
- Pull request review comment event: 4
- Pull request review event: 10
- Pull request event: 13
Last Year
- Create event: 9
- Release event: 2
- Watch event: 4
- Delete event: 7
- Member event: 1
- Issue comment event: 1
- Push event: 23
- Public event: 1
- Pull request review comment event: 4
- Pull request review event: 10
- Pull request event: 13
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: about 2 hours
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: about 2 hours
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- vic-tsang (5)
- danielfrankcom (1)
- wcmjunior (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 258 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 4
- Total maintainers: 2
pypi.org: aurora-dsql-sqlalchemy
Amazon Aurora DSQL dialect for SQLAlchemy
- Documentation: https://aurora-dsql-sqlalchemy.readthedocs.io/
- License: Apache License 2.0
-
Latest release: 1.0.2
published 7 months ago
Rankings
Maintainers (2)
Dependencies
- actions/cache v4 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- aws-actions/configure-aws-credentials v4 composite
- actions/checkout v4 composite
- gitleaks/gitleaks-action v1.6.0 composite
- aurora-dsql-sqlalchemy *
- boto3 >=1.35.74
- psycopg2-binary >=2.9
- pytest >=8
- sqlalchemy *
- sqlalchemy >=2.0.0