Skip to main content

Fastest JSON encode / decode library.

Project description

GitHub Workflow Status GitHub Workflow Status GitHub Workflow Status PyPI - Downloads

yapic.json is an extreamly fast json encoder / decoder package for python. Encoding and decoding output fully compatible with python.json package.

Features

  • Extreamly fast (see benchmark results in ‘/benchmark’ directory)

  • Fully compatible output with Python json package

  • Builtin object serialization method __json__ (see below)

  • Strict JSON (RFC 4627) expected: Infinity, NaN (JavaScript compatible infinity and not a number symbols)

  • UTF-8 encoding & decoding support

  • Accurate float encoding & decoding

  • date / datetime / time encondig & decoding support (can encode subclasses)

  • uuid.UUID encoding support

  • ItemsView encoding support

    from collections.abc import ItemsView
    
    class MyDictGenerator(ItemsView):
       def __iter__(self):
          yield ("some_key", "some_value")
          yield ("meaning_of_life", 42)
    
    json.dumps(MyDictGenerator()) == '{"some_key":"some_value","meaning_of_life":42}'

Requirements

  • Only works with Python 3.5 or greater

  • c++ 11 comaptible compiler. (only if u want to build from source)

    Wheels provided for windows x86/x64 and linux x86/x64 and osx x64

  • On Windows you maybe need to install Microsoft Visual C++ Redistributable

Windows

Usage

Very similar that python.json, let’s see some example

Json data to python

from yapic import json

>>> json.loads('"Hello World"')
"Hello World"

Python object to json data

from yapic import json

>>> json.dumps("Hello World")
'"Hello World"'

class Point:
   def __json__(self):
      return {"x":1, "y":2}

>>> json.dumps(Point())
'{"x":1,"y":2}'

Functions

  • loads (s: bytes, str, *, object_hook: Callable[[dict], Any]]=None, parse_float: Callable[[str], Any]]=None, parse_date: bool=True)

    object_hook example:

    >>> from yapic import json
    >>> def hook(dict_):
    ...     if "__complex__" in dict_:
    ...         return complex(dict_["real"], dict_["imag"])
    ...
    >>> json.loads('{"__complex__":true, "real":1, "imag":2}',
    >>>     object_hook=hook)
    (1+2j)

    parse_float example:

    >>> from yapic import json
    >>> from decimal import Decimal
    >>> json.loads("1.2", parse_float=Decimal)
    Decimal('1.2')
  • dumps (obj: Any, *, default: Callable[[Any], JSONT]=None, tojson: str="__json__", ensure_ascii: bool=True, encode_datetime: bool=True) -> str

    default example:

    >>> from yapic import json
    >>> def default_func(o):
    ...     if isinstance(o, complex):
    ...         return {"__complex__": True, "real": 1, "imag": 2}
    ...
    >>> json.dumps(1 + 2j, default=default_func)
    '{"__complex__":true,"real":1,"imag":2}'

    tojson example:

    >>> from yapic import json
    >>> class Point(object):
    ...     def __init__(self, x, y):
    ...         self.x = x
    ...         self.y = y
    ...     def __json__(self):
    ...         return {"x": self.x, "y": self.y}
    ...
    >>> json.dumps(Point(10, 20))
    '{"x":10,"y":20}'
  • dumpb (obj: Any, *, default: Callable[[Any], JSONT]=None, tojson: str="__json__", ensure_ascii: bool=True, encode_datetime: bool=True) -> bytes

    Same as dumps, but this function is return bytes insted of str

Exceptions

import json as py_json

class JsonError(ValueError):
   """Base exception for all json errors"""

class JsonEncodeError(JsonError):
   """Exception for encoding errors"""

class JsonDecodeError(JsonError, py_json.JSONDecodeError):
   """Exception for decoding errors

   Can match python builtin ``json.JSONDecodeError``.
   """

# alias for easier switch from std json lib
JSONDecodeError = JsonDecodeError

Json to Python translations

Json

Python

“string”

str

42

int

4.2, 4e2

float (unless you specify parse_float)

Infinity

float(“inf”)

NaN

float(“NaN”)

true

True

false

False

null

None

2000-01-01 12:34:56

datetime without timezone

2000-01-01 12:34:56Z

datetime with utc timezone

2000-01-01 12:34:56+0300

datetime with custom timezone

2000-01-01

date

10:12:34

time without timezone

10:12:34+0300

time with custom timezone

{…}

dict (unless you specify object_hook)

[…]

list

