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.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893496bbf8bfaa9f5d15eb4186abea96ef98bdc782635c93cf6d2581074cb8ac |
|
MD5 | 82a565eaeff2468a53513440ad16023b |
|
BLAKE2b-256 | 4bb7d68218eb26c5da01f89d07c5d8213aa02e32101aabef219faf9cf563653f |
Hashes for yapic.json-1.6.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd7342412680d7c414dbafe8769440f2f62a1c051d69dbb6e5f8ad25037cacde |
|
MD5 | 3c1113be22558e68f08e3571f6e7a17b |
|
BLAKE2b-256 | 62f83638c8bfe0387f7b72e049f23dfb205937dcb45c5582617a36b2ef005726 |
Hashes for yapic.json-1.6.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6d8f029a8dd06c1ffb1311d813c770590291518cad1fd417879f52267bf4479 |
|
MD5 | 21a331be3b32ec35ae0a9be551f11da3 |
|
BLAKE2b-256 | af673fd97d822a9c940468beab899ed963ec6fb83c17fd568ebf151519cb70de |
Hashes for yapic.json-1.6.2-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca261d308665a00449e475ee515c59dc1a91a42e00e89fbef37f93f20b86b717 |
|
MD5 | 86d7534681b1f5cee1759ad377780a42 |
|
BLAKE2b-256 | 5f3974c9ccca9cb60683a5ee1732f36f395a67482dfbc40b66f1ce90552deb16 |
Hashes for yapic.json-1.6.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a2f871e51af45c2fb6a9dd026f5c4422829afce0cfa487f684489cb5d610641 |
|
MD5 | 8d95b90a7390e00b70acac7b5b52ebf8 |
|
BLAKE2b-256 | d4aaa70a5edcc0cf3648173501be91513f70c986f3f36af37c064f37a1fb5331 |
Hashes for yapic.json-1.6.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dfc5ad2bc1b258acbfb5e8bc23da32639e4e9101f730e5ae9b8830f4d2ab891 |
|
MD5 | 0d87df2c81c9f4317f13f9b200d886e2 |
|
BLAKE2b-256 | e3581a45ce623a50bc26deebadd6fa59fa8b6a3b30588997a5d1fd9026dcfd78 |
Hashes for yapic.json-1.6.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40bc1388ca6c841b1cf13427e21addf46d6884e2178c34b0c93a415e1a03e222 |
|
MD5 | 46680dbfad98b8ff4539cf905a39abae |
|
BLAKE2b-256 | 95591ca247ceb9d616652a677acb5e929ea9561b75fcbb5c153afc6c210dcb1a |
Hashes for yapic.json-1.6.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17f5adb807989f2cbe4f5a1529009c3d06e9f5264d6c6b898db80ea345bdc08d |
|
MD5 | 966b30353d1a86566ce8cfdba7b48021 |
|
BLAKE2b-256 | 9420cdf0b409685055212856fd1292aa04cde3de11a81a15a075eb4b2d78e0b3 |
Hashes for yapic.json-1.6.2-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e522a6681eba9d46099d08b06735235feadcd1b3ca75efea2c443b6d96be8716 |
|
MD5 | 8228aae4cf1d37bc793529443432613c |
|
BLAKE2b-256 | a262302b93cc8078d14412ad6d37a35032c6049bc2f756fed6a1b25a8b560299 |
Hashes for yapic.json-1.6.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18232492ffb02f89e24794095b9d4e70c4acad38dbe248e0ec3fce598d9ad788 |
|
MD5 | e683f4c0310bd65f4e1ed295ed3d8bd2 |
|
BLAKE2b-256 | 361857821b1ca970051eddd7158c89ceef5ca964d2580c07367e02803b525e82 |
Hashes for yapic.json-1.6.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2700a72cb3dcd3e05679b0b46475c56c03198aed99a8e7f72178d6ee34d7a2cd |
|
MD5 | f338c02372ec55c56f5d6e3f43ff64c2 |
|
BLAKE2b-256 | 4625066a2e9482d864aa9a973870fc7c4f4e9d8eeb67f4c5e92de53beed4a7da |
Hashes for yapic.json-1.6.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7d7915ddaff5a442f7308e3c0ad2a85965f3b50a59f0ca4951041b0bbe06526 |
|
MD5 | 1064430ad465dcfb03f18d99eaf0be51 |
|
BLAKE2b-256 | d839d825ecf6d539ffe0b2d34187d434eafe9429a62024b552cddfb268281af1 |
Hashes for yapic.json-1.6.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3143371d117d1f6b11ba89d0bcfe890b467d7c90863d60addb6a85b7620a5511 |
|
MD5 | 7956491e0494119327195c661c019fcf |
|
BLAKE2b-256 | a855f6c12d40173de5f11f01396ed1a016fc47a516bbd3e13be44fd425c1956f |
Hashes for yapic.json-1.6.2-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f37288e83819517b73ffbd2ec2d22cd325f620eb3e14b46691650a5fc237be7 |
|
MD5 | ad3e28139c0e23816e70af3facab2e19 |
|
BLAKE2b-256 | 2ce16a64034ed8779114ef7fffbcb3f75be4c5406c4f45947b435662f0ecf473 |
Hashes for yapic.json-1.6.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 553c46a9c9a680bef4892bcedc11540c68ec894091289b31a87f644ab5031a3c |
|
MD5 | 8722f2bbd750bb4c74acedfe388d367d |
|
BLAKE2b-256 | 0fa4df9c413f3f9fb0ffd6c233c66bf9ee62b4bcd367be2e59e0524a0858b5d7 |
Hashes for yapic.json-1.6.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89f0e8fab39ae47272c758240d8172ec009efe1a3183b47b961e4d0bd74753c2 |
|
MD5 | ec4ea6974965fdae963961174cab7ce4 |
|
BLAKE2b-256 | fb391cd227bf03c9fabb652a77b4ac1b952236299a9ae77487021d66c65f6268 |
Hashes for yapic.json-1.6.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 507a462bbe3302b48da27fcf398ad6e6164ad6d732cc86acefbee0284296651a |
|
MD5 | 4c586d213f04530df42f40477653fb09 |
|
BLAKE2b-256 | 7083fb10608bd805c689097be1d3b8488869723b99432c3ba9e7037d74abe50b |
Hashes for yapic.json-1.6.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9958daf79ca6e9b527e91f108931848e876ee1339a6d5996d35c6d06a32dce2 |
|
MD5 | 961fb804135fe903260eecef3e45776d |
|
BLAKE2b-256 | c2c87f2b74e5ceb1c9488e8a176db53bb942caf60c559fd9808a67db6a7a6c77 |
Hashes for yapic.json-1.6.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 304e6b6244be4239959b99d9d1f835f25cdf504058988f22f8fa87e033555baa |
|
MD5 | be57bb45de09fc5a80a3afb0248b54ea |
|
BLAKE2b-256 | 4683fc6aed2f779a464816e94a8544a899fe43d76c210c20ddeb36521b72f040 |
Hashes for yapic.json-1.6.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f942f66495a02093c7d6c4af6457e996b297e49275f9a06d06555c1dd0996e42 |
|
MD5 | 7f7c5ebe01ac155302b9535e18009a31 |
|
BLAKE2b-256 | dfa30d5dfc4b08f77f547190250435d7b23cfa665bc4d3c31f31f82c504f614d |
Hashes for yapic.json-1.6.2-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e52395632fe118df5112daf0ece0e369b46adde533291d3c53364d57439f8f9c |
|
MD5 | b7456b92b9c3f6170f718e3f44eedaa4 |
|
BLAKE2b-256 | 104afd8008f5452fa13cd6a17662dafa39ce5e65a59b543f7eb16b09149b91ed |