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",
table="orders",
schema="public",
write_mode=WriteMode.TRUNCATE_INSERT,
database=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",
table="orders_view",
schema="public",
model_type=ModelType.VIEW,
write_mode=WriteMode.VIEW,
database=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",
database=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",
database=Database.POSTGRES,
columns=[
PostgresColumn(name="id", data_type=PostgresType.BIGINT, primary_key=True, nullable=False),
],
ddl=my_ddl,
table_name="orders",
schema="public",
)
model.extra["ddl"] # resolved DDL string
Callables in **kwargs are resolved at init using the non-callable kwargs as arguments.
With debug
model = Model(
name="orders",
source_table="raw.orders",
debug=True,
)
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",
database=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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bollhav-1.1.3.tar.gz.
File metadata
- Download URL: bollhav-1.1.3.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04ee26d380f130008edda323cc186b1111af8de8ede6aa8ef30db62df7365698
|
|
| MD5 |
9a3982c2d7148e55a03ba7d67920cc84
|
|
| BLAKE2b-256 |
13c5ecaa9d7ec46dd23f8e78f81c6e7b68864a69dab4459807a141745944a79f
|
File details
Details for the file bollhav-1.1.3-py3-none-any.whl.
File metadata
- Download URL: bollhav-1.1.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a60d15116e7d769a9f91055cbbf436e26ec1275c8408175fe407dde1a74b903a
|
|
| MD5 |
31f9c5965477d7b72c8a07af2483783a
|
|
| BLAKE2b-256 |
3c8b9dcb5f4f9754323fe99ad0ead4c73227f097293470f95a6d3f5f2e30783e
|