# SQLAlchemy [GizmoSQL](https://github.com/gizmodata/GizmoSQL) ADBC Dialect
[<img src="https://img.shields.io/badge/GitHub-gizmodata%2Fsqlalchemy--gizmosql--adbc--dialect-blue.svg?logo=Github">](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect)
[![sqlalchemy-gizmosql-adbc-dialect-ci](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect/actions/workflows/ci.yml)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--gizmosql--adbc--dialect)](https://pypi.org/project/sqlalchemy-gizmosql-adbc-dialect/)
[![PyPI version](https://badge.fury.io/py/sqlalchemy-gizmosql-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-gizmosql-adbc-dialect)
[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--gizmosql--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-gizmosql-adbc-dialect/)
Basic SQLAlchemy dialect for [GizmoSQL](https://github.com/gizmodata/GizmoSQL)
## Installation
### Option 1 - from PyPi
```sh
$ pip install sqlalchemy-gizmosql-adbc-dialect
```
### Option 2 - from source - for development
```shell
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:
```shell
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
```bash
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
```python
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
Raw data
{
"_id": null,
"home_page": null,
"name": "sqlalchemy-gizmosql-adbc-dialect",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "sqlalchemy, flight-sql, gizmosql, adbc, dialect",
"author": null,
"author_email": "Philip Moore <prmoore77@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/9e/7d/34c0ec06ff043190f3e009bbf616f3197cb9880d04efd4a0f480a14ecb72/sqlalchemy_gizmosql_adbc_dialect-0.0.21.tar.gz",
"platform": null,
"description": "# SQLAlchemy [GizmoSQL](https://github.com/gizmodata/GizmoSQL) ADBC Dialect \n\n[<img src=\"https://img.shields.io/badge/GitHub-gizmodata%2Fsqlalchemy--gizmosql--adbc--dialect-blue.svg?logo=Github\">](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect)\n[![sqlalchemy-gizmosql-adbc-dialect-ci](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect/actions/workflows/ci.yml)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--gizmosql--adbc--dialect)](https://pypi.org/project/sqlalchemy-gizmosql-adbc-dialect/)\n[![PyPI version](https://badge.fury.io/py/sqlalchemy-gizmosql-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-gizmosql-adbc-dialect)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--gizmosql--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-gizmosql-adbc-dialect/)\n\nBasic SQLAlchemy dialect for [GizmoSQL](https://github.com/gizmodata/GizmoSQL)\n\n## Installation\n\n### Option 1 - from PyPi\n```sh\n$ pip install sqlalchemy-gizmosql-adbc-dialect\n```\n\n### Option 2 - from source - for development\n```shell\ngit clone https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect\n\ncd sqlalchemy-gizmosql-adbc-dialect\n\n# Create the virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\n. .venv/bin/activate\n\n# Upgrade pip, setuptools, and wheel\npip install --upgrade pip setuptools wheel\n\n# Install SQLAlchemy GizmoSQL ADBC Dialect - in editable mode with dev dependencies\npip install --editable .[dev]\n```\n\n### Note\nFor 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:\n```shell\nexport PYTHONPATH=$(pwd)/src\n```\n\n## Usage\n\nOnce you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search\n\n### Start a GizmoSQL Server - example below - see https://github.com/gizmodata/GizmoSQL for more details\n```bash\ndocker run --name gizmosql \\\n --detach \\\n --rm \\\n --tty \\\n --init \\\n --publish 31337:31337 \\\n --env TLS_ENABLED=\"1\" \\\n --env GIZMOSQL_PASSWORD=\"gizmosql_password\" \\\n --env PRINT_QUERIES=\"1\" \\\n --pull missing \\\n gizmodata/gizmosql:latest\n```\n\n### Connect with the SQLAlchemy GizmoSQL ADBC Dialect\n```python\nimport os\nimport logging\n\nfrom sqlalchemy import create_engine, MetaData, Table, select, Column, text, Integer, String, Sequence\nfrom sqlalchemy.orm import Session\nfrom sqlalchemy.orm import declarative_base\nfrom sqlalchemy.engine.url import URL\n\n# Setup logging\nlogging.basicConfig()\nlogging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)\n\n\nBase = declarative_base()\n\n\nclass FakeModel(Base): # type: ignore\n __tablename__ = \"fake\"\n\n id = Column(Integer, Sequence(\"fakemodel_id_sequence\"), primary_key=True)\n name = Column(String)\n\n\ndef main():\n # Build the URL\n url = URL.create(drivername=\"gizmosql\",\n host=\"localhost\",\n port=31337,\n username=os.getenv(\"GIZMOSQL_USERNAME\", \"gizmosql_username\"),\n password=os.getenv(\"GIZMOSQL_PASSWORD\", \"gizmosql_password\"),\n query={\"disableCertificateVerification\": \"True\",\n \"useEncryption\": \"True\"\n }\n )\n\n print(f\"Database URL: {url}\")\n\n engine = create_engine(url=url)\n Base.metadata.create_all(bind=engine)\n\n metadata = MetaData()\n metadata.reflect(bind=engine)\n\n for table_name in metadata.tables:\n print(f\"Table name: {table_name}\")\n\n with Session(bind=engine) as session:\n\n # Try ORM\n session.add(FakeModel(id=1, name=\"Joe\"))\n session.commit()\n\n joe = session.query(FakeModel).filter(FakeModel.name == \"Joe\").first()\n\n assert joe.name == \"Joe\"\n\n # Execute some raw SQL\n results = session.execute(statement=text(\"SELECT * FROM fake\")).fetchall()\n print(results)\n\n # Try a SQLAlchemy table select\n fake: Table = metadata.tables[\"fake\"]\n stmt = select(fake.c.name)\n\n results = session.execute(statement=stmt).fetchall()\n print(results)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Credits\nMuch code and inspiration was taken from repo: https://github.com/Mause/duckdb_engine\n",
"bugtrack_url": null,
"license": null,
"summary": "A SQLAlchemy dialect for connecting to a [GizmoSQL](https://github.com/gizmodata/GizmoSQL) server with ADBC",
"version": "0.0.21",
"project_urls": {
"Homepage": "https://github.com/gizmodata/sqlalchemy-gizmosql-adbc-dialect"
},
"split_keywords": [
"sqlalchemy",
" flight-sql",
" gizmosql",
" adbc",
" dialect"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "17eba3f4310c6b661710a2378a99066df1e693fef6333e391bf87e2a792257f5",
"md5": "a640c87d36c75878af70f8eb66f56da3",
"sha256": "49b1e1d14c2be00e6dd016d6965b48cb4aa2f401d703ddd64695f6b2f7183891"
},
"downloads": -1,
"filename": "sqlalchemy_gizmosql_adbc_dialect-0.0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a640c87d36c75878af70f8eb66f56da3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10110,
"upload_time": "2024-10-21T18:40:52",
"upload_time_iso_8601": "2024-10-21T18:40:52.919520Z",
"url": "https://files.pythonhosted.org/packages/17/eb/a3f4310c6b661710a2378a99066df1e693fef6333e391bf87e2a792257f5/sqlalchemy_gizmosql_adbc_dialect-0.0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9e7d34c0ec06ff043190f3e009bbf616f3197cb9880d04efd4a0f480a14ecb72",
"md5": "cf9562adb2ab6100dfe3d5708ddb2f44",
"sha256": "1bcc562f20c960ae9a47cfa5f5f472152ce78f3e9bce57392b51ddd397e02e1d"
},
"downloads": -1,
"filename": "sqlalchemy_gizmosql_adbc_dialect-0.0.21.tar.gz",
"has_sig": false,
"md5_digest": "cf9562adb2ab6100dfe3d5708ddb2f44",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11379,
"upload_time": "2024-10-21T18:40:54",
"upload_time_iso_8601": "2024-10-21T18:40:54.406723Z",
"url": "https://files.pythonhosted.org/packages/9e/7d/34c0ec06ff043190f3e009bbf616f3197cb9880d04efd4a0f480a14ecb72/sqlalchemy_gizmosql_adbc_dialect-0.0.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-21 18:40:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gizmodata",
"github_project": "sqlalchemy-gizmosql-adbc-dialect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sqlalchemy-gizmosql-adbc-dialect"
}