Skip to content

Python API

benzsevern edited this page Mar 29, 2026 · 1 revision

Python API

Top-level functions

infermap.map(source, target, **kwargs) -> MapResult

The main entry point. Auto-detects providers based on input type.

import infermap

# Files
result = infermap.map("source.csv", "target.csv")

# DataFrames (Polars or Pandas)
result = infermap.map(source_df, target_df)

# Database
result = infermap.map("data.csv", "postgresql://host/db", table="users")

# With schema file overlay
result = infermap.map("data.csv", "target.csv", schema_file="schema.yaml")

# With required fields
result = infermap.map("data.csv", "target.csv", required=["email", "phone"])

infermap.from_config(path) -> MapResult

Load a saved mapping config. Skips inference entirely.

result = infermap.from_config("mapping.yaml")
remapped = result.apply(new_df)

infermap.MapEngine

Advanced usage with custom configuration.

engine = infermap.MapEngine(
    min_confidence=0.4,     # minimum score to keep a mapping (default: 0.3)
    sample_size=1000,       # rows to sample for profiling (default: 500)
    scorers=infermap.default_scorers() + [my_custom_scorer],
    config_path="infermap.yaml",  # scorer weight overrides
)
result = engine.map(source, target)

MapResult

Method Returns Description
report() dict Structured mapping with per-scorer breakdown
apply(df) DataFrame Remap columns (preserves Polars/Pandas type)
to_config(path) None Save as reusable YAML
to_json() str JSON string of report
Attribute Type Description
mappings list[FieldMapping] Source-to-target mappings
unmapped_source list[str] Source fields with no match
unmapped_target list[str] Target fields with no match
warnings list[str] Required field warnings
metadata dict Timing, scorer config

FieldMapping

Attribute Type Description
source str Source field name
target str Target field name
confidence float Combined score (0.0-1.0)
breakdown dict[str, ScorerResult] Per-scorer scores
reasoning str Human-readable summary

Custom Scorers

@infermap.scorer(name="fhir_type", weight=0.8)
def fhir_scorer(source, target):
    # source and target are FieldInfo objects
    # Return ScorerResult(score, reasoning) or None to abstain
    return infermap.ScorerResult(score=0.9, reasoning="FHIR match")

Clone this wiki locally