Ultra fast JSON encoder and decoder for Python with NumPy support
Project description
nujson: The UltraJSON Fork That Supports Numpy Serialization That Actually Includes Python Wheels
Inspired by Pandas' ujson
How to install
Python versions: Python 3.5+
Using pip:
pip install shaped-nujson
If you get an error like this:
ERROR: Could not find a version that satisfies the requirement numpy>=1.16.4 (from nujson) (from versions: 1.9.3)
ERROR: No matching distribution found for numpy>=1.16.4 (from nujson)
Try this:
pip uninstall numpy
pip install numpy==1.16.4
pip install shaped-nujson
Example
>>> import numpy as np
>>> import nujson as ujson
>>> a = {"a": np.int64(100)}
>>> ujson.dumps(a)
'{"a":100}'
>>> a["b"] = np.float64(10.9)
>>> ujson.dumps(a)
'{"a":100,"b":10.9}'
>>> a["c"] = np.str_("12")
>>> ujson.dumps(a)
'{"a":100,"b":10.9,"c":"12"}'
>>> a["d"] = np.array(list(range(10)))
>>> ujson.dumps(a)
'{"a":100,"b":10.9,"c":"12","d":[0,1,2,3,4,5,6,7,8,9]}'
>>> a["e"] = np.repeat(3.9, 4)
>>> ujson.dumps(a)
'{"a":100,"b":10.9,"c":"12","d":[0,1,2,3,4,5,6,7,8,9],"e":[3.9,3.9,3.9,3.9]}'
Why make such a package and what is modified?
On Python 3, some data types of NumPy are not serializable. Here are some references:
- python - Why are some numpy datatypes JSON serializable and others not? - Stack Overflow
- Maximum recursion level reached in Python 3 - Issue #221 - esnme/ultrajson
- Issue 24313: json fails to serialise numpy.int64 - Python tracker
One solution is type conversion like: int(numpy.int64) and numpy.array.tolist().
But it's not good for performance. After searching the Internet, we found an unmaintained project Komnomnomnom/ultrajson which recommends to use Pandas' ujson.
We tried but found Pandas is too heavy for our projects. So we decided to build our own lightweight fork. Currently, esn's ujson master branch has some problems we needed to solve, and the master branch is based on the the v1.35 ujson.
The main point is to convert NumPy data types in C, with calling NumPy's header. Commit 187bd15 has the most changes we made to support NumPy, and commit afedc42 fixes a build issue on macOS caused by Clang.
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 Distributions
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 shaped-nujson-1.35.2.tar.gz.
File metadata
- Download URL: shaped-nujson-1.35.2.tar.gz
- Upload date:
- Size: 186.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b0af07484ccdd5ac0045bb3d5c9e3a04d05171defa4d7e02f80b03e07031a6a
|
|
| MD5 |
306c712bc8a6776242a0ec370fd840b0
|
|
| BLAKE2b-256 |
aceb3304e6652c187fb4c27843b348d03ac01c72dfd12e93aa67db274f3c3933
|
File details
Details for the file shaped_nujson-1.35.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: shaped_nujson-1.35.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 79.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88e5bcd755fda68f75f569e554635167f16074ce6288390fe0b81a6b28f30d14
|
|
| MD5 |
6339b567911b63dd5935aa2468764217
|
|
| BLAKE2b-256 |
4bf27fe8adc18f2ac14053914246453e213bc3f6022a6bb0df16d9a81eac8460
|
File details
Details for the file shaped_nujson-1.35.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: shaped_nujson-1.35.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 80.2 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
666c75377df51879c7c27d9ff981a47fd6500bc44783340a88d1440dd1fb41da
|
|
| MD5 |
730640879bb8be71acc0b08aff8f3995
|
|
| BLAKE2b-256 |
dc6c66298196b0afa18fb48209fe20c3866168296bd31760496ef73ab1172755
|
File details
Details for the file shaped_nujson-1.35.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: shaped_nujson-1.35.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 77.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
107a1e2ec30ffd0671ef4f9f51bde3e572955996e57001c7650a8a425117f93b
|
|
| MD5 |
840470f7fdb1066b0f2a225b745814bf
|
|
| BLAKE2b-256 |
ba6127381396aee374a712d3a9f5fd81dd1ec94cb007966bae5559d2f071026c
|
File details
Details for the file shaped_nujson-1.35.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: shaped_nujson-1.35.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 76.9 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac01d603b51e24cb08654f32038f9bdc46ff420731927b6cef5806611379c448
|
|
| MD5 |
08eaa7eadcb368317879f2cbd72254e7
|
|
| BLAKE2b-256 |
334703c99c5b6814ae393a84d7bdbdc628a0a18b28f0005621b2f2d671177eaf
|