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
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
yapic.json.JsonError: base exception class
yapic.json.JsonEncodeError: exception class for encoding errors
yapic.json.JsonDecodeError: exception class for decoding errors
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” |
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.6.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de634c592dc557c3fcb23414f7905f29426780837f0131d07880ac4add13b95b |
|
MD5 | e70a7f1447c0e14e2b797d13a876634a |
|
BLAKE2b-256 | 5f1b13154d6c13dc31bf0d4eba6f1c886e94f9665b88010a0d171c248b5aadb6 |
Hashes for yapic.json-1.6.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eea1694fd64750d8f670c986d98c6d340fbc482ff6f9f86ced0102c7ae0a390 |
|
MD5 | bb9787f9cb429fb0355d0dfb43085f65 |
|
BLAKE2b-256 | 25f798c92b5821dd35446243fd693050750a13634523fd99f8ea9ece7fecce04 |
Hashes for yapic.json-1.6.3-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5d278079bbfca229297b435ba93c0a3703becfe6949a08d80f5a1cd1741cfb |
|
MD5 | 8bf89123895ad89c87b869776b994068 |
|
BLAKE2b-256 | 5370c09dec65d336d5daff97bb8400d306ea6956515425c1bc7183e27fb9469d |
Hashes for yapic.json-1.6.3-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a769f16fea39b18fba788834d3332f35a23e044fe805d07435306e9449a6dfca |
|
MD5 | c76e8387f6d12c3036bfb89f54f6a5ea |
|
BLAKE2b-256 | 5601f52e894d7f062169786fa74cdaa20c65fbe9be59521417a4cb9104ce5bc5 |
Hashes for yapic.json-1.6.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f467f75ab6da41d9746560261e96aaf49d9f0b3ffac92143baf9afe268fa9e9 |
|
MD5 | c48347f4cdd1f3fc8d6ca42ee6526907 |
|
BLAKE2b-256 | ae02c1301ae7191c66b93e03e239a615ee9e2dfaaf83aab73668ac06e8ec186a |
Hashes for yapic.json-1.6.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde37e9e45f371678293fb5274c586e2fdc43d8ac257e8034f3d524d1470d6bb |
|
MD5 | d576490089b62ba66d46ad679ebb355d |
|
BLAKE2b-256 | 9320780aef001ed376bce08da20c13532bf665db5eeb8a7e5bcb6d53cc82a0e2 |
Hashes for yapic.json-1.6.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62c5a5c25bce34eb206cba4be00af7b6ccf540900d82ee541b3e579fe770ad86 |
|
MD5 | 2a732fcdc7bc21dc715da2d3a282e42b |
|
BLAKE2b-256 | 106bb4b4459f607f43506b6b2f8d5045f7fb6f0e00387fbfe6d10a35cd2a438f |
Hashes for yapic.json-1.6.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3063258e56b416719cce864d11eafb82039edda89d3c9af338013c2021bba99a |
|
MD5 | 725be439c6c4ab3618564a7e7519d518 |
|
BLAKE2b-256 | cc1e5ee86e8ff8a1ddd5dd1d058147426401ef0e5830cfe04f1ff8ee7e0537ce |
Hashes for yapic.json-1.6.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 661394243a52372844080fa8227d7469980980fb9aa136096322c60be160386b |
|
MD5 | e5b5dd1fb5b688e2757c1258ae6bd5a4 |
|
BLAKE2b-256 | a31f7f72d95991b740ce0420eb184909e01e05cdbe9eec8c7ff415722140d12a |
Hashes for yapic.json-1.6.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4151ae45ed45478f5675b11c9a99cc4166e01eb08451930db34f642679c95d65 |
|
MD5 | 4c1954b560754df729cdd3fbc1a473f6 |
|
BLAKE2b-256 | 9ce55f4181366ec764607a048a08a347a6bf6c7eb9462428d8882d26fa995a83 |
Hashes for yapic.json-1.6.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faa6082cfd4e3d450b28729745a2de71ec0d06bcca4d21f1ed6ec801eb5a27fd |
|
MD5 | 7fa1fd16eb166078c0a8e7ec18301f38 |
|
BLAKE2b-256 | c16b408124b871f9c47d1dd89e8255cf04351c8039f72a260cb02959b8280378 |
Hashes for yapic.json-1.6.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58047932e98fbe6f09ccd5e6d6cc6b5931705fa68beaafc5a00a51c2f3884f0c |
|
MD5 | 5c58bb53b6eee8a61444da0cfc8ec21b |
|
BLAKE2b-256 | b79cd308a86f42ed0493875f04f4c6b90b062f42bbd5468d99fb749c98eb68b1 |
Hashes for yapic.json-1.6.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 641f3d63d1d7d431dc6e4dcddc8f59edb904e251af5d22abc55034d9e4386b1c |
|
MD5 | 6c6845123be64540c7aaeabd833f26f0 |
|
BLAKE2b-256 | c5204bca7172947de533cca650ef295bbe7af13e703fa88867d96cc02ffab2ce |
Hashes for yapic.json-1.6.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb71f6d9d7842cab99f250025e2ef1497c655cfa9ccab82380e8891d293b7df0 |
|
MD5 | 3c55adb264ad86b0e07484acdbdbfa63 |
|
BLAKE2b-256 | 664214f94fb29384c01f5e8b733954b41ff9539999112b048ecfef936507635f |
Hashes for yapic.json-1.6.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0fee5e0c286dc4b32a802f65fa56ad62c19d98a4e656b74089fa72a139a9824 |
|
MD5 | 2375e02a7a8ec0bf42c5184e49459b76 |
|
BLAKE2b-256 | f21f6cc907c96a8c5586a182e63e6c086a3f9e99a41321e02e773d07326035e8 |
Hashes for yapic.json-1.6.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2bdde42965b56a34cb066807dffbfee123efe03e82912195521be8d54b5be7e |
|
MD5 | 0bbcaa20da99d2b72df880f9ea3a2409 |
|
BLAKE2b-256 | 17849ad663addf6a0a354a6934f64bd5cfbc36d6a76fc68629cfb7820a590dd4 |
Hashes for yapic.json-1.6.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc314895195ccc9e7094037cf11aa1999bb82cf8a248f01b30a4ad9cc75c4771 |
|
MD5 | 0c893459b285d4e52e52dc93feb3ff94 |
|
BLAKE2b-256 | 98b2735ae48065bbe6289f9eeaba352e736300ecd7cb3a1eda5455c07f03ac79 |
Hashes for yapic.json-1.6.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f07e07845e656affcc089b6a1235057b65fc424e285d5a6776173c0c87851c8 |
|
MD5 | b74c1b17df4d12fbe363d3afbd22587e |
|
BLAKE2b-256 | 6f95930a6de34aec12625ae973c3c163b62af9892f27e8b4a608d6ad21e0d430 |
Hashes for yapic.json-1.6.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8a7441086969d6720238e347f9c4503a9166b08105103a3a4ea01fad5eb21ad |
|
MD5 | 3648036433b6bcb66145f8d37d73198e |
|
BLAKE2b-256 | ab931b3e780ca5312a42c1b61be67ceae674b910e88bfd92eb505fa6ac8c7fbd |
Hashes for yapic.json-1.6.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca39d22f599360f6388175ad910b9fb8e9b2a8034cf5ee5d1d1049c6f31c2b6 |
|
MD5 | cdb53a52e0cd1375c2ed8e54867afc9f |
|
BLAKE2b-256 | 3ff95a27ca6cc6b415ff221a549ddb260e5450bd0fb90b549b0eeb923bcd16bb |
Hashes for yapic.json-1.6.3-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88f84a51288243673da7b7583c466abefdd1dc84a5ac849d69a88e142031bed2 |
|
MD5 | e475d3bf9636c089ebb80ccb7d26696d |
|
BLAKE2b-256 | 49be5f84013738a87362b9c9f691ad0160da22877ebc39a82f72148c401887ba |