A SQLAlchemy dialect for connecting to a [GizmoSQL](https://github.com/gizmodata/gizmosql) server with ADBC
Project description
SQLAlchemy GizmoSQL ADBC Dialect
Basic SQLAlchemy dialect for GizmoSQL
Installation
Option 1 - from PyPi
$ pip install sqlalchemy-gizmosql-adbc-dialect
Option 2 - from source - for development
git clone https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect
cd sqlalchemy-gizmosql-adbc-dialect
# Create the virtual environment
python3 -m venv .venv
# Activate the virtual environment
. .venv/bin/activate
# Upgrade pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel
# Install SQLAlchemy GizmoSQL ADBC Dialect - in editable mode with dev dependencies
pip install --editable .[dev]
Note
For the following commands - if you are running from source and using --editable mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:
export PYTHONPATH=$(pwd)/src
Usage
Once you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search
Start a GizmoSQL Server - example below - see https://github.com/gizmodata/GizmoSQL for more details
docker run --name gizmosql \
--detach \
--rm \
--tty \
--init \
--publish 31337:31337 \
--env TLS_ENABLED="1" \
--env GIZMOSQL_PASSWORD="gizmosql_password" \
--env PRINT_QUERIES="1" \
--pull missing \
gizmodata/gizmosql:latest
Connect with the SQLAlchemy GizmoSQL ADBC Dialect
import os
import logging
from sqlalchemy import create_engine, MetaData, Table, select, Column, text, Integer, String, Sequence
from sqlalchemy.orm import Session
from sqlalchemy.orm import declarative_base
from sqlalchemy.engine.url import URL
# Setup logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
Base = declarative_base()
class FakeModel(Base): # type: ignore
__tablename__ = "fake"
id = Column(Integer, Sequence("fakemodel_id_sequence"), primary_key=True)
name = Column(String)
def main():
# Build the URL
url = URL.create(drivername="gizmosql",
host="localhost",
port=31337,
username=os.getenv("GIZMOSQL_USERNAME", "gizmosql_username"),
password=os.getenv("GIZMOSQL_PASSWORD", "gizmosql_password"),
query={"disableCertificateVerification": "True",
"useEncryption": "True"
}
)
print(f"Database URL: {url}")
engine = create_engine(url=url)
Base.metadata.create_all(bind=engine)
metadata = MetaData()
metadata.reflect(bind=engine)
for table_name in metadata.tables:
print(f"Table name: {table_name}")
with Session(bind=engine) as session:
# Try ORM
session.add(FakeModel(id=1, name="Joe"))
session.commit()
joe = session.query(FakeModel).filter(FakeModel.name == "Joe").first()
assert joe.name == "Joe"
# Execute some raw SQL
results = session.execute(statement=text("SELECT * FROM fake")).fetchall()
print(results)
# Try a SQLAlchemy table select
fake: Table = metadata.tables["fake"]
stmt = select(fake.c.name)
results = session.execute(statement=stmt).fetchall()
print(results)
if __name__ == "__main__":
main()
Credits
Much code and inspiration was taken from repo: https://github.com/Mause/duckdb_engine
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_gizmosql_adbc_dialect-0.0.23.tar.gz.
File metadata
- Download URL: sqlalchemy_gizmosql_adbc_dialect-0.0.23.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8417e5b196360071a2c61a79a3fe652fecf34f55a77de2b767cc2827084f92ae
|
|
| MD5 |
d6ce72ec252c14338cdcc5a347908bc5
|
|
| BLAKE2b-256 |
169b6f8580c6d3541e8b2c88e32ccdffdbefcd0dd3cfe749900e35daee624daa
|
Provenance
The following attestation bundles were made for sqlalchemy_gizmosql_adbc_dialect-0.0.23.tar.gz:
Publisher:
ci.yml on gizmodata/sqlalchemy-gizmosql-adbc-dialect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_gizmosql_adbc_dialect-0.0.23.tar.gz -
Subject digest:
8417e5b196360071a2c61a79a3fe652fecf34f55a77de2b767cc2827084f92ae - Sigstore transparency entry: 237313678
- Sigstore integration time:
-
Permalink:
gizmodata/sqlalchemy-gizmosql-adbc-dialect@8d67820b3cf231d91d40bf5edfb7d8cc6a74dbd2 -
Branch / Tag:
refs/tags/0.0.23 - Owner: https://github.com/gizmodata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@8d67820b3cf231d91d40bf5edfb7d8cc6a74dbd2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sqlalchemy_gizmosql_adbc_dialect-0.0.23-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_gizmosql_adbc_dialect-0.0.23-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ae0ca55a5aa49b841b06ac25655faa11b725489c7f178a57373dfea4d32f94
|
|
| MD5 |
6744144c4f36efd464d4546e9220b520
|
|
| BLAKE2b-256 |
a32dcc5422ac88985efb1445696938866fa01c993887cc87ea246e2acd23af17
|
Provenance
The following attestation bundles were made for sqlalchemy_gizmosql_adbc_dialect-0.0.23-py3-none-any.whl:
Publisher:
ci.yml on gizmodata/sqlalchemy-gizmosql-adbc-dialect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_gizmosql_adbc_dialect-0.0.23-py3-none-any.whl -
Subject digest:
76ae0ca55a5aa49b841b06ac25655faa11b725489c7f178a57373dfea4d32f94 - Sigstore transparency entry: 237313696
- Sigstore integration time:
-
Permalink:
gizmodata/sqlalchemy-gizmosql-adbc-dialect@8d67820b3cf231d91d40bf5edfb7d8cc6a74dbd2 -
Branch / Tag:
refs/tags/0.0.23 - Owner: https://github.com/gizmodata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@8d67820b3cf231d91d40bf5edfb7d8cc6a74dbd2 -
Trigger Event:
workflow_dispatch
-
Statement type: