Skip to main content

simdjson bindings for python

Project description

PyPI - License Tests

pysimdjson

Python bindings for the simdjson project, a SIMD-accelerated JSON parser.

Bindings are currently tested on OS X, Linux, and Windows for Python 3.4+.

Installation

If binary wheels are available for your platform, you can install from pip with no further requirements:

pip install pysimdjson

The project is self-contained, and has no additional dependencies. If binary wheels are not available for your platform, or you want to build from source for the best performance, you'll need a C++11-capable compiler to compile the sources:

pip install 'pysimdjson[dev]' --no-binary :all:

Development and Testing

This project comes with a full test suite. To install development and testing dependencies, use:

pip install -e ".[dev]"

To also install 3rd party JSON libraries used for running benchmarks, use:

pip install -e ".[benchmark]"

To run the tests, just type pytest. To also run the benchmarks, use pytest --runslow.

To properly test on Windows, you need both a recent version of Visual Studio (VS) as well as VS2015, patch 3. Older versions of CPython required portable C/C++ extensions to be built with the same version of VS as the interpreter. Use the Developer Command Prompt to easily switch between versions.

How It Works

This project uses pybind11 to generate the low-level bindings on top of the simdjson project. You can use it just like the built-in json module, or use the simdjson-specific API for much better performance.

import simdjson
doc = simdjson.loads('{"hello": "world"}')

Making things faster

pysimdjson provides an api compatible with the built-in json module for convenience, and this API is pretty fast (beating or tying all other Python JSON libraries). However, it also provides a simdjson-specific API that can perform significantly better.

Don't load the entire document

95% of the time spent loading a JSON document into Python is spent in the creation of Python objects, not the actual parsing of the document. You can avoid all of this overhead by ignoring parts of the document you don't want.

pysimdjson supports this in two ways - the use of JSON pointers via at(), or proxies for objects and lists.

import simdjson
parser = simdjson.Parser()
doc = parser.parse(b'{"res": [{"name": "first"}, {"name": "second"}]')

For our sample above, we really just want the second entry in res, we don't care about anything else. We can do this two ways:

assert doc['res'][1]['name'] == 'second' # True
assert doc.at('res/1/name') == 'second' # True

Both of these approaches will be much faster than using load/s(), since they avoid loading the parts of the document we didn't care about.

Re-use the parser.

One of the easiest performance gains if you're working on many documents is to re-use the parser.

import simdjson
parser = simdjson.Parser()

