Skip to main content

nujson: The UltraJSON Fork That Support Numpy Serialization

Inspired by Pandas' ujson

Build Status Version Status

How to install

Python version: Python2.7, Python3.5+

Using pip:

pip install nujson

Clone and install:

# git clone
git clone https://github.com/caiyunapp/ultrajson

# Don't use `python setup.py install`
# NumPy will install automatically
pip install -e .

If get 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 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 Python3, some data types of NumPy is not serializable. Here is some references we searched:

One solution is type conversion like: int(numpy.int64) and numpy.array.tolist(). But it's not good for performance. After searching Internet, find a no longer maintained project Komnomnomnom/ultrajson recommond to use Pandas' ujson.

We tried but found Pandas is to heavy for our projects. So we decide to build our own light weight fork. Currentltly, the esn's ujson master branch has some problems we need to solve, and the master branch is based on the the v1.35 ujson.

The main point is convert NumPy data type in C, with calling NumPy's header. Commit 187bd15 has the most changes we made to support NumPy, and Commit afedc42 fix a build issue on macOS caused by Clang.

Metadata

Release files for nujson 1.35.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nujson 1.35.2
File Size Uploaded Provenance
nujson-1.35.2.tar.gz 187.2 kB Without provenance Details

Release files / nujson-1.35.2.tar.gz

Download URL nujson-1.35.2.tar.gz
Size 187.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2b231051b6e983d38e9fc4801841a60cd91e6266505f616d32046e54e92e7032
BLAKE2b-256 checksum
How to use checksums
4176440ee0166cdb6674fe744f96498cdce6bac7cae0a543b84f19dfa1704fc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

Security for nujson 1.35.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.35.2 This release

1 release file No provenance

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