Python bindings for JSONata
Project description
Python bindings for JSONata.
Usage
from pyjsonata import jsonata
my_expression = "$"
my_json = "{'foo': 'bar'}"
# "{'foo': 'bar'}"
result = jsonata(my_expression, my_json)
With exception handling:
from pyjsonata import jsonata, PyjsonataError
my_expression = "$"
my_json = "{'foo': 'bar'}"
try:
# "{'foo': 'bar'}"
result = jsonata(my_expression, my_json)
except PyjsonataError as e:
print("Error: ", e)
That’s it! Return values are always strings.
About
The reference implementation for JSONata is written in JavaScript. I have a separate library that makes this accessible from C via Duktape. This is a Python wrapper that calls into that library using Python’s built-in ctypes library, which should be portable to most Python interpreters.
At first I tried using py_mini_racer to run the JSONata library, but that package is around 40mb because it ships the complete V8 JavaScript runtime. In contrast this library is about 650k.
Building Packages
Source
Source packages are currently broken until I can be bothered to rewrite jsonata-c’s Makefile in Python, as required by setuptools.
🖕 setuptools.
Wheels
pyjsonata can be built to the manylinux2014 standard. There is no Windows support at this time.
The standard way to build manylinux2014 compatible extensions is with a bunch of Centos 7 Docker containers. The idea is that by linking against Centos 7 libc, the resultant binaries will be “portable enough” to modern systems. You don’t have to use these, but it’s not a bad idea.
Without Docker
Install gcc, patchelf and make from your distro repository
Install Python build deps:
python3 -m pip install setuptools wheel auditwheel
To build:
git submodule update --init --recursive
python3 -m setup.py bdist_wheel
cd dist && auditwheel repair ./*.whl
mv wheelhouse/*.whl .
This will make you manylinux2014 wheels. These wheels are tagged to your specific Python version and ABI, like cp37-cp37m, but in reality, they should be py3-none. I can’t figure out how to make setuptools understand that. I think you can safely manually re-tag these by unzipping the wheel, editing the metadata in the WHEEL file, rezipping it, and changing the tag in the filename, but I haven’t yet tested whether that yields the desired results.
However, the arch tag, e.g. x86_64, aarch64, armv7l etc, is necessary.
With Docker
./build.sh <arch>
arch must be one of the architectures for which manylinux2014 build containers are provided. For example, if you are building on aarch64:
./build.sh aarch64
This will download the appropriate container and run the build. Built wheels are in the dist directory.
If you are me:
python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*manylinux2014_*.whl
Testing
Pytest
From the repository root:
python3 -m pip install pytest
python3 -m pytest
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 Distributions
Built Distributions
File details
Details for the file pyjsonata-0.0.1a10-cp39-cp39-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyjsonata-0.0.1a10-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 285.0 kB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24f87e13d7e87f0d72798061f5888f1c928190cdc6a4fe43e5b467aefe09542b |
|
MD5 | dffd3893f30b380d8d5f9255cfd10bf0 |
|
BLAKE2b-256 | 64fb9978597de662cf70348beb104754e09e3b08ccbf5bcbc653862aaeb3c4e5 |
File details
Details for the file pyjsonata-0.0.1a10-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyjsonata-0.0.1a10-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 285.0 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f11d7c08cc128c6e150f464b731787d39dfad009ce06914b44c386db724a734 |
|
MD5 | 0e00914b417b890ce5c7198f47d24d9b |
|
BLAKE2b-256 | 623d09f9561357f328bce76ddeba5dd100e82c4af9041993846bd0b1ab31cfdc |
File details
Details for the file pyjsonata-0.0.1a10-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyjsonata-0.0.1a10-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 285.0 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ec6c0f391827a647663d6003ba3e5abc25f97f95f3a7fa29bdbf6830e705dfe |
|
MD5 | 70ef34cd4b996507155b9c6b14697f9e |
|
BLAKE2b-256 | 7aa96d37247ea0d542f2f7c3307b045feeeb3e224b650e39aed66c84fb965c7f |
File details
Details for the file pyjsonata-0.0.1a10-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyjsonata-0.0.1a10-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 285.0 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1803c3083afbbc4aab87b08922564353f5422e9fbd2d99302df792300d0052e |
|
MD5 | 40df4e454bc69fc0566bc9b696002c21 |
|
BLAKE2b-256 | e843612182789f49849942d9cf54c678baad4f997a624643161a0b44010dfd94 |
File details
Details for the file pyjsonata-0.0.1a10-cp35-cp35m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyjsonata-0.0.1a10-cp35-cp35m-manylinux2014_x86_64.whl
- Upload date:
- Size: 285.0 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcbfa888bd139aaef5c47e19725fa0342fa60ef13eab1fd7a8c3491f702eaef3 |
|
MD5 | ed36bb1ffb192f4ee7fe4de9789a4070 |
|
BLAKE2b-256 | 453c5a36cf825d3be28b8c56801602a68033cfdc94c915edf280a56899db2655 |