Skip to main content

Minimal DSL for API data extraction

Project description

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
Filtering where: {status: "active"} Filter by field values
Projection select: {new: "old"} Rename and reshape fields
Collect collect: true Return all matches (default: first only)

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

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]

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.

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

siphon_dsl-0.4.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

siphon_dsl-0.4.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file siphon_dsl-0.4.0.tar.gz.

File metadata

  • Download URL: siphon_dsl-0.4.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for siphon_dsl-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d5d316335b13595399351ae7832880ebb30bffee0b502e6bcfbc3ace508a6874
MD5 0534f55f4a7f7f7e7f36b646be74d279
BLAKE2b-256 7fb70a80fc9a57aa7586f93271cc57a72a218f46e55434076355583b2b46d812

See more details on using hashes here.

File details

Details for the file siphon_dsl-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: siphon_dsl-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for siphon_dsl-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 030e611acb982b0aef7c48ec11e6b112d6a182a7438493daa23dda6833df9337
MD5 04a85624b6f0230b3233faa9f7988a0a
BLAKE2b-256 2018ca4b34b508fc6b6a651aced201aadf5a70bbff00fcc74ed99383dfec6bd2

See more details on using hashes here.

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