Skip to main content

Join JSON responses into CSV-style rows with dotted-path projection — a Tabular Helper API.

Project description

tha-map-runner

CI

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

Think "left join between rows and a lookup source, with dotted-path projection on the source side."

Install

pip install tha-map-runner

Quick start

from tha_map_runner import enrich_rows

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"}},
]

enriched = 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

enrich_rows(
    rows,                              # list of row dicts
    source,                            # list of dicts to join against
    mapping,                           # {"output_column": "dotted.path"} — callable values planned
    row_key,                           # column name in rows to match on
    source_key,                        # field in source to match on
    *,
    on_no_match="skip",                # "skip" | "error" | "blank"
    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]

on_no_match

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:

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

Composing with tha-csv-runner

from tha_csv_runner import ThaCSV
from tha_map_runner import enrich_rows
import requests

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

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

runner.rows = 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")

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.1.0.tar.gz (33.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.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tha_map_runner-0.1.0.tar.gz
  • Upload date:
  • Size: 33.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.1.0.tar.gz
Algorithm Hash digest
SHA256 4ca262560ddd0a30f07ab48f43c71714d1b425cf8c86109248bcdbbe58efc164
MD5 eaa670ba0bf81fd798d0bb2d09bd57b6
BLAKE2b-256 e0ca5f6ff72cdc73b967b07f18b1a293ffa258c96e5d8e9098b0756b9591298d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_map_runner-0.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: tha_map_runner-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2193de5d2b06439cf39e120a2fdc715b90e170098a3acbb5afc822005072c59c
MD5 d330948fa3d0aaddc59ced12d6c50824
BLAKE2b-256 767f19f75f0bef690f096cbd81ab66b920321b02ce641c9862c29237acffcc28

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_map_runner-0.1.0-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