Skip to main content

polars-lineage

Extract column-level lineage from Polars LazyFrame transformations.

This PoC uses a metadata-first workflow through a LazyFrame.lineage namespace. Attach source metadata with lineage.add_source(...), then run lineage.extract().

Install and Setup

pip install polars-lineage

For local development:

uv sync --dev

Python API (Metadata First)

Importing polars_lineage registers LazyFrame.lineage.

lineage.add_source(...) accepts:

  • name: logical source name
  • uri: source URI
  • optional destination_table: explicit destination FQN

If destination_table is not provided, a deterministic destination FQN is derived.

Example:

import polars as pl
import polars_lineage  # registers LazyFrame.lineage namespace

df_orders = (
    pl.DataFrame({"id": [1, 2], "amount": [10, 20]})
    .lazy()
    .lineage.add_source(name="orders", uri="postgres://warehouse/svc.db.raw.orders")
)

df_accounts = (
    pl.DataFrame({"id": [1, 2], "segment": ["A", "B"]})
    .lazy()
    .lineage.add_source(name="accounts", uri="https://crm/accounts")
)

lineage = (
    df_orders.join(df_accounts, on="id", how="left")
    .with_columns(pl.col("amount").alias("amount_copy"))
    .lineage.extract()
)

print(lineage)

markdown = (
    df_orders.join(df_accounts, on="id", how="left")
    .with_columns(pl.col("amount").alias("amount_copy"))
    .lineage.to_markdown()
)

print(markdown)

URI parsing notes:

  • If the URI path ends with a table FQN (service.database.schema.table), that FQN is used.
  • Otherwise lineage derives source FQN from URI parts:
    • service: URI scheme
    • database: URI hostname (or external)
    • schema: public
    • table: final URI path segment

Namespace Notes

  • lineage.add_source(...) returns the same pl.LazyFrame instance.
  • Metadata is propagated through common lazy operations (including joins).
  • lineage.extract() returns deterministic OpenMetadata-style payloads.

Current Capabilities

  • Projection lineage (select, with_columns)
  • Literals and aliases
  • Basic expression dependency extraction (arithmetic, casts, conditional-like patterns)
  • Transitive dependency resolution
  • Join-aware attribution with explicit left/right mapping aliases
  • Group-by aggregation expression and key coverage
  • Deterministic OpenMetadata payload export
  • Deterministic custom JSON export via typed LineageDocument model
  • Deterministic Markdown lineage rendering

Current Constraints

  • Multiple joins in one parsed plan are rejected.
  • Ambiguous non-join overlapping columns are rejected with clear errors.
  • For static type checking, dynamically registered LazyFrame.lineage may require stubs.

Development

uv run pytest
uv run ruff check .
uv run mypy
uv build

Metadata

Release files for polars-lineage 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-lineage 0.1.6
File Size Uploaded Provenance Actions
polars_lineage-0.1.6.tar.gz 11.9 kB With provenance Details for polars_lineage-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polars-lineage 0.1.6
File Interpreter ABI Platform Actions
polars_lineage-0.1.6-py3-none-any.whl Python 3 none any Details for polars_lineage-0.1.6-py3-none-any.whl

Total release size: 30.9 kB

Release files / polars_lineage-0.1.6.tar.gz

Download URL polars_lineage-0.1.6.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e99f7cd5d348bd6265fe29508783320a8b0648c25d7f5e5345e59df60ad513
BLAKE2b-256 checksum
How to use checksums
7f27574557c44f4077b191e9484df36a3d0b55820cab52d6f1e8158d2bcdb0fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.

Transparency log

Release files / polars_lineage-0.1.6-py3-none-any.whl

Download URL polars_lineage-0.1.6-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b111cf7226bba731a19ea818f4ff88acad523fec98598928351139bbe08c5ecc
BLAKE2b-256 checksum
How to use checksums
eca0591d408249bda71950878d55ef7cba893caf9ec194ae036f0285d6189afa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.

Transparency log

Security for polars-lineage 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for polars_lineage-0.1.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page