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.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f270215211c7f00c4e5b99553e8f2d7fb9e39e719f5eba3e90a68e7a1557ff2 |
|
MD5 | 1ade7fc0b29ffaa4dd1e2da0ed211718 |
|
BLAKE2b-256 | c43b53d4b2ae79b096ae9a49a5f962af83636e096c52af502809157115ca4001 |
Hashes for yapic.json-1.6.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1fa804bc38c8356be90593268c6ac1422fd2007203269db6f7243e8d8a62f13 |
|
MD5 | 5a0c5d3c09c7157db1c2927ab53f1f60 |
|
BLAKE2b-256 | 21321681c87188dde06ed218e7247b79667b2275cfcc8f4e1771064aedfdf608 |
Hashes for yapic.json-1.6.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62dff556c9db3f519b2c508bba84741e40e91b43bff65282e75524fb3c88b2df |
|
MD5 | 9b53b00fd975ad97a634bce15a3057b2 |
|
BLAKE2b-256 | bbc5d2097b3f4f99d7f1677c236bcccf0063dc33fcfe0803bc0d038455e8f6d3 |
Hashes for yapic.json-1.6.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42356181d04ccd650a497c6d26419ad9bd46d63bef4115739d0fb4fd80e7342f |
|
MD5 | 917cd1540a16b2a813184529ee236f31 |
|
BLAKE2b-256 | 283d399e448272f10323097801e652b91b0fd20dbbca887295736688d6936ba0 |
Hashes for yapic.json-1.6.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5b77fba235fede5cbf640a392e42680b96444ab257cc946102f00aed3c1a20c |
|
MD5 | d115d0a47adb0a3a5377d17dab7512b0 |
|
BLAKE2b-256 | f4ed5466e048f8d8f2da6ce9e36fc9f105bb5d8293cc24270066462a2bf64e1a |
Hashes for yapic.json-1.6.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57ef99fdf555b4e38c7b2cb9fa37cd382759dd851620e80fbe26eabb8f819a4c |
|
MD5 | 0eae51edda90a019d41df6425250d3ae |
|
BLAKE2b-256 | 49e1358f37fb9a254fb2bd4288b0a9d90a5189a7b42f3b6750243a9326f5e2cc |
Hashes for yapic.json-1.6.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f97865085353f80f5f4060e9f34959ce7a2adcc8f4c44cc89b4bf2a93a27971a |
|
MD5 | f706cc6e03fff87affeed72bc650ddb9 |
|
BLAKE2b-256 | 2cd5d74e88faed6acbc813b91b7bcb4baba6f5b5df3894f194b92f07f9ffca3e |
Hashes for yapic.json-1.6.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b468463c7d1c04bd8c3f8f77d79fc5e7d8b907a887d9e34b71c4165ea91c36be |
|
MD5 | f060148e4f97f9bd8482a5c4c51847f1 |
|
BLAKE2b-256 | 3f2fd38b5acbdcc5f6d24fcce023fa302f26f83f938152a6ec25f04684889c6f |
Hashes for yapic.json-1.6.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d26ab6ea5d346c7ead954c5faf666f4cd3d7180889f4fc8667e54c75b64639f |
|
MD5 | ad5d834c2d4b9efe93545270d6926706 |
|
BLAKE2b-256 | e21ab33098fe38dd656fcd798d3138e4aadb8de4c18baacc0f1c17af4465698c |
Hashes for yapic.json-1.6.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f39e287a5cf0a91dca34b50d7f4c10e39ae3e3458157d1e0739c362de255a74a |
|
MD5 | 60955555a95f5861736f565d9aa53399 |
|
BLAKE2b-256 | 2b1826275c338846b26e65f99978b1ac340da0c86e65df54dd0f0935ca5f9345 |
Hashes for yapic.json-1.6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6503c13767e7c89f718eecbf6356f280f05b268458086305713255d4eeef917f |
|
MD5 | 9d11b47ed1c5b540ba8d0b905dd49837 |
|
BLAKE2b-256 | 3bf19bea0338301795f56ed04ee4083ad8995ff7d71ecef6dd4511bc3d78253e |
Hashes for yapic.json-1.6.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c52b2aa12e412f00a444b3b93f564ad9a3a2075a8fdd010fb45aa72be03f6c6 |
|
MD5 | 361e1f81d78ae4ea0f9785e90143978a |
|
BLAKE2b-256 | bf13643ab4c7844c97bb7a8373f20073e6ef0a63e209cc3813f2d9e7de194a9f |
Hashes for yapic.json-1.6.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ed2844d0d90c856c231b34465380e06598e2d344841d8b91cbd475a26e0fc4 |
|
MD5 | c53d125b08d0ab1a77aaea8425621cbe |
|
BLAKE2b-256 | de72b2348b48e1507c45975e54b15e5ce345caa7c74fc6172c9a6a4e5bef9ebb |
Hashes for yapic.json-1.6.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c34beb43e29c66f93eb988f395608522ece35b86fd4b29d41de8d92befd920ae |
|
MD5 | ad4100758c9caf151cb22e93da1027a6 |
|
BLAKE2b-256 | ebde040e449dde5eaf7b8c186d6282a0df13225845f257d7cbab01251ebc6248 |
Hashes for yapic.json-1.6.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 490eae1f8735b3bf18f2919918696f5e301904f991cb94321fd85a1a047339a1 |
|
MD5 | 495681424bcc60fabb350bc2ce5aa280 |
|
BLAKE2b-256 | 27f9986091fe5b89735e0f2c6b5c7723b54e79d4e145be9f778297ce4f15b336 |
Hashes for yapic.json-1.6.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c13f23e55cb0f1c8b7e95a32d70cdb35a4ddd0a4907e9e5ac3296be92d89d2 |
|
MD5 | 2739fa318911470347cb7a0756f36d84 |
|
BLAKE2b-256 | 1ec5b88506eec6632a5575b4e2d94a6efc3a3e07f4cca46a163779ce70f9ed63 |
Hashes for yapic.json-1.6.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 449c083446c89eda27fa912aad11a7443e12dda36d02dc2e9a90010bae47b67a |
|
MD5 | d7b858b03aa57ac06c39f5215f30fc09 |
|
BLAKE2b-256 | a44ff8a18045a50778770fb79482068fc0c9c8b0e45e6099a5b71df9ab043261 |
Hashes for yapic.json-1.6.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b859fa090e9d552f359c25b793445061f268b4889bf5cdea0fa7e16548c07e7 |
|
MD5 | 7b422e51934fec95324e57713f51c003 |
|
BLAKE2b-256 | 8b5df39fcdb3ca93d2c4a9c1769978665575da92f25935957e5a7d0a98f022ce |
Hashes for yapic.json-1.6.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b125d234df6c9fb4931a0c5d729b520598d21f65ed94954393f608472dbe111b |
|
MD5 | 25f5c0a12fee61ff622c78d2849f4729 |
|
BLAKE2b-256 | 344f4735d459cf1996325ea7e46aa3ee1ea5fdf43f8b7efbfe506e05e09be132 |
Hashes for yapic.json-1.6.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb0ebc3f9de38791aeb86ddd142852c219c8436e9adcbd6137685bd715c57421 |
|
MD5 | 0b936f2f2b8a1ef3cf2e73fa962c8df0 |
|
BLAKE2b-256 | 2e5c8e5bccd8238de25ae1a543aa5688ce88b643638511cdfd9609599d64085b |
Hashes for yapic.json-1.6.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24deb2041586d971fda910d4f4d42a5201675ba91b85e8902c11475ae97f550f |
|
MD5 | 96640d65835ae78b47e3028edd427fde |
|
BLAKE2b-256 | 6e797c1fada7ad124150769a4b0debb4ae6677c7fe82b07fb7fbb129c4fb1b4c |