Python to Json translations

Python

Json

str

“…”

int(42)

42

float(4.2), Decimal(4.2)

4.2

float(“inf”), Decimal(“inf”)

Infinity

float(“nan”), Decimal(“nan”)

NaN

True

true

False

false

None

null

datetime

“2000-01-01 12:34:56”, “2000-01-01T12:34:56+0300”

date

“2000-01-01”

time

“12:34:56”, “12:34:56+0300”

UUID

“aba04c17-6ea3-48c1-8dcd-74f0a9b79bee”

Enum

encoding Enum.value attribute

dict, ItemsView, dataclass

{…}

list, tuple, set, iterable

[…]

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

yapic.json-1.9.5.tar.gz (105.4 kB view details)

Uploaded Source

Built Distributions

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

yapic.json-1.9.5-cp312-cp312-win_amd64.whl (84.5 kB view details)

Uploaded CPython 3.12Windows x86-64

yapic.json-1.9.5-cp312-cp312-win32.whl (77.8 kB view details)

Uploaded CPython 3.12Windows x86

yapic.json-1.9.5-cp311-cp311-win_amd64.whl (83.9 kB view details)

Uploaded CPython 3.11Windows x86-64

yapic.json-1.9.5-cp311-cp311-win32.whl (77.3 kB view details)

Uploaded CPython 3.11Windows x86

