Shared utilities for Model Oncology data pipelines
Project description
moncpipelib
moncpipelib is a Dagster-based data-pipeline framework: it provides the resources, IO managers, contract enforcement, lineage, and ingest patterns that Dagster code locations compose into pipelines. It owns the I/O boundary policy (streaming-by-default reads/writes against Postgres and blob), the contract/lineage policy, and the partition/period coordination model.
It is maintained by Model Oncology and developed against our internal data-pipeline needs, released under the Apache 2.0 license.
Features
- PostgreSQL IO Manager -- write Polars DataFrames to PostgreSQL with multiple write modes (full refresh, upsert, append, partitioned)
- PostgreSQL Resource -- streaming/batched reads for large tables via server-side cursors
- Row-level lineage tracking -- UUID7-based lineage with foreign key to a centralized lineage table
- Data contracts -- declarative YAML-based schema validation, auto-enforced on write
- OpenLineage integration -- emit lineage events to Marquez, DataHub, or other backends
- Data transforms --
clean_text,safe_decimal,safe_bool,safe_date, and more
Installation
uv add moncpipelib
# or
pip install moncpipelib
Requires Python 3.11+.
To work from source:
git clone https://github.com/model-oncology-public/moncpipelib
cd moncpipelib
uv sync --all-extras --dev
Quick Start
from dagster import asset, Definitions, EnvVar
import polars as pl
from moncpipelib import PostgresResource, PostgresIOManager, clean_text, safe_decimal
database = PostgresResource(
host=EnvVar("DB_HOST"), port=EnvVar.int("DB_PORT"),
user=EnvVar("DB_USER"), password=EnvVar("DB_PASSWORD"),
database=EnvVar("DB_NAME"),
)
@asset
def orders_bronze(database: PostgresResource) -> pl.DataFrame:
return database.read_batched_to_dataframe("SELECT * FROM raw.orders")
@asset(io_manager_key="silver_io_manager")
def orders_silver(orders_bronze: pl.DataFrame) -> pl.DataFrame:
return orders_bronze.select([
clean_text("order_id"),
safe_decimal("amount"),
])
defs = Definitions(
assets=[orders_bronze, orders_silver],
resources={
"database": database,
"silver_io_manager": PostgresIOManager(
postgres_resource=database,
default_schema="silver",
),
},
)
For more examples, see the auto-generated Cookbook.
Documentation
| Topic | Link |
|---|---|
| Usage examples (auto-generated) | docs/cookbook.md |
| Database resources and IO managers | docs/best-practices.md |
| Data contracts specification | docs/data-contracts-spec.md |
| Row-level lineage tracking | docs/lineage-tracking.md |
| OpenLineage integration | docs/openlineage-integration-spec.md |
| SCD Type 2 guide | docs/scd2-guide.md |
| Security controls | docs/security.md |
Configuration
moncpipelib uses environment variables for global configuration:
| Variable | Default | Description |
|---|---|---|
MONCPIPELIB_DEFAULT_DATABASE |
analytics |
Default database name for contract sources/sinks that omit one |
MONCPIPELIB_OPENLINEAGE_SCHEMA_URL |
(repo URL) | Base URL for OpenLineage custom facet schemas |
MONCPIPELIB_OPENLINEAGE_NAMESPACE |
moncpipelib |
Default namespace for OpenLineage jobs/datasets |
MONCPIPELIB_LINEAGE_TABLE |
data_lineage |
Name of the lineage tracking table |
MONCPIPELIB_LINEAGE_SCHEMA |
lineage |
Schema containing the lineage tracking table |
Development
uv sync --all-extras # Install dev dependencies
uv run pytest # Run tests
uv run ruff check src tests # Lint
uv run mypy src # Type check
uv run ruff format src tests # Format
See CONTRIBUTING.md before opening a pull request.
License
Apache License 2.0 -- see LICENSE.
Project details
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 moncpipelib-0.39.4.tar.gz.
File metadata
- Download URL: moncpipelib-0.39.4.tar.gz
- Upload date:
- Size: 909.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
809ca38d53a27db80f983ebab9aaeb581d4b1a2130f0c7e7eeec616509f4d262
|
|
| MD5 |
fc3b585eced6122e3252c68532377d07
|
|
| BLAKE2b-256 |
4eb93323a15d152e02ed2817240040f4f2e0ece3b973a911270f12f766cbeecc
|
Provenance
The following attestation bundles were made for moncpipelib-0.39.4.tar.gz:
Publisher:
publish-pypi.yml on model-oncology-public/moncpipelib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moncpipelib-0.39.4.tar.gz -
Subject digest:
809ca38d53a27db80f983ebab9aaeb581d4b1a2130f0c7e7eeec616509f4d262 - Sigstore transparency entry: 1999491623
- Sigstore integration time:
-
Permalink:
model-oncology-public/moncpipelib@961188f23564f956ffc700a11795acf6babe437e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/model-oncology-public
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@961188f23564f956ffc700a11795acf6babe437e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file moncpipelib-0.39.4-py3-none-any.whl.
File metadata
- Download URL: moncpipelib-0.39.4-py3-none-any.whl
- Upload date:
- Size: 316.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce9559b83a6f05fcb947ceb8fb603df453be52212140d5e0956a4c7fe8c38adf
|
|
| MD5 |
1f04c1a3c2d03cf8261f368acfa84864
|
|
| BLAKE2b-256 |
5ad8f257b83da0542a603909f87ae123d46d30b93ef5d9a2dbebe3ecc6270f47
|
Provenance
The following attestation bundles were made for moncpipelib-0.39.4-py3-none-any.whl:
Publisher:
publish-pypi.yml on model-oncology-public/moncpipelib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moncpipelib-0.39.4-py3-none-any.whl -
Subject digest:
ce9559b83a6f05fcb947ceb8fb603df453be52212140d5e0956a4c7fe8c38adf - Sigstore transparency entry: 1999491676
- Sigstore integration time:
-
Permalink:
model-oncology-public/moncpipelib@961188f23564f956ffc700a11795acf6babe437e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/model-oncology-public
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@961188f23564f956ffc700a11795acf6babe437e -
Trigger Event:
workflow_dispatch
-
Statement type: