Skip to main content

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphql-0.1.46.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

morphql-0.1.46-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file morphql-0.1.46.tar.gz.

File metadata

  • Download URL: morphql-0.1.46.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for morphql-0.1.46.tar.gz
Algorithm Hash digest
SHA256 31a152035e13d2dccc39d59185b61fa716aecb5695f752bc4d946c6341b121fb
MD5 15fa62a10698e5542391c87ff000a121
BLAKE2b-256 aad17b8a4e6d666e7cffcbb7c8101ce9857dbdd64ae306f4f4b81d5e98f3bc8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for morphql-0.1.46.tar.gz:

Publisher: publish.yml on Hyperwindmill/morphql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file morphql-0.1.46-py3-none-any.whl.

File metadata

  • Download URL: morphql-0.1.46-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.14

File hashes

Hashes for morphql-0.1.46-py3-none-any.whl
Algorithm Hash digest
SHA256 61388d8753744fe69a06af09bec5ab522d2199d56fa6be818c5fe36d5eae6545
MD5 96a01dbff63416c3a03c7964894b8970
BLAKE2b-256 896690719f7b9cbe7e693ec1c44ee8519d97c1d769d2062703e8a63d6a5b3f83

See more details on using hashes here.

Provenance

The following attestation bundles were made for morphql-0.1.46-py3-none-any.whl:

Publisher: publish.yml on Hyperwindmill/morphql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.46 This release

2 files

0.1.45

2 files

0.1.44

2 files

0.1.43

2 files

0.1.42

2 files

0.1.41

2 files

0.1.39

2 files

0.1.38

2 files

0.1.37

2 files

0.1.36

2 files

0.1.35

2 files

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