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.43.3.tar.gz (959.6 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.43.3-py3-none-any.whl (354.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for moncpipelib-0.43.3.tar.gz
Algorithm Hash digest
SHA256 ce33c4b9799d4a51f488fdc0f6f335accd503827e4c460913f77a6caa6e64032
MD5 9ec2adc7c4d9156e4f325bd3cb7f3ffe
BLAKE2b-256 b97a1b9bb1954c8e39808b7d1164b79f69eae99f34a81dd1b21581c37578a614

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: moncpipelib-0.43.3-py3-none-any.whl
  • Upload date:
  • Size: 354.6 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.43.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0fd94f13966bdcf2f51a7225ccec9841007232f630627777787d51c037a17b23
MD5 943bdbed7e705a4c8d8cde2e21c6596d
BLAKE2b-256 5daa600120beb1f4c02464c8eb97a049d2eeb11cf21205cb67e136de7128b25c

See more details on using hashes here.

Provenance

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