Fastest JSON encode / decode library.
Project description
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 |
{…} |
list, tuple, set, iterable |
[…] |
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
Hashes for yapic.json-1.8.11-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6432931da0970ffe3730b6cdc1c4f93176aca23e1c22fe53b5cd02c82fb2d43c |
|
MD5 | 97adf30f30b22e59ed9714dcbc9a366f |
|
BLAKE2b-256 | 67cc767106a7b01724b96f50debc0b4b7d8fd1fd106c9f9b4b3d9cca71fdd3ea |
Hashes for yapic.json-1.8.11-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd097cbaee20fdfab4d3544ba47e7fc8fb2609327a4e82e48c536e3fb0690c1 |
|
MD5 | b4c29b149458d2d0f95545d9e0d95875 |
|
BLAKE2b-256 | 3f3e782e670a55d6ebd49c7f4a7cacdac93591b1df06cbbcc8113b0370601dc1 |
Hashes for yapic.json-1.8.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95194911a8dd209097604a09c72a596f2f8ee2d02aa95982cea351f616cf9d0f |
|
MD5 | 8a6f0924e792cc9ceee1c13185f7c43f |
|
BLAKE2b-256 | 8bcd6292dfd96cc45210e071d03082d7478ddeba4ae334670eed6acfe7fed8db |
Hashes for yapic.json-1.8.11-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3840e009c8b30ab55f3293eeb600eb38ff39dfe4ac30ee58ea92eab25e62d30f |
|
MD5 | ca187b2059828074ebfc468c6038fd6e |
|
BLAKE2b-256 | d18d34e659796e57f1f1eef963797a4340b6b3e51716e9c1cb38b15ccf348a67 |
Hashes for yapic.json-1.8.11-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ece06e9f6d356d1f140503b5a5ac1d9da4a4ce42a87ec2730ae5ac226bd3cfcd |
|
MD5 | a1c7ab85b8268cd197a244579e937afe |
|
BLAKE2b-256 | b83e504bdc0a8f4b1a8ed439a62d60cec8715dfb90ac8d382a45d10ad5282627 |
Hashes for yapic.json-1.8.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42a60b71b18b95d5875015b9bfc17f9fccd3e8a8eb369d7c5df0caba46ef3557 |
|
MD5 | 639f8add101ba9706ce803140b675fef |
|
BLAKE2b-256 | 8a08221aa320b79dd3a77b141a5df39bc259ef97100a35d18ad53f7bbe685e0f |
Hashes for yapic.json-1.8.11-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7445e737d89e6eaf368c8953d7ec4c02ebf265801c1faacc985a9c3ce35a29 |
|
MD5 | d7611acf72893c6b34a3fdfbef5d8483 |
|
BLAKE2b-256 | 03812dc08f0e99f008e139e4b7ea1b7674440db8e53f4a7c083946b92da9a6f2 |
Hashes for yapic.json-1.8.11-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7903525adeb376c1423aad2ac59bda4d63c2a2dc18c468cc356c891397de4333 |
|
MD5 | 3344f233de14a64d71ad2655e1921583 |
|
BLAKE2b-256 | fd67ada2ebf8dbd2e6555ab511a2441d300f6f570483c14cf6d6c4873dc30ac6 |
Hashes for yapic.json-1.8.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 151595e693e5e977558f3a7d9968f245af40c6e05500877f070c3e4a35a92f66 |
|
MD5 | fa461ac2a912b16964a3b4e5cadb468c |
|
BLAKE2b-256 | da64685e2f8c1d7950dcc2c7698b67cb258e18de43626884154b23bb5ae35800 |
Hashes for yapic.json-1.8.11-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f25149a8cb0be226a0a182f45c2d9c152671e534961aa01a085183731dc5b270 |
|
MD5 | c1f07cee01f98c98dd9641508cdeab5b |
|
BLAKE2b-256 | 4defbffd2c026dbfdc41b7eaffa588ae7588dbfc803890916f10e80fc4c0ab2b |
Hashes for yapic.json-1.8.11-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f5cb55838473eb9d0bade5059f24c6cfd322c6098ed449fbf4989a1a04e346 |
|
MD5 | 9d82cf48de7c87cca7657338e4443da6 |
|
BLAKE2b-256 | bd71287c095e2653ad5b8e6a8ff8c421a9949810d5e9dd407882f2e75fa3a936 |
Hashes for yapic.json-1.8.11-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba18e62a5862f7377d1abd0478949ff7cec7f222cf33c4e2672953a70adb426 |
|
MD5 | e58445daec9c4c9f1a2c5042a5199f25 |
|
BLAKE2b-256 | 2ac55616b38a6832938b08f201593e903723298f8cde95a191ab8a41f10833f7 |
Hashes for yapic.json-1.8.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21582dae0e2eea18bb4014d559d8136877eb372c3acd23367acab648370d7109 |
|
MD5 | 3e9063e116497315ab52df2f236b6b22 |
|
BLAKE2b-256 | 8183ae10f020e0bd7b249add4762af7186f882988ed26ddd22aa310c40914559 |
Hashes for yapic.json-1.8.11-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97024cfa810015c970bc5778af860afc29253cfcf72dce2a4d9b9fe421631920 |
|
MD5 | 5279dc1e68a049449b8dfcfc4c528836 |
|
BLAKE2b-256 | 7b776b2a6eea5b7fa83dd354c710068e63803c455db3b2b350de6e701ea94c95 |
Hashes for yapic.json-1.8.11-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7087c49711c3482c5a5a61f695b7c7a5dac3bc431f539c20a31514c66c817ef7 |
|
MD5 | 2db1cc2c5ae4ff07b8beb1c5074a17c9 |
|
BLAKE2b-256 | d5659c95a1df8ab8e9cb400b555295694c343d0ad91dfec90ee53802d0fc3eed |
Hashes for yapic.json-1.8.11-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b578e8169812961712f69732ab6fdca3f0c4dc8672879f7b924141e47f1c19a9 |
|
MD5 | 7586a80bc9ff9158604426803117de39 |
|
BLAKE2b-256 | 8d6bde6f30d38be09d3bdb5fe6554a81eaa279c5c8cc03e434a079f9a4ed6268 |
Hashes for yapic.json-1.8.11-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f784889c45a258367ee2731642c7b7ea809ae82d68eb26d3e55f77858b191e60 |
|
MD5 | 63a4d1015112050ad1e7e6e875d0567c |
|
BLAKE2b-256 | f72efbbd978c1f3a5930652e82b6907c1c9d90f227c7494a121f64ee8d859dd3 |
Hashes for yapic.json-1.8.11-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75e77b92fb88fdaa785f4adedf646a77f3d2bbe015cd56135784d9427468d7ea |
|
MD5 | ffd7ea570fb741c06d76ca2d428223ff |
|
BLAKE2b-256 | f929dd89365f348e8e7a4beb1305a320d2e3ec8194ed7c9048210f9efcf84b97 |