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 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
    *,
    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]

Results are also stored in mapper.rows.

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:

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)

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.2.tar.gz (33.2 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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tha_map_runner-0.1.2.tar.gz
  • Upload date:
  • Size: 33.2 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.2.tar.gz
Algorithm Hash digest
SHA256 259da5376de92017dcc1b6a8caa5e3dba9e124353271d55e0de55552e3c82724
MD5 3feb8c8b2116c205a4865252a31b79ac
BLAKE2b-256 a782254d41e98803992852ca3f4b581329d0410675ebe41b804a46febdfcaeb6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tha_map_runner-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4bf2cd6acd1927992d1aa0cfca7997886e97130916b20cc1fdbce8a059cd9b0
MD5 645ea22afb198c2dd41183805298f583
BLAKE2b-256 a7b134a27cf58e14a3b132024bd5534520932f54ae6bc18ae3dd69c736b91efc

See more details on using hashes here.

Provenance

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