GithubHelp home page GithubHelp logo

stevewithington / firebolt-sqlalchemy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firebolt-db/firebolt-sqlalchemy

0.0 1.0 0.0 519 KB

The Firebolt dialect for SQLAlchemy.

License: Apache License 2.0

Python 98.24% Shell 1.76%

firebolt-sqlalchemy's Introduction

SQLAlchemy and Firebolt

firebolt-sqlalchemy

Unit tests Code quality checks Firebolt Security Scan Integration tests Coverage

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://{username}:{password}@{database}[/{engine_name}][?account_name={name}}]

engine_name is optional. If omitted, Firebolt will use the default engine for the database.

account_name is optional. If omitted a default account will be used for connection.

Examples:

firebolt://email@domain:password@sample_database
firebolt://email@domain:password@sample_database/sample_engine

If a different account name is required, it can be specified in the connection string

firebolt://email@domain:password@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 password contains % or / characters they need to be sanitised as per https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls

my_pass = "0920%/2"
import urllib.parse
new_pass = urllib.parse.quote_plus(my_pass)

Quick Start

import urllib.parse
from sqlalchemy import create_engine

password = urllib.parse.quote_plus("your_password_here")
engine = create_engine("firebolt://email@domain:" + password + "@sample_database/sample_engine")
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

password = urllib.parse.quote_plus("your_password_here")
engine = create_async_engine("asyncio+firebolt://email@domain:" + password + "@sample_database/sample_engine")

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

  1. Transactions are not supported since Firebolt database does not support them at this time.
  2. Parametrised calls to execute and executemany are not implemented.

Contributing

See: CONTRIBUTING.MD

firebolt-sqlalchemy's People

Contributors

apurva-sigmoid avatar raghavsharmacode avatar ptiurin avatar cosmpop avatar kevinmarr avatar knan02 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.