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 |
| Ancestor filtering | where: {parentId: 123} |
Filter by parent-level properties |
| 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]
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.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file siphon_dsl-0.7.0.tar.gz.
File metadata
- Download URL: siphon_dsl-0.7.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
018a9a48db869fd6391cc85d0d327bfd3228fd88e3093dc6aa778b600522f70b
|
|
| MD5 |
01ff0a21ec1731c36712e69e367d1a89
|
|
| BLAKE2b-256 |
ef4ba65cb756092f94d489bcbccdd9078afc4afd33c343ff25f72f0b21329a35
|
Provenance
The following attestation bundles were made for siphon_dsl-0.7.0.tar.gz:
Publisher:
workflow.yml on alpeshvas/siphon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
siphon_dsl-0.7.0.tar.gz -
Subject digest:
018a9a48db869fd6391cc85d0d327bfd3228fd88e3093dc6aa778b600522f70b - Sigstore transparency entry: 1216327669
- Sigstore integration time:
-
Permalink:
alpeshvas/siphon@d03d7229a50240bc0c11688e2dc8f1021d1da41d -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/alpeshvas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@d03d7229a50240bc0c11688e2dc8f1021d1da41d -
Trigger Event:
release
-
Statement type:
File details
Details for the file siphon_dsl-0.7.0-py3-none-any.whl.
File metadata
- Download URL: siphon_dsl-0.7.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5646f87430eb49f07c6da98487e2c34b1292480792bef04ef0db40a082864310
|
|
| MD5 |
ec6e95a705ee55bdb348d7b2f409ade0
|
|
| BLAKE2b-256 |
f29156c58ca24d73ee12b25f1e459ff4bb47b7af16940ea43227301a38a3a885
|
Provenance
The following attestation bundles were made for siphon_dsl-0.7.0-py3-none-any.whl:
Publisher:
workflow.yml on alpeshvas/siphon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
siphon_dsl-0.7.0-py3-none-any.whl -
Subject digest:
5646f87430eb49f07c6da98487e2c34b1292480792bef04ef0db40a082864310 - Sigstore transparency entry: 1216327727
- Sigstore integration time:
-
Permalink:
alpeshvas/siphon@d03d7229a50240bc0c11688e2dc8f1021d1da41d -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/alpeshvas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@d03d7229a50240bc0c11688e2dc8f1021d1da41d -
Trigger Event:
release
-
Statement type: