Skip to main content

A Tabular Helper API library that maps and joins dict-like data into row dicts using dotted-path projection.

Project description

tha-map-runner

CI

A small Python library that joins a list of row dicts with a lookup source on a single key, projecting values into flat row columns via a mapping config.

Supports left, inner, and anti joins — all with dotted-path projection on the source side.

Install

pip install tha-map-runner

Quick start

from tha_map_runner import ThaMap

rows = [
    {"Org BK": "school-001", "Start Date": "08/15"},
    {"Org BK": "school-002", "Start Date": "08/16"},
]

api_response = [
    {"sourcedId": "school-001", "name": "Lincoln Elementary", "parent": {"sourcedId": "dist-A"}},
    {"sourcedId": "school-002", "name": "Roosevelt Middle",   "parent": {"sourcedId": "dist-A"}},
]

mapper = ThaMap()
enriched = mapper.enrich_rows(
    rows=rows,
    source=api_response,
    mapping={
        "Org Name":  "name",
        "Parent BK": "parent.sourcedId",
    },
    row_key="Org BK",
    source_key="sourcedId",
)

How it works

  1. Builds an index of source on source_key — O(n+m), no nested loops
  2. For each row, looks up a match by row[row_key]
  3. Walks dotted paths ("parent.sourcedId") into the matched source entry
  4. Projects resolved values into new columns on a copy of the row
  5. Returns a new list — input is never mutated

Rows whose row status is in skip_statuses are passed through unchanged.

API

ThaMap

ThaMap()

mapper.enrich_rows()

mapper.enrich_rows(
    rows,                              # list of row dicts
    source,                            # list of dicts to join against
    mapping,                           # {"output_column": "dotted.path"}
    row_key,                           # column name in rows to match on
    source_key,                        # field in source to match on
    *,
    how="left",                        # "left" | "inner" | "anti"
    on_no_match="skip",                # "skip" | "error" | "blank"  (left only)
    allow_empty_source=False,          # if True, empty source is not an error
    skip_statuses=["error", "warning"],# rows with these statuses are passed through
) -> list[dict]

Results are also stored in mapper.rows.

how

Value Behaviour
"left" All rows kept; unmatched rows handled by on_no_match
"inner" Only matched rows kept; mapping applied
"anti" Only unmatched rows kept; no mapping applied

Rows whose row status is in skip_statuses are always passed through unchanged, regardless of how.

on_no_match (left join only)

Value Behaviour
"skip" Row is returned unchanged — no new columns added
"error" row status="error", message=..., mapping columns set to ""
"blank" Mapping columns set to "", row status untouched

skip_statuses

By default, rows already marked row status="error" or row status="warning" are passed through without processing. Override with any list:

mapper.enrich_rows(..., skip_statuses=["error"])               # only skip errors
mapper.enrich_rows(..., skip_statuses=["error", "pending"])    # custom statuses
mapper.enrich_rows(..., skip_statuses=[])                      # process every row regardless

Composing with tha-csv-runner

from tha_csv_runner import ThaCSV
from tha_map_runner import ThaMap
import requests

runner = ThaCSV()
runner.read("Step 1 of 2", "input.csv", ["Org BK"])

api_response = requests.get(api_url).json()

mapper = ThaMap()
enriched = mapper.enrich_rows(
    rows=runner.rows,
    source=api_response,
    mapping={"Org Name": "name", "District": "parent.sourcedId"},
    row_key="Org BK",
    source_key="sourcedId",
)

runner.write("Step 2 of 2", "output.csv", rows=enriched)

Alternatives

This library is intentionally limited in scope — it handles one specific pattern: joining row dicts against a lookup list on a single key and projecting values via dotted paths. For more general needs:

  • pandasDataFrame.merge() covers join operations with far more flexibility (outer, multi-key, aggregations)
  • glom — powerful dotted-path access and transformation for arbitrarily nested Python data structures
  • jmespath — JSON path-style queries for extracting values from nested dicts

Choose this library when you're already working with tha-* row dicts and want to join them against a lookup list in one call — no DataFrame conversion, left/inner/anti join and projection in a single step.

License

MIT

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

tha_map_runner-0.2.1.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

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

tha_map_runner-0.2.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file tha_map_runner-0.2.1.tar.gz.

File metadata

  • Download URL: tha_map_runner-0.2.1.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tha_map_runner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 246944793639bb6419798be9511d992091a78f4a3036c6e1db374bab16caf9da
MD5 9283274415e9a1e73ca41c4426879f62
BLAKE2b-256 f1af6305dc0903cddab56801a02e3b8983a77be26e587de8e4514698498de297

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_map_runner-0.2.1.tar.gz:

Publisher: publish.yml on tha-guy-nate/tha-map-runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tha_map_runner-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tha_map_runner-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tha_map_runner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afc199032d8d5f2f8310f115968932c34d514b7aa65e36d2ba5a0c2949dd2c9b
MD5 32e5880725a568311056b4d888181634
BLAKE2b-256 be2e8e6cad2be2c3e12582e182ff0a55d83ab764c718c64f827e0bd594b4a08a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_map_runner-0.2.1-py3-none-any.whl:

Publisher: publish.yml on tha-guy-nate/tha-map-runner

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