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.5.4-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b27e32d09fbf0770ac52ab4aed34f7530b5cea28419a2fdaa2fae4d8c0ccac63 |
|
MD5 | e9817775696f7cd921872e9ed24ec642 |
|
BLAKE2b-256 | 9121b871ecc52b3a9077e61b5f1edce13cb334aa092eab7d5d1686b9ebc2a21c |
Hashes for yapic.json-1.5.4-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b1272678e847a4c01e05328fea5243a749a619b4d6cff10595f567e30f16e1e |
|
MD5 | ca4c4dc1c02fa33569abcaee987266d2 |
|
BLAKE2b-256 | 538d6a6031515e6b07cf7f0c6945b6dbfb74a08e6a30051484bc491d5d8f3dd0 |
Hashes for yapic.json-1.5.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6233f98dffaf09d45cdb2984c9dbf814958ce4ac45ce0c47f01623ebd4822259 |
|
MD5 | ea02d45c359591a530c3e09f3ee9eaee |
|
BLAKE2b-256 | 896da696ee002d30873a512f6ed1d5e0255761cd4407bb23dd645e16f9bc95af |
Hashes for yapic.json-1.5.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39414491a76df2a46eb9a8c5ccd62415d59a9f2312969fcac001647162d01277 |
|
MD5 | d543bc7b20f79b5b409154ac7c93b1b4 |
|
BLAKE2b-256 | ecbd1c3144e5aeae91147b42233048b64e4b061810564b38958a334ca1600afc |
Hashes for yapic.json-1.5.4-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86cf4f75e093b71fbea29f6a01f6cbec92e3cd88716442a3e282a850fffe5f9f |
|
MD5 | 80bb2e7e764c3d9462f239f980169b92 |
|
BLAKE2b-256 | 69ab8e5058f0c0b2231bee3c4ebcc1f835172d56aaee934261555155eb75d394 |
Hashes for yapic.json-1.5.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aae17354eadd3927528d411ab53fdf1923398900e397040adba88cc322b745bb |
|
MD5 | 5d866be174e22fc36b213874115a2ded |
|
BLAKE2b-256 | 6a5ee277aa34a940cb6183117004e01cbfda8be1eb4df422879d943ae1381994 |
Hashes for yapic.json-1.5.4-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 745ce3cb5fe719fe68f54e44cc2af6e4a3763a3266cfe302cca4a76f039f73e6 |
|
MD5 | e2b59de292bcd18a77f30d2e53072b64 |
|
BLAKE2b-256 | 93dc0092e2bb9411cbfe11bcd9c786239924038402b6765a8de90501d8079f71 |
Hashes for yapic.json-1.5.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecbc5fd55ab83edb183bd50cc5af16f73559943430583451f590a7d5fe8f7074 |
|
MD5 | d8ea5b8bcb6014cff3f190e3690ad753 |
|
BLAKE2b-256 | 365660c11d59083feb61c50f69174c19b085d014e4596041456f7cd71780d512 |
Hashes for yapic.json-1.5.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c64f3ef13a038e0853b9706adead7bc523bda3b6cf7d32d3a7931c5ca9db9e13 |
|
MD5 | 1c90b27fa6ff5b0b597b9ca3696f9b3f |
|
BLAKE2b-256 | 2e2732a11261e50d512e3be16eba8c99ce1a299d112821e4a9b79180483c82c6 |
Hashes for yapic.json-1.5.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af3c5a7ee4c5119e75e473de923a26b2a2fceafd2ecb6ca6ce2b36b1351175d0 |
|
MD5 | 58f73a2fdbef771a837bd3b38c9ddb0f |
|
BLAKE2b-256 | b5f9d6da33902811e660caee5814076f3888eddd02ba788be84c1a428bd74853 |
Hashes for yapic.json-1.5.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 120a7e337af6cff1f1407deda6fef2dfe49b596a82d9af6a46b5bf5db96c9c89 |
|
MD5 | 58f6f346853da811f63e9488d6a6ebb8 |
|
BLAKE2b-256 | 5289ffc456341f53878f759e65b16467864b9c53174308a52e2d18ba62d50e5b |
Hashes for yapic.json-1.5.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c267e7578253977cf00322853c832a24347a563dea39772195b5070d8d6e75e |
|
MD5 | a076ddff8eb17d5742e649f520a4924f |
|
BLAKE2b-256 | 3c0f283fb1e03695838cb57ad0b97591f0f20f9da7a82c9021c3ee2801e382c7 |
Hashes for yapic.json-1.5.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0868b6a64b904688bab0bfda01d947cd0a2843f7dd1171ae0a29739f84b8d5ef |
|
MD5 | 54709eee6f78061be930d7a511c316d7 |
|
BLAKE2b-256 | 8dcb4fc920a31883b7c987eb066f8a7e71089d05cc4cbb80714af28d2d9a51de |
Hashes for yapic.json-1.5.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 584bd8a74357511c997ba413e328a745287ea143c10937d668aaff880de2a4f0 |
|
MD5 | 8d5b13b0ead3354637375a3f4cad5fbd |
|
BLAKE2b-256 | 7ca3ac3ae9108b8cd6cea7ac70ea7bf2643c8aac4309f891ce6e39ca87521aba |
Hashes for yapic.json-1.5.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c212f6b58fc91207f3908d9e9960bd0caaf417984d5f80c4c8fe8506ae832d4b |
|
MD5 | 3520959175879901c46839c591ae4a51 |
|
BLAKE2b-256 | f4212ba0e0df0d44c19aea749658b5fa402544e1095697f3587d11296dc70d47 |
Hashes for yapic.json-1.5.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fa1adc7fc98dd3d633eed6ad696656ce5ce2cac02bb8d0aaa797a581de1520a |
|
MD5 | 484893b46af87dd03f0ca8d710644837 |
|
BLAKE2b-256 | fe784bde26741135d23a5fc624bb77747bb07b7b9f7c2d2493e3abf9293f5b2c |
Hashes for yapic.json-1.5.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf65b957151e68ac1cb8192d425ba9f77b7e93389f8ce2f949425541a62465d9 |
|
MD5 | de5acf0a861098a1b766630e838070a3 |
|
BLAKE2b-256 | e413e1f7c33c5bf9d30c2cb2a78435ab95fb0d1f8759208a140168745203ea06 |
Hashes for yapic.json-1.5.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba9794f1a124d16946e3fde57d9179162687a7eaafd9945cc8f23524bdde9b9a |
|
MD5 | f180696664d317098412f74b3a6a8778 |
|
BLAKE2b-256 | d04ce3e0915e48a7ea6d1ebd1225472383ed0a383478499331e5fa228948f5a6 |
Hashes for yapic.json-1.5.4-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 540551609902b35423488897e9c71502c92773b2bf2fe0e71fa5dcd265eddc23 |
|
MD5 | 798e6ba53aeb6def4e0be72c24ff7dd2 |
|
BLAKE2b-256 | 1fe8b2d536aa3f81e8aedf8ea18004ceb63c1c61204bb6964cead18e8062c07f |