Skip to main content

Comprehensive open-source Python library for schema inference, normalization, transformation, and DDL generation

Project description

helix-ir

PyPI version License Python versions Tests

helix-ir is a comprehensive open-source Python library for schema inference, normalization, transformation, and DDL generation. It takes raw, messy document streams (JSON, Parquet, MongoDB, REST APIs, Kafka) and produces clean, typed, normalized schemas ready for any data warehouse — Postgres, Redshift, BigQuery, Snowflake, Databricks, or DuckDB.

Installation

pip install helix-ir
# With optional extras:
pip install 'helix-ir[mongo]'       # MongoDB source
pip install 'helix-ir[postgres]'    # PostgreSQL source
pip install 'helix-ir[kafka]'       # Kafka source
pip install 'helix-ir[dev]'         # Development tools

Hello World

from helix_ir import infer, normalize, compile_ddl

# 1. Infer schema from documents
documents = [
    {"order_id": "ORD-001", "customer_email": "alice@example.com",
     "amount": 99.99, "items": [{"sku": "A1", "qty": 2}]},
    {"order_id": "ORD-002", "customer_email": "bob@example.com",
     "amount": 149.50, "items": [{"sku": "B3", "qty": 1}]},
]

schema = infer(documents, name="orders")
print(schema)
# Schema('orders', [order_id: string, customer_email: string, amount: double, items: list<...>])

# 2. Normalize to 1NF (flatten nested arrays)
plan = normalize(schema)
print(plan.table_names())
# ['orders', 'orders__items']

# 3. Compile DDL for your target warehouse
ddl = compile_ddl(plan, dialect="duckdb")
print(ddl)
# CREATE TABLE IF NOT EXISTS "orders" (
#   "__id" VARCHAR NOT NULL,
#   "order_id" VARCHAR NOT NULL,
#   ...
# );
# CREATE TABLE IF NOT EXISTS "orders__items" (
#   "__id" VARCHAR NOT NULL,
#   "__parent_id" VARCHAR NOT NULL,
#   ...
# );

Quick Start: Infer + Normalize + DDL

from helix_ir import infer, normalize, compile_ddl
from helix_ir.ddl import DDLOptions

# Infer with PII detection
schema = infer(
    documents,
    name="customers",
    sample_size=5000,
    seed=42,
    detect_pii=True,
    pii_locale="in",   # India locale: detects PAN, Aadhaar, GSTIN
)

# Check PII annotations
for name, ht in schema.fields:
    if ht.pii_class:
        print(f"  {name}: {ht.pii_class}")

# Normalize
plan = normalize(schema, strategy="1nf")

# Generate DDL with options
opts = DDLOptions(if_not_exists=True, schema_prefix="raw")
ddl_pg = compile_ddl(plan, dialect="postgres", options=opts)
ddl_bq = compile_ddl(plan, dialect="bigquery", options=opts)

print(ddl_pg.to_sql())
print(ddl_bq.to_sql())

Quick Start: Transformation Pipeline

from helix_ir.transform import Table
from helix_ir.transform.expression import col, lit

# Build a lazy query plan
table = Table("orders")
result = (
    table
    .filter(col("status") == lit("shipped"))
    .select(col("order_id"), col("amount"), col("customer_email"))
    .sort(col("amount").desc())
    .limit(100)
)

# Compile to SQL for any dialect
print(result.to_sql("duckdb"))
print(result.to_sql("bigquery"))
print(result.to_sql("snowflake"))

Quick Start: Schema Diff

from helix_ir.diff import diff

# Compare two schema versions
schema_v1 = infer(old_documents, name="orders")
schema_v2 = infer(new_documents, name="orders")

schema_diff = diff(schema_v1, schema_v2)

print(f"Breaking changes: {schema_diff.has_breaking_changes}")
for change in schema_diff.changes:
    print(f"  [{change.severity.upper()}] {change.description}")

# Filter by severity
breaking = schema_diff.filter("breaking")

CLI

# Infer schema from a file
helix-ir infer data.ndjson --name orders --locale in

# Generate DDL
helix-ir ddl schema.json --dialect snowflake

# Normalize + DDL
helix-ir normalize schema.json --strategy 1nf --dialect bigquery

# Diff two schemas
helix-ir diff schema_v1.json schema_v2.json

# Generate data quality tests
helix-ir test schema.json --sensitivity 1.5

# Generate lineage graph
helix-ir lineage schema.json --format dot

Module Overview

Module Description
helix_ir.infer Schema inference from document streams using Algorithm R reservoir sampling
helix_ir.types HelixType dataclass + type lattice (join, meet, subsumes)
helix_ir.schema Schema class + Path addressing
helix_ir.normalize 1NF / MongoDB / inline_small normalization strategies
helix_ir.transform Lazy SQL transformation DSL with multi-dialect compilation
helix_ir.ddl DDL generation for DuckDB, Postgres, Redshift, BigQuery, Snowflake, Databricks
helix_ir.diff Schema diff with safe/risky/breaking change classification
helix_ir.pii PII detection via field name heuristics + regex patterns (IN/US/EU)
helix_ir.lineage Field-level lineage tracking with OpenLineage export
helix_ir.sources Connectors: JSON, Parquet, MongoDB, PostgreSQL, REST, Kafka
helix_ir.test Automatic data quality test generation from schema metadata
helix_ir.cli Typer-based CLI with rich output

Documentation

Full documentation: https://helix-ir.readthedocs.io/

License

Apache 2.0 — Copyright 2024 Sparsh Prakash

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

helix_ir-0.1.0.tar.gz (60.8 kB view details)

Uploaded Source

Built Distribution

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

helix_ir-0.1.0-py3-none-any.whl (78.1 kB view details)

Uploaded Python 3

File details

Details for the file helix_ir-0.1.0.tar.gz.

File metadata

  • Download URL: helix_ir-0.1.0.tar.gz
  • Upload date:
  • Size: 60.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for helix_ir-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2afa6ca9801a7f3a68cfa54b5f0a8d50c943951a5ba65c7dbc4616f58e4c2648
MD5 5c669d447263ba57a6d0c245d0cfde8c
BLAKE2b-256 c173f46c892b4b48224ecab13f14bf7993963a862d4164b539098fc814a473ed

See more details on using hashes here.

File details

Details for the file helix_ir-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: helix_ir-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 78.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for helix_ir-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc6fe4d2312991e14744407cda3da4a329dea9c428f7cfbc6b72ede305cbf70e
MD5 7ae26c6bcb9758e0e3d56f9041a3e4e3
BLAKE2b-256 243db29fcd48f79eff31bff9af14e55d2d9342b93587efada7705a7630b2adb1

See more details on using hashes here.

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