Skip to main content

Siphon

A minimal DSL for extracting data from JSON APIs.

Like a siphon draws liquid from a container, Siphon draws the data you need from nested JSON structures—just define the paths, and let it flow.

Install

pip install siphon-dsl

Or with uv:

uv add siphon-dsl

Quick Start

from siphon import process

data = {
    "data": {
        "id": "prod_123",
        "items": [
            {"id": 1, "status": "active", "name": "Widget"},
            {"id": 2, "status": "inactive", "name": "Gadget"},
            {"id": 3, "status": "active", "name": "Thing"},
        ],
    }
}

spec = {
    "extract": {
        "id": "$.data.id",
        "all_active": {
            "path": "$.data.items[*]",
            "where": {"status": "active"},
            "select": {"item_id": "id", "item_name": "name"},
            "collect": True,
        },
    }
}

result = process(spec, data)

Output:

{
  "id": "prod_123",
  "all_active": [
    {"item_id": 1, "item_name": "Widget"},
    {"item_id": 3, "item_name": "Thing"}
  ]
}

Features

Feature Syntax Description
Simple paths $.data.id Extract nested values
Array iteration $.items[*].name Traverse arrays
List indexing items[0].id / names[-1] Pick a specific list position (supports negative)
Root capture from: "$" Iterate root once — lets a pipeline stage project top-level scalars
Pipeline $stages in select select: {x: "$stages.act.y"} Carry a prior stage's value as a literal into the current stage's projection
Filtering where: {status: "active"} Filter by field values
Ancestor filtering where: {parentId: 123} Filter by parent-level properties
Projection select: {new: "old"} Rename and reshape fields
Coalesce select: {price: "sale || list"} First non-null path wins (SQL-style ||)
Collect collect: true Return all matches (default: first only)
Reduce reduce: "min_time" Aggregate array values to a single result

Spec Format

Simple extraction

extract:
  id: "$.data.id"
  name: "$.data.name"

Extended extraction

extract:
  active_items:
    path: "$.data.items[*]"
    where: {status: "active"}
    select: {item_id: "id", item_name: "name"}
    collect: true

List indexing ([N])

Any path segment can drill into a list at a specific position with [N]. Negative indices count from the end; out-of-bounds or non-list values resolve to None. Indexing composes with ||:

extract:
  rows:
    path: "$.items[*]"
    select:
      # Try the first tier, fall back to a flat price field
      amount: "tieredPrices[0].amount || price.amount"
      last_name: "names[-1]"
    collect: true

[*] and [N] are distinct — [*] iterates, [N] picks one element.

Coalesce in select

A select path string may contain || to declare a fallback chain. Segments are tried left-to-right; the first one resolving to a non-None value wins; otherwise the field is None. Any number of segments is supported.

extract:
  products:
    path: "$.products[*]"
    select:
      id: id
      price: "sale_price || list_price"   # fall back to list_price if sale_price is null
      label: "customLabel || title || ticketCategory"
    collect: true

Reduce (aggregation)

extract:
  earliest_slot:
    path: "$.items[*].from_datetime"
    reduce: min_time          # earliest time-of-day across all items

  latest_slot:
    path: "$.items[*].to_datetime"
    reduce: max_time          # latest time-of-day across all items

  total_price:
    path: "$.items[*].price"
    reduce: sum

  unique_categories:
    path: "$.items[*].category"
    reduce: distinct

Available operators:

Operator Description
min_time / max_time Earliest/latest time-of-day — accepts ISO 8601 datetime or plain HH:MM / HH:MM:SS (ignores date + timezone)
min_date / max_date Earliest/latest calendar date (ignores time)
min_datetime / max_datetime Earliest/latest full datetime (timezone-normalised)
min_int / max_int Minimum/maximum numeric value
sum Sum of numeric values
count Count of non-null values (returns 0 for empty)
first / last First or last value in traversal order
concat Join values as a string (default separator ", ")
distinct Deduplicated list, preserving first-seen order

For concat with a custom separator use the dict form:

"reduce": {"op": "concat", "sep": " | "}

Fetch from API

from siphon import fetch_and_process

spec = {
    "request": {"path": "/products"},
    "extract": {
        "id": "$.data.id",
        "names": {"path": "$.data.items[*].name", "collect": True},
    },
}

result = fetch_and_process(spec, "https://api.example.com")

Requires requests:

pip install siphon-dsl[http]

Typed Specs (Pydantic)

from siphon.typed import process_spec, ExtractSpec, FieldSpec

spec = ExtractSpec(
    extract={
        "id": "$.data.id",
        "active_items": FieldSpec(
            path="$.data.items[*]",
            where={"status": "active"},
            select={"item_id": "id", "name": "name"},
            collect=True,
        ),
    }
)

result = process_spec(spec, data)

Requires pydantic:

pip install siphon-dsl[typed]

Why Siphon?

  • Minimal — ~100 lines of code, no dependencies
  • Declarative — specs are data, not code
  • Composable — combine paths, filters, and projections

Spec History

See specs/ for version history and full documentation. Latest: v0.12 — pipeline stages can capture root scalars via from: "$" and reference prior stages from select via $stages.<id>.<field>.

License

MIT

Metadata

Release files for siphon-dsl 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for siphon-dsl 0.12.0
File Size Uploaded Provenance Actions
siphon_dsl-0.12.0.tar.gz 11.6 kB With provenance Details for siphon_dsl-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for siphon-dsl 0.12.0
File Interpreter ABI Platform Actions
siphon_dsl-0.12.0-py3-none-any.whl Python 3 none any Details for siphon_dsl-0.12.0-py3-none-any.whl

Total release size: 25.0 kB

Release files / siphon_dsl-0.12.0.tar.gz

Download URL siphon_dsl-0.12.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e576e6921f1302f9f34c45e2e92fdbe543bdbf1a147c76ecb846495af019de3a
BLAKE2b-256 checksum
How to use checksums
1019efe71f439315e57721babb0ae219016e79cfe9d1a6e194e2f2e99aad0166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 22, 2026.

Transparency log

Release files / siphon_dsl-0.12.0-py3-none-any.whl

Download URL siphon_dsl-0.12.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e26639ec29f36cec2c1c0a053af6eafec0ea6f48fb2e12d57b527e7858a44c1
BLAKE2b-256 checksum
How to use checksums
397cf41724ffcac809e09e6c91c2645baaa717b3b67c08ec0ecde5ba03844450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 22, 2026.

Transparency log

Security for siphon-dsl 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for siphon_dsl-0.12.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page