Sqlalchemy adapter for Firebolt
Project description
firebolt-sqlalchemy
The Firebolt dialect for SQLAlchemy. firebolt-sqlalchemy
uses Firebolt's Python SDK which implements PEP 249.
Installation
Requires Python >=3.7.
pip install firebolt-sqlalchemy
Connecting
Connection strings use the following structure:
firebolt://{client_id}:{client_secret}@{database}[/{engine_name}]?account_name={name}
engine_name
is optional.
account_name
is required.
Examples:
firebolt://aaa-bbb-ccc-222:$ecret@sample_database?account_name=my_account
firebolt://aaa-bbb-ccc-222:$ecret@sample_database/sample_engine?account_name=my_account
To override the API URL (e.g. for dev testing):
export FIREBOLT_BASE_URL=<your_url>
If your secret contains % or / characters they need to be sanitised as per https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls
my_secret = "0920%/2"
import urllib.parse
new_secret = urllib.parse.quote_plus(my_secret)
Quick Start
import urllib.parse
from sqlalchemy import create_engine
secret = urllib.parse.quote_plus("your_secret_here")
engine = create_engine("firebolt://aaa-bbb-ccc-222:" + secret + "@sample_database/sample_engine?account_name=my_account")
connection = engine.connect()
connection.execute("CREATE FACT TABLE example(dummy int) PRIMARY INDEX dummy")
connection.execute("INSERT INTO example(dummy) VALUES (11)")
result = connection.execute("SELECT * FROM example")
for item in result.fetchall():
print(item)
AsyncIO extension
import urllib.parse
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
secret = urllib.parse.quote_plus("your_secret_here")
engine = create_async_engine("asyncio+firebolt://aaa-bbb-ccc-222:" + secret + "@sample_database/sample_engine?account_name=my_account")
async with engine.connect() as conn:
await conn.execute(
text(f"INSERT INTO example(dummy) VALUES (11)")
)
result = await conn.execute(
text(f"SELECT * FROM example")
)
print(result.fetchall())
await engine.dispose()
Limitations
- Transactions are not supported since Firebolt database does not support them at this time.
- Parametrised calls to execute and executemany are not implemented.
Contributing
See: CONTRIBUTING.MD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
firebolt_sqlalchemy-1.0.0.tar.gz
(11.6 kB
view hashes)
Built Distribution
Close
Hashes for firebolt_sqlalchemy-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d7498f100b0274db3793bb4f7f02112927d1c0f7a7c346f76e305896e23d1b3 |
|
MD5 | fde32ce07764e46e744323d7a8b017ae |
|
BLAKE2b-256 | e98bfe071a31f3644813ab3691a03274c85e1be573eb4c8fddd1ead35a0e8ba7 |
Close
Hashes for firebolt_sqlalchemy-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c75c147be10c0f73e3ee36a2378052ad47f667cbd17d65c2a224ddab6d9bca9 |
|
MD5 | 82b9402fdcff70faa3b65908a6163920 |
|
BLAKE2b-256 | 2fd338cce932fba433dc9c109a01a5d563b795065b03dd60c4b262b974def19d |