Skip to main content

One query language for every tree — Python bindings for the Quarb engine: JSON, YAML, TOML, CSV, XML, HTML, Markdown, SQLite, kaiv (typed units), filesystem, git, archives, XLSX, and source code (Rust/Python/JS/C), plus jq/XPath/SQL translators

Project description

qua

Python bindings for the Quarb query engine. Quarb reads structured text as an arbor — a tree-spanned graph — and runs one query language over all of it, generalizing what XPath does for XML and jq does for JSON to JSON, YAML, TOML, CSV/TSV, XML, HTML, and Markdown alike. Try it live in the playground.

Install

pip install quarb

This installs the quarb Python module and the qua command (the language is Quarb; qua is its CLI).

Wheels are published for Linux (x86_64, aarch64), macOS (arm64, x86_64), and Windows (x86_64). The extension is built against PyO3's stable ABI (abi3-py38); a single wheel covers CPython 3.8 and later.

The qua command

The entry point covers what the bindings cover — one query over a text document:

qua '/books/*[/price:: > 20]/title::' store.json
echo '{"users":[{"name":"ada"}]}' | qua -f json '/users/*/name::'

The full qua CLI — file systems, git, databases, mail, adapter composition — is the Rust binary: cargo install qua.

Quick start

import quarb

doc = quarb.loads("""{
  "books": [
    {"title": "Sapiens", "price": 25},
    {"title": "Cosmos",  "price": 18}
  ]
}""", "json")

doc.values('/books/*[/price:: > 20]/title::')
# ['Sapiens']

doc.value('/books/*/price:: @| mean')
# 21.5

doc.records('/books/* | rec("t", /title::, "p", /price::)')
# [{'t': 'Sapiens', 'p': 25}, {'t': 'Cosmos', 'p': 18}]

loads(text, format) / load(path) parse once into a Document, queried many times. Results come back typed: ints, floats, strings, None for null, tz-aware datetime for instants, timedelta for durations, Quantity for unit-carrying values, dicts for records. Formats: json, yaml, toml, csv, tsv, xml, html, markdown.

The lower-level quarb.run(query, text, format) and quarb.run_file(query, path) return the result lines as strings — exactly what the qua CLI prints. All errors raise ValueError with the engine's message.

For the query language itself — steps, criteria, readings, patterns, joins — see the user guide and spec.

License

Licensed under either of Apache License, Version 2.0 or the MIT license at your option. Both texts are bundled in the package.

Jupyter

%load_ext quarb.ipython
%quarb_mount fleet.daiv
%quarb /@hosts/*[::power > 0.2kW]::name

%%quarb [NAME] runs a cell-sized query against a named mount; results render as HTML tables, iterate as typed values (quantities keep magnitude + unit), and convert with .df / .df_magnitudes(). pip install quarb[jupyter] pulls IPython and pandas.

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

quarb-0.3.0.tar.gz (427.5 kB view details)

Uploaded Source

Built Distributions

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

quarb-0.3.0-cp38-abi3-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

quarb-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

quarb-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

quarb-0.3.0-cp38-abi3-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

quarb-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file quarb-0.3.0.tar.gz.

File metadata

  • Download URL: quarb-0.3.0.tar.gz
  • Upload date:
  • Size: 427.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quarb-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6a6da3c241b0deffbaff2dc46193165aead51a1423831e45b24dee4df21f2916
MD5 fd37067d8d810a694c4cca1690963459
BLAKE2b-256 acdba5ac181e4a7252abcfd52a9d8e9ee9183d9906e72217d6c3bd28ec804d82

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0.tar.gz:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

File details

Details for the file quarb-0.3.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: quarb-0.3.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quarb-0.3.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7b3dae2f466282b5295ba8037c9c89940b930612566e3d4fdcb2e07af39623de
MD5 d3daf040ccc27670720cc4ab2c77306b
BLAKE2b-256 00bbf53281597f89827b5454c8e3a52d1be17a77f37ec98a0e9ed0c1195497f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0-cp38-abi3-win_amd64.whl:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

File details

Details for the file quarb-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quarb-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 428c3f98c8d78ca4b61aea3568c04db60e2c199aebcda313f71116937f4c2601
MD5 75766e9bf21106ee35099db5febb958e
BLAKE2b-256 1809e5e4c4a1997ede763435e983901a1c4b1c7372d3fc7b3bbbd7347676defe

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

File details

Details for the file quarb-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quarb-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81b2846e0b1a744aee116673e8566c49612fb7fcf92ee62a9ac9f3dabd2934eb
MD5 4ecc06cd077122b13cb6952db7459d11
BLAKE2b-256 125c28b87d4eca74b997ec47049f5a16bf3ad719ac218fa8f3c247ffb058094f

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

File details

Details for the file quarb-0.3.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: quarb-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: CPython 3.8+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quarb-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03a01b36aa127541621a8bf01b151420dcd7c7fe46d34b638591e45f9f4bc587
MD5 b99034ddc784718ffb1effe7d1323568
BLAKE2b-256 4b07fa8a0df572d0945043f4c54d69d75295cc3d7fd57f65df58377ab04349ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

File details

Details for the file quarb-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for quarb-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e51ea937cae10bda21104be51fd1e464cf8f549f7d7d98906d5c376116a5d9e5
MD5 ac36b1dc2f58e32910b265733fd356e4
BLAKE2b-256 a87b0fd7144d2b5065a2c2b9a312e7cfba6d9e68588246be6aab1f01c1d5fc9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for quarb-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-pypi.yml on deyanovich/quarb-rs

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

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