for i in range(0, 100):
    doc = parser.parse(b'{"a": "b"})

This will drastically reduce the number of allocations being made, as it will reuse the existing buffer when possible. If it's too small, it'll grow to fit.

Performance Considerations

The actual parsing of a document is a small fraction (~5%) of the total time spent bringing a JSON document into CPython. However, even in the case of bringing the entire document into Python, pysimdjson will almost always be faster or equivelent to other high-speed Python libraries.

There are two things to keep in mind when trying to get the best performance:

  1. Do you really need the entire document? If you have a JSON document with thousands of keys but just need to check if the "published" key is True, use the JSON pointer interface to pull only a single field into Python.
  2. There is significant overhead in calling a C++ function from Python. Minimizing the number of function calls can offer significant speedups in some use cases.

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

pysimdjson-2.0.11.tar.gz (203.7 kB view details)

Uploaded Source

Built Distributions

pysimdjson-2.0.11-pp36-pypy36_pp73-macosx_10_9_x86_64.whl (173.1 kB view details)

Uploaded PyPy macOS 10.9+ x86-64

pysimdjson-2.0.11-cp38-cp38-win_amd64.whl (140.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

pysimdjson-2.0.11-cp38-cp38-macosx_10_14_x86_64.whl (194.1 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pysimdjson-2.0.11-cp37-cp37m-win_amd64.whl (140.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

pysimdjson-2.0.11-cp37-cp37m-manylinux2010_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pysimdjson-2.0.11-cp37-cp37m-macosx_10_14_x86_64.whl (190.0 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pysimdjson-2.0.11-cp36-cp36m-manylinux2010_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pysimdjson-2.0.11-cp36-cp36m-macosx_10_14_x86_64.whl (190.0 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

pysimdjson-2.0.11-cp35-cp35m-manylinux2010_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

pysimdjson-2.0.11-cp35-cp35m-macosx_10_14_x86_64.whl (190.0 kB view details)

Uploaded CPython 3.5m macOS 10.14+ x86-64

File details

Details for the file pysimdjson-2.0.11.tar.gz.

File metadata

  • Download URL: pysimdjson-2.0.11.tar.gz
  • Upload date:
  • Size: 203.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11.tar.gz
Algorithm Hash digest
SHA256 20b6c2701749e5e12f766cba59387e558470c8f6f91548ed0c45649eacdb0e83
MD5 2086e27f351e7f78975059f48ad1d016
BLAKE2b-256 9be17ec92d2ae38c27fe62764b87e6ddc7bf4239786e42db864dfa228ac73009

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-pp36-pypy36_pp73-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 173.1 kB
  • Tags: PyPy, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 PyPy/7.3.1

File hashes

Hashes for pysimdjson-2.0.11-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b7342ca5acef84e5a7153360b377ce7e0299e2d282d81312baa9f95c117d8d31
MD5 b95af02cb5e4f56a007b77381a249b0d
BLAKE2b-256 95d7942e62e9f2fd1a88dba6dff426bc484b821bb167ac0fb3e0159a9eb514d2

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 140.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9d41a9fd69a10ee43ea02be6897230f8b49a79700a871e9636402b43c64235d7
MD5 fd8ad9256be11bcc8fc89788e509cbe7
BLAKE2b-256 2a6c2a9edc13a67945fdb95d243819c5eae88e80be55e3e3e41945a4576b1ac3

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 194.1 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d89fd223cbe5e1098e73c6437f664e95355a243986a86c32daa171fdb68af2e3
MD5 9d5a56cc7a2639ad56c97e3d1d38cd07
BLAKE2b-256 6baeff9efc45e049df42e258b5cd549a94cb3607386ee379a0fa239de626e460

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 140.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for pysimdjson-2.0.11-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 77a1663fd9555f3d7e6c2587c076f23b26fb79d2a56afbd7011156b5544cec42
MD5 9fb0310191a57acdd8a5239a5a9701f5
BLAKE2b-256 1324420cd5319cb8c141a2f42672ddcb1cfe3863b2601b3d072dccb528700d0d

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c63ce9b69a525b714c5d1eb7e3e658d0e8cb88f6bedd836926e7ebd86fc9da38
MD5 eaa352d8b01d353e4b65646c3ddb9a27
BLAKE2b-256 c7a375c4ccdfe64629ae5c8ac72115cef042ea284d5e5a0d6efdf9a6d363e87f

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 190.0 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for pysimdjson-2.0.11-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5993538d449458d7dd6f836a57ad0b577f81cf742d41c8a97314fe85d7632b48
MD5 c73d1456c7d32968b0247699170aa06b
BLAKE2b-256 6cc25794c013496541dc8764870452698f42188dc08261f9bd8e68575992f639

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6c5f1fa3a977780aa72f1ac295937f6b3fa88ad37ea9c3627bad1cdb8d23125f
MD5 8181e42dabc970f7c882e381fff27590
BLAKE2b-256 c62848789f012292973d38ba45a1624dbb69d3b6a74d0a0c8702545e815e0e06

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 190.0 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.11

File hashes

Hashes for pysimdjson-2.0.11-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0b1f26dad83113d546eff4994f5deef642a75e9914b9ccbb2a9fdef98ece8cd9
MD5 a635ba901cb5c5ae1e8f9624d3441ebf
BLAKE2b-256 92f2470a02c165e5786ce7932bfbddbf0ced823e16f704b9f61647546daa8d7b

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pysimdjson-2.0.11-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f3b52d1a9c2837df5fd0188d2c8f5b94d2fd79380922403ed7fa8197d23dcb77
MD5 5431d416a556a29b8d819f1c5884a3a1
BLAKE2b-256 dbdeddedb25d695f1faaa192a460297a7533eccd3e7de6b6aacc672563574f08

See more details on using hashes here.

File details

Details for the file pysimdjson-2.0.11-cp35-cp35m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pysimdjson-2.0.11-cp35-cp35m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 190.0 kB
  • Tags: CPython 3.5m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.5.9

File hashes

Hashes for pysimdjson-2.0.11-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1ec98933e7db1fdee6b16afd7a278be6cdf5134629dd53d9aa1306596a18cef9
MD5 c54d6e84450cd1746b90c38651496047
BLAKE2b-256 25221f2d7d95573aca82db946949a3f3bce010c21fc6ad348414a13a35b9f0bf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page