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.45.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

moncpipelib-0.45.0-py3-none-any.whl (373.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for moncpipelib-0.45.0.tar.gz
Algorithm Hash digest
SHA256 78f86c700df7ea1994316b3e75b748d5ecbeb891fb007f58e016e4e840a62427
MD5 99599cd498c63956916a2ad8bf624b86
BLAKE2b-256 f2223cf2a64505fdeef02b8868756fadcf836cb2fe88c160eaaa4354e759ce6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for moncpipelib-0.45.0.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.45.0-py3-none-any.whl.

File metadata

  • Download URL: moncpipelib-0.45.0-py3-none-any.whl
  • Upload date:
  • Size: 373.3 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.45.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ac70ba87fb886b919a54b2a0193d0a3e93d8effeac066f90d44d203e9e6f2c5
MD5 e2b97b627ce1b9c121d2ab8ea27b58e4
BLAKE2b-256 7e4be7d652df491a3f0f49840ece5aa31d1312daf54cc27f6b7f383e4e1fd0a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for moncpipelib-0.45.0-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