yapic.json-1.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (610.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

yapic.json-1.9.5-cp310-cp310-win_amd64.whl (83.9 kB view details)

Uploaded CPython 3.10Windows x86-64

yapic.json-1.9.5-cp310-cp310-win32.whl (77.2 kB view details)

Uploaded CPython 3.10Windows x86

yapic.json-1.9.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (575.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

yapic.json-1.9.5-cp39-cp39-win_amd64.whl (84.0 kB view details)

Uploaded CPython 3.9Windows x86-64

yapic.json-1.9.5-cp39-cp39-win32.whl (77.2 kB view details)

Uploaded CPython 3.9Windows x86

yapic.json-1.9.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (573.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

yapic.json-1.9.5-cp38-cp38-win_amd64.whl (84.1 kB view details)

Uploaded CPython 3.8Windows x86-64

yapic.json-1.9.5-cp38-cp38-win32.whl (77.2 kB view details)

Uploaded CPython 3.8Windows x86

yapic.json-1.9.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (579.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

yapic.json-1.9.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (541.3 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

File details

Details for the file yapic.json-1.9.5.tar.gz.

File metadata

  • Download URL: yapic.json-1.9.5.tar.gz
  • Upload date:
  • Size: 105.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.11.10

File hashes

Hashes for yapic.json-1.9.5.tar.gz
Algorithm Hash digest
SHA256 d4c7a533b0670709fca9623f243e6bc5b6c0f67adbb4de508af2381c271e98b4
MD5 c680c025d990d672e73d1a7826cbfb54
BLAKE2b-256 3d355d52934c020bfbffaff2c09b311f65103655a25dd4182cd23984187b9872

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 84.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.12.6

File hashes

Hashes for yapic.json-1.9.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3db5a5828efd0d207a74f71bd41ab7db995fe26920bff1e413b756b367691db2
MD5 aa27e60386149da775bd83a1c8d825eb
BLAKE2b-256 cb6e664b9557cf99e34783da9f2cb384817379cea2b8d5f02f73fe119023c4dd

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp312-cp312-win32.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp312-cp312-win32.whl
  • Upload date:
  • Size: 77.8 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.12.6

File hashes

Hashes for yapic.json-1.9.5-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 63036af738ccd4d3cf5a3446a2867ad62e78f66af21dcd73b77992a19ee43e15
MD5 77db3a0f7bb0c1af550105a7b101ef92
BLAKE2b-256 263deedd25e7497d7e761907705b99f8fb452e27a24f54be9d4d4cd505eec1b6

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 83.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.11.9

File hashes

Hashes for yapic.json-1.9.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f8d37c115b31bdef135918a2f24e3bdbee128f16838ce44def5114dd48da2de1
MD5 e9b89f56572ba48fb107ba88d506d50f
BLAKE2b-256 e9d44c7341485efead5d29d8230789fb44af3c6a27b57c54661aaf3e0bc389e6

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp311-cp311-win32.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp311-cp311-win32.whl
  • Upload date:
  • Size: 77.3 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.11.9

File hashes

Hashes for yapic.json-1.9.5-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 570a65975f312cf7118526e36349d914a3b736b79e6e005dae99e6dd1eb00fea
MD5 c524d9a460685769aa19f559a44db19d
BLAKE2b-256 90c8f409a334fea320b3505812ed190559e0b62ef53cbabe19428615ad974634

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yapic.json-1.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cea756a8c786309690f95a76d49549094fc8c40ba8ea14b53cc484ffdbec885
MD5 c7e6201284593d7d0c46902df5ac5831
BLAKE2b-256 6eedebc25d60204cff64ed2182ae819a92df06afd8b9a1ce067d9026d52e759e

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 83.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.10.11

File hashes

Hashes for yapic.json-1.9.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5b5a42986def9908fab9da85ce35429f76a0f92b0c13e42660b5de921e0cb2b6
MD5 dbcbdb39c18bffc768a02eab7a576069
BLAKE2b-256 89e34290f611ce9216af7252a07c7e08ea8831e83cab8d85925c9852f2b30f3f

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp310-cp310-win32.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp310-cp310-win32.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.10.11

File hashes

Hashes for yapic.json-1.9.5-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 9b69e9d7a84aac758883c47e4eff379b64283be34da9804a3ce19373d0bf7361
MD5 96319e2c1f6b3489b4fc8bca09c2570d
BLAKE2b-256 11cef1630faee68721ce2d0d7a4864ba0b9454dc66ff5d56bfb623e40a47663d

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yapic.json-1.9.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e2955502171738e9bfd367dfe4680f8a21eeec5b5cef84b4bafb6b487fa05bb
MD5 f058cde4ee2541ccbe6331a6bc6ee418
BLAKE2b-256 9b97cf6fed72febc22404ce36713653ec38715e1f73cfc63a58496bddd536482

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 84.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for yapic.json-1.9.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 be226bc8b20af020b2453c017ac753d5ae48cb5989386f0dc8910a861750f3f4
MD5 e4e5181b8486e3ada407907fdfb37b5a
BLAKE2b-256 02ac4b01db28bb6eb315c523c0210b32e723d4a3cecdae6ff155fa01777a2166

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp39-cp39-win32.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp39-cp39-win32.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for yapic.json-1.9.5-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 5abaa56b65cdb5d72fa6878339296edfb7702bb3893031662753fec52cb7fa12
MD5 00e295a2ed64448f814f8b7a6824c251
BLAKE2b-256 c62aeccd59bf1411db491dcd33f9addacec2989193ab39142bb8464eace575bb

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yapic.json-1.9.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7c3cc99d44e57d1e214c9c2e0be70c98123e602efb7b2be0161268c456cfc4d5
MD5 775c947c34b7e214422fee4a6516e7ae
BLAKE2b-256 db4d37f0a6036e755a5f76eb2a3d1130384d3f00dcee3b9a0cbdc7aeabc87451

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 84.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.8.10

File hashes

Hashes for yapic.json-1.9.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fefe71a6d64fbcd69ea12bfe820c91d7fa8148369970ff61fa7ac29456df92c4
MD5 0de2ab2b52006d7cfd87c55df553bd0f
BLAKE2b-256 7cc1f4c4dff34dc6a6b39519d643dd8b147e2f93c49fb5c41068e3e25b5922c6

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp38-cp38-win32.whl.

File metadata

  • Download URL: yapic.json-1.9.5-cp38-cp38-win32.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.8.10

File hashes

Hashes for yapic.json-1.9.5-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 71e6eac1d1bead9ce1107312d567d0ba74802fe34e2db2dba50d24b9286551f5
MD5 69788281b127d2becdc8ed1a6a1d0ed6
BLAKE2b-256 28c8fb65c09a6f9724b2b6c70fb73519743b74754cfdaa702830b7cb51418567

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yapic.json-1.9.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9d2ac05d561e13bb6364aa08b5afbddd4531968e434595ae99d1ec9fca23bf8
MD5 6e9d5860ad8775f6eed2eeb8df5334b1
BLAKE2b-256 78543b6baf1059ec582691dd7be210119e1acd3ac78b5805d6e3729e7ecbcd11

See more details on using hashes here.

File details

Details for the file yapic.json-1.9.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yapic.json-1.9.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a6895cc0a8942202da85b64b3fbecfcdf1519676f92c539d89418df25e5845b
MD5 98252085ab91f25dd455165267f7de4f
BLAKE2b-256 4c513ce5602196422eb171004946762f1f019168e0f1e2297c6ce11f6347bb2f

See more details on using hashes here.

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