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.1.tar.gz
(11.6 kB
view hashes)
Built Distribution
Close
Hashes for firebolt_sqlalchemy-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf08306938200683d5b5c604905c162bf7e9cb285b600d9cb5b0cdff75df6f1 |
|
MD5 | d2fbbb73c09977760d32eec410b0c625 |
|
BLAKE2b-256 | acb0ad8f03e41b4ac060e6f40a79b222e269f68896b1ae3b7e9ecf423d9792d3 |
Close
Hashes for firebolt_sqlalchemy-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607e0c9623cc19fcf77a03c72f64bc05f4065a511299b3f0d635544fe174ab75 |
|
MD5 | d61d87d2fe699d0e084bf2efecdc63f4 |
|
BLAKE2b-256 | 50bffceab72d57642e5108989fe5d952e85b3b5e2fe727f2f725b612f9f8da01 |