Python client for MorphQL — transform data with declarative queries.
Project description
morphql · Python client
Python client for MorphQL — a declarative DSL for structural data transformation.
Delegates execution to the MorphQL CLI or a running MorphQL server. Zero external dependencies. Python >= 3.8.
Installation
pip install morphql
Quick start
from morphql import MorphQL
# One-shot static call (CLI provider)
result = MorphQL.execute(
"from json to json transform set name = source.firstName",
data={"firstName": "Alice"},
)
print(result) # {"name":"Alice"}
# From a .morphql file
result = MorphQL.execute_file("transform.morphql", data={"x": 1})
# Instance with preset defaults (server provider)
morph = MorphQL(provider="server", server_url="http://localhost:3000")
result = morph.run("from json to json transform set x = source.x", data={"x": 42})
result = morph.run_file("transform.morphql", data={"x": 42})
Providers
| Provider | How it works |
|---|---|
"cli" |
Runs morphql CLI via subprocess (default) |
"server" |
POST {server_url}/v1/execute via urllib |
Options
| Option | Default | Env var |
|---|---|---|
provider |
"cli" |
MORPHQL_PROVIDER |
runtime |
"node" |
MORPHQL_RUNTIME |
cli_path |
"morphql" |
MORPHQL_CLI_PATH |
node_path |
"node" |
MORPHQL_NODE_PATH |
qjs_path |
auto-resolved | MORPHQL_QJS_PATH |
cache_dir |
$TMPDIR/morphql |
MORPHQL_CACHE_DIR |
server_url |
"http://localhost:3000" |
MORPHQL_SERVER_URL |
api_key |
None |
MORPHQL_API_KEY |
timeout |
30 (seconds) |
MORPHQL_TIMEOUT |
Priority: call kwarg > instance default > env var > hardcoded default.
API
Static
MorphQL.execute(query, data=None, **options) -> str
MorphQL.execute_file(query_file, data=None, **options) -> str
Instance
morph = MorphQL(**defaults)
morph.run(query, data=None, **options) -> str
morph.run_file(query_file, data=None, **options) -> str
data accepts str (JSON), dict, list, or None.
Exceptions
| Situation | Exception |
|---|---|
query missing or empty |
ValueError |
| Query file not found | FileNotFoundError |
| CLI exits with error | RuntimeError |
| Server HTTP error | RuntimeError |
| Server unreachable | RuntimeError |
Running tests
cd packages/python
PYTHONPATH=src python -m unittest discover tests/
# or with pytest:
pip install pytest
pytest
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 morphql-0.1.38.tar.gz.
File metadata
- Download URL: morphql-0.1.38.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2b949eb2db74e297cd62a5cd1105faa0f307a3df18d8b213d6c208cb6d0a754
|
|
| MD5 |
e124b6d6ca81ed44ef1187b440f7290e
|
|
| BLAKE2b-256 |
41a840d9446879a86c54c8de66fc2b49ce4917f5baebc0d73423716e43f3d35e
|
Provenance
The following attestation bundles were made for morphql-0.1.38.tar.gz:
Publisher:
publish.yml on Hyperwindmill/morphql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphql-0.1.38.tar.gz -
Subject digest:
b2b949eb2db74e297cd62a5cd1105faa0f307a3df18d8b213d6c208cb6d0a754 - Sigstore transparency entry: 1186003407
- Sigstore integration time:
-
Permalink:
Hyperwindmill/morphql@06bfefac1d24bf6346be9da5e00a0221f8dbb054 -
Branch / Tag:
refs/tags/v0.1.38 - Owner: https://github.com/Hyperwindmill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06bfefac1d24bf6346be9da5e00a0221f8dbb054 -
Trigger Event:
push
-
Statement type:
File details
Details for the file morphql-0.1.38-py3-none-any.whl.
File metadata
- Download URL: morphql-0.1.38-py3-none-any.whl
- Upload date:
- Size: 6.5 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 |
b615b8b2caf197a14c6264c6f50cb418675a247aca43da3bbd24d42d75abb08c
|
|
| MD5 |
a7ad9efca57a5072a705b2a828c4b978
|
|
| BLAKE2b-256 |
5c4ad2e8a89b13aa15239f7c2d6531d22b0051acdbb0f93029eb983d8961c245
|
Provenance
The following attestation bundles were made for morphql-0.1.38-py3-none-any.whl:
Publisher:
publish.yml on Hyperwindmill/morphql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphql-0.1.38-py3-none-any.whl -
Subject digest:
b615b8b2caf197a14c6264c6f50cb418675a247aca43da3bbd24d42d75abb08c - Sigstore transparency entry: 1186003432
- Sigstore integration time:
-
Permalink:
Hyperwindmill/morphql@06bfefac1d24bf6346be9da5e00a0221f8dbb054 -
Branch / Tag:
refs/tags/v0.1.38 - Owner: https://github.com/Hyperwindmill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06bfefac1d24bf6346be9da5e00a0221f8dbb054 -
Trigger Event:
push
-
Statement type: