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.2.tar.gz
(11.7 kB
view hashes)
Built Distribution
Close
Hashes for firebolt_sqlalchemy-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe64c37e13dd8dc408908995371e2cbb34b5afae6d5a7a212cbc248db81d43fd |
|
MD5 | 8c8fdbd770960b25bd20c298014fcf8f |
|
BLAKE2b-256 | 48d28763dddf8306bbeae8abc924af670238f4b939dce778ddb683f0fdfe02fb |
Close
Hashes for firebolt_sqlalchemy-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92e7f3266ad6cb589e1b0326f5466891c8217bfda3ab640715efdc14f50551f5 |
|
MD5 | b6323487971b084caaaf364cbdf8cf7b |
|
BLAKE2b-256 | bcd21b867fac57a763b95e1f533288df19e5788f1cc6b5fc45baa314e61cfce0 |