Skip to main content

Standardizing models

Project description

Bollhav

A lightweight config class for defining data pipeline models.

Usage

Basic table

model = Model(
    name="orders",
    source_table="raw.orders",
    destination_table="orders",
    destination_schema="public",
    write_mode=WriteMode.TRUNCATE_INSERT,
    destination_db=Database.POSTGRES,
    columns=[
        PostgresColumn(name="id", data_type=PostgresType.BIGINT, primary_key=True, nullable=False),
        PostgresColumn(name="customer_id", data_type=PostgresType.BIGINT),
        PostgresColumn(name="amount", data_type=PostgresType.NUMERIC, precision=10, scale=2),
        PostgresColumn(name="created_at", data_type=PostgresType.TIMESTAMPTZ),
    ],
)

View

model = Model(
    name="orders_view",
    source_table="raw.orders",
    destination_table="orders_view",
    destination_schema="public",
    model_type=ModelType.VIEW,
    write_mode=WriteMode.VIEW,
    destination_db=Database.POSTGRES,
    columns=[
        PostgresColumn(name="id", data_type=PostgresType.BIGINT),
        PostgresColumn(name="amount", data_type=PostgresType.NUMERIC, precision=10, scale=2),
    ],
)

With a schedule

model = Model(
    name="orders",
    source_table="raw.orders",
    destination_db=Database.POSTGRES,
    columns=[
        PostgresColumn(name="id", data_type=PostgresType.BIGINT),
        PostgresColumn(name="amount", data_type=PostgresType.NUMERIC, precision=10, scale=2),
    ],
    cron="0 3 * * *",
)
model.batch_size  # BatchSize.DAILY

batch_size is inferred from the cron expression and is read-only.

BatchSize Example cron
YEARLY 0 0 1 1 *
MONTHLY 0 0 1 * *
WEEKLY 0 0 * * 0
DAILY 0 3 * * *
HOURLY 0 * * * *

With dynamic kwargs

def my_ddl(table_name: str, schema: str, **kwargs) -> str:
    return f"CREATE TABLE {schema}.{table_name} (id SERIAL PRIMARY KEY);"

model = Model(
    name="orders",
    source_table="raw.orders",
    destination_db=Database.POSTGRES,
    columns=[
        PostgresColumn(name="id", data_type=PostgresType.BIGINT, primary_key=True, nullable=False),
    ],
    destination_ddl=my_ddl,
    table_name="orders",
    schema="public",
)
model.extra["destination_ddl"]  # resolved DDL string

Callables in **kwargs are resolved at init using the non-callable kwargs as arguments.

Write modes

WriteMode ModelType Description
APPEND TABLE Insert without truncating
TRUNCATE_INSERT TABLE Truncate then insert
OVERWRITE_INSERT TABLE Overwrite matching rows
MERGE TABLE Upsert based on keys
VIEW VIEW Create or replace view

ModelType and WriteMode are validated against each other at init.

PostgresColumn

Field Type Default Notes
name str required
data_type PostgresType required
nullable bool True
order int | None None
primary_key bool False Implies nullable=False
unique bool False
precision int | None None For NUMERIC, DECIMAL
scale int | None None For NUMERIC, DECIMAL
length int | None None For VARCHAR, CHAR, BIT

primary_key=True with nullable=True raises at init.

Tags

Optional and freeform.

model = Model(
    name="orders",
    source_table="raw.orders",
    destination_db=Database.POSTGRES,
    columns=[
        PostgresColumn(name="id", data_type=PostgresType.BIGINT),
    ],
    tags=["finance", "critical"],
)

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

bollhav-1.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bollhav-1.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file bollhav-1.1.1.tar.gz.

File metadata

  • Download URL: bollhav-1.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for bollhav-1.1.1.tar.gz
Algorithm Hash digest
SHA256 061c3693cd3f74ab46855b558b311f390e3c905a3b247919294f6547830b06b7
MD5 62f6f6cfad1a9d660b69eb580f30c00b
BLAKE2b-256 a885a6908edca0029e57ad561dce1f9032c6329837e7418986b79fb46ec4c02f

See more details on using hashes here.

File details

Details for the file bollhav-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: bollhav-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for bollhav-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0dff8a84977e25e3a42113978d05545e8fdadd07a29f5218bf02192fffbf0def
MD5 2424d868af5e66c2d783739b8c2b642c
BLAKE2b-256 3bdff3b08447d29587d704cb73f11b9d47ed0e4697f93095194e1d17d0d28326

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page