Skip to content

Database Connections 🔌

Jetbase supports multiple databases. This guide covers how to connect to each supported database using a SQLAlchemy url.

PostgreSQL

PostgreSQL is a popular open-source relational database and is fully supported by Jetbase.

Installing a Driver

PostgreSQL requires a database driver. Examples:

pip install psycopg2-binary

pip install "psycopg[binary]"

Connection String

sqlalchemy_url = "postgresql+driver://username:password@host:port/database"

Example

# jetbase/env.py
sqlalchemy_url = "postgresql+psycopg2://myuser:mypassword@localhost:5432/myapp"

With a specific schema:

# jetbase/env.py
sqlalchemy_url = "postgresql://myuser:mypassword@localhost:5432/myapp"
postgres_schema = "public"

Snowflake

Snowflake is a cloud-based data warehouse. Jetbase supports both username/password and key pair authentication.

Installing the Driver

Snowflake requires additional dependencies. Install Jetbase with the Snowflake extra:

pip install "jetbase[snowflake]"

Connection String Format

sqlalchemy_url = "snowflake://username:password@account/database/schema?warehouse=WAREHOUSE_NAME"
Component Description
username Your Snowflake username
password Your Snowflake password (omit for key pair auth)
account Your Snowflake account identifier (e.g., abc12345.us-east-1)
database Target database name
schema Target schema name
warehouse Compute warehouse to use

Username & Password Authentication

The simplest way to connect is with username and password:

# jetbase/env.py
sqlalchemy_url = "snowflake://myuser:mypassword@myaccount.us-east-1/my_db/public?warehouse=COMPUTE_WH"

Key Pair Authentication

For enhanced security, Snowflake supports key pair authentication. To use it, omit the password from your connection string and configure your private key.

Step 1: Create a connection string without a password:

# jetbase/env.py
sqlalchemy_url = "snowflake://myuser@myaccount.us-east-1/my_db/public?warehouse=COMPUTE_WH"

Step 2: Configure your private key as an environment variable:

# Set the private key (PEM format)
export JETBASE_SNOWFLAKE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASC...
-----END PRIVATE KEY-----"

# Optional: if your private key is encrypted
export JETBASE_SNOWFLAKE_PRIVATE_KEY_PASSWORD="your-key-password"

Tip

It's best to read your private key file directly into the environment variable locally:

export JETBASE_SNOWFLAKE_PRIVATE_KEY=$(cat snowflake_private_key.pem)

SQLite

SQLite is a lightweight, file-based database. It's great for development, testing, or small applications.

Connection String

SQLite doesn't require any additional drivers. Just connect with the connection string.

sqlalchemy_url = "sqlite:///path/to/database.db"

Examples

Relative path (relative to where you run Jetbase):

# jetbase/env.py
sqlalchemy_url = "sqlite:///myapp.db"

In-memory database (useful for testing):

# jetbase/env.py
sqlalchemy_url = "sqlite:///:memory:"