# SQLAlchemy Flight SQL ADBC Dialect
[<img src="https://img.shields.io/badge/GitHub-prmoore77%2Fsqlalchemy--flight--sql--adbc--dialect-blue.svg?logo=Github">](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect)
[![sqlalchemy-flight-sql-adbc-dialect-ci](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect/actions/workflows/ci.yml)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--flight--sql--adbc--dialect)](https://pypi.org/project/sqlalchemy-flight-sql-adbc-dialect/)
[![PyPI version](https://badge.fury.io/py/sqlalchemy-flight-sql-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-flight-sql-adbc-dialect)
[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--flight--sql--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-flight-sql-adbc-dialect/)
Basic SQLAlchemy dialect for the [Flight SQL Server Example](https://github.com/voltrondata/flight-sql-server-example)
## Installation
### Option 1 - from PyPi
```sh
$ pip install sqlalchemy-flight-sql-adbc-dialect
```
### Option 2 - from source - for development
```shell
git clone https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect
cd sqlalchemy-flight-sql-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 Flight SQL ADBC Dialect - in editable mode with dev dependencies
pip install --editable .[dev]
```
### Note
For the following commands - if you 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 Flight SQL Server - example below - see https://github.com/voltrondata/flight-sql-server-example for more details
```bash
docker run --name flight-sql \
--detach \
--rm \
--tty \
--init \
--publish 31337:31337 \
--env TLS_ENABLED="1" \
--env FLIGHT_PASSWORD="flight_password" \
--env PRINT_QUERIES="1" \
--pull missing \
voltrondata/flight-sql:latest
```
### Connect with the SQLAlchemy Flight SQL 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="flight_sql",
host="localhost",
port=31337,
username=os.getenv("FLIGHT_USERNAME", "flight_username"),
password=os.getenv("FLIGHT_PASSWORD", "flight_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-flight-sql-adbc-dialect",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "sqlalchemy, flight-sql, adbc, dialect",
"author": null,
"author_email": "Philip Moore <prmoore77@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ea/f1/5000ed613f0d436bd6c3a15fce2f77345eb26299c0fd8def27291f574569/sqlalchemy_flight_sql_adbc_dialect-0.0.14.tar.gz",
"platform": null,
"description": "# SQLAlchemy Flight SQL ADBC Dialect \n\n[<img src=\"https://img.shields.io/badge/GitHub-prmoore77%2Fsqlalchemy--flight--sql--adbc--dialect-blue.svg?logo=Github\">](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect)\n[![sqlalchemy-flight-sql-adbc-dialect-ci](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect/actions/workflows/ci.yml)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--flight--sql--adbc--dialect)](https://pypi.org/project/sqlalchemy-flight-sql-adbc-dialect/)\n[![PyPI version](https://badge.fury.io/py/sqlalchemy-flight-sql-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-flight-sql-adbc-dialect)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--flight--sql--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-flight-sql-adbc-dialect/)\n\nBasic SQLAlchemy dialect for the [Flight SQL Server Example](https://github.com/voltrondata/flight-sql-server-example)\n\n## Installation\n\n### Option 1 - from PyPi\n```sh\n$ pip install sqlalchemy-flight-sql-adbc-dialect\n```\n\n### Option 2 - from source - for development\n```shell\ngit clone https://github.com/prmoore77/sqlalchemy-flight-sql-adbc-dialect\n\ncd sqlalchemy-flight-sql-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 Flight SQL ADBC Dialect - in editable mode with dev dependencies\npip install --editable .[dev]\n```\n\n### Note\nFor the following commands - if you 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 Flight SQL Server - example below - see https://github.com/voltrondata/flight-sql-server-example for more details\n```bash\ndocker run --name flight-sql \\\n --detach \\\n --rm \\\n --tty \\\n --init \\\n --publish 31337:31337 \\\n --env TLS_ENABLED=\"1\" \\\n --env FLIGHT_PASSWORD=\"flight_password\" \\\n --env PRINT_QUERIES=\"1\" \\\n --pull missing \\\n voltrondata/flight-sql:latest\n```\n\n### Connect with the SQLAlchemy Flight SQL 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=\"flight_sql\",\n host=\"localhost\",\n port=31337,\n username=os.getenv(\"FLIGHT_USERNAME\", \"flight_username\"),\n password=os.getenv(\"FLIGHT_PASSWORD\", \"flight_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 Flight SQL server with ADBC",
"version": "0.0.14",
"project_urls": {
"Homepage": "https://github.com/prmoore77/sqlalchemy_flight_sql_adbc_dialect"
},
"split_keywords": [
"sqlalchemy",
" flight-sql",
" adbc",
" dialect"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8c82a59b2a0025546be00b8205b0b1fe506d2a438ded305279a19f663631c1ba",
"md5": "58483d2538f58028dc5a0c1c0fb5cfd6",
"sha256": "56b15efc52e9791d363d16774274e170f4212d6d41ef827e1ab2178ed96e4c73"
},
"downloads": -1,
"filename": "sqlalchemy_flight_sql_adbc_dialect-0.0.14-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58483d2538f58028dc5a0c1c0fb5cfd6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10206,
"upload_time": "2024-07-17T14:28:22",
"upload_time_iso_8601": "2024-07-17T14:28:22.848860Z",
"url": "https://files.pythonhosted.org/packages/8c/82/a59b2a0025546be00b8205b0b1fe506d2a438ded305279a19f663631c1ba/sqlalchemy_flight_sql_adbc_dialect-0.0.14-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "eaf15000ed613f0d436bd6c3a15fce2f77345eb26299c0fd8def27291f574569",
"md5": "d13d79c0635d886760543fb5913420fc",
"sha256": "d5c8c30898656671d74d687b59047bb0a51dabbc1e68f63d6bad1eec0842f0f7"
},
"downloads": -1,
"filename": "sqlalchemy_flight_sql_adbc_dialect-0.0.14.tar.gz",
"has_sig": false,
"md5_digest": "d13d79c0635d886760543fb5913420fc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11339,
"upload_time": "2024-07-17T14:28:23",
"upload_time_iso_8601": "2024-07-17T14:28:23.977279Z",
"url": "https://files.pythonhosted.org/packages/ea/f1/5000ed613f0d436bd6c3a15fce2f77345eb26299c0fd8def27291f574569/sqlalchemy_flight_sql_adbc_dialect-0.0.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-17 14:28:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "prmoore77",
"github_project": "sqlalchemy_flight_sql_adbc_dialect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sqlalchemy-flight-sql-adbc-dialect"
}