Skip to main content

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

moncpipelib-0.41.3.tar.gz (908.4 kB view details)

Uploaded Source

Built Distribution

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

moncpipelib-0.41.3-py3-none-any.whl (331.9 kB view details)

Uploaded Python 3

File details

Details for the file moncpipelib-0.41.3.tar.gz.

File metadata

  • Download URL: moncpipelib-0.41.3.tar.gz
  • Upload date:
  • Size: 908.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for moncpipelib-0.41.3.tar.gz
Algorithm Hash digest
SHA256 cd6c69f8b396e36f15e43c5e41e252d38a36bb4004cbc1457ea46537bcb7ff7e
MD5 43b4d91216206796739cedfc72f6aacf
BLAKE2b-256 713398e3577a84ecab6473cd10430dac78b4ddaa23bc5303f9b2996389dd7b09

See more details on using hashes here.

Provenance

The following attestation bundles were made for moncpipelib-0.41.3.tar.gz:

Publisher: publish-pypi.yml on model-oncology-public/moncpipelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moncpipelib-0.41.3-py3-none-any.whl.

File metadata

  • Download URL: moncpipelib-0.41.3-py3-none-any.whl
  • Upload date:
  • Size: 331.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for moncpipelib-0.41.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c975f7ff2340ad6d8f6fd9b56ebd4f2e8a6a3b359d653a11d88417e87fda1e46
MD5 1ace55cd9c52cdee53feef4ee10373f2
BLAKE2b-256 059a8aa4b42c6f51ad2d50de153ff3ad1199a068ab7ab41e450771f4cc19aa63

See more details on using hashes here.

Provenance

The following attestation bundles were made for moncpipelib-0.41.3-py3-none-any.whl:

Publisher: publish-pypi.yml on model-oncology-public/moncpipelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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