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
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” |
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.7.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd732e3afb89c34c190232e219ca98ef0ed1e87470e3bf6aa392053dfd65d92 |
|
MD5 | 422b8a8c407b42445a342fe8f8d0a0c1 |
|
BLAKE2b-256 | 75640d63c568bf30dde0bb9738b3612b388c290202949311b1ce1cfef0dfd725 |
Hashes for yapic.json-1.7.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f8e3b08ded687e688b4983f027c051bba6cf11571f7e3c919d0d8fe9a4085fd |
|
MD5 | 33de5cea1d179af95c2b3c6102dee979 |
|
BLAKE2b-256 | 759a54b1d6f925aaca8c32428604870f4197a1e6aa34e514aa29e0e7d1c59887 |
Hashes for yapic.json-1.7.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8a3a23494286fa2f8fac4b92667ad7ca99a254704930a67f70446f2c7b90643 |
|
MD5 | b2dd7115d48341f5ce0f9520ceade784 |
|
BLAKE2b-256 | 6f08122c47b468be08ca46aa4aa2f4374dd788b364f23f9dfdda663237913cd8 |
Hashes for yapic.json-1.7.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df3b8344d30ba28f755ba2339af081c98c688030c857020f10dba978022f6a46 |
|
MD5 | d31c6b2378041786680c8ca85061442b |
|
BLAKE2b-256 | a7796492e6e4bc617381c3c7be339c82970ed75954ad590efb4c4302ae10d740 |
Hashes for yapic.json-1.7.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec543a60ba202cbbeeb894218d132b3004d85fd392b1d710e5476d28ef4aacc |
|
MD5 | 8b9a87946575df2ab792d5e0ff02ab06 |
|
BLAKE2b-256 | 3dc8b8649a439b5104fd6c985a7d27ad6d1c900657b7c236364118d631be71b8 |
Hashes for yapic.json-1.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fb39bec4900b4b9728357f211fd4c0262a5f51e8d0ce2a0c3946aaeee63ae8f |
|
MD5 | 838122229042ca29937202c7cb8cc6e8 |
|
BLAKE2b-256 | 266771b3433bd06f14364fa2ff8ca37933e61900a7f0588ebb3084f279be5932 |
Hashes for yapic.json-1.7.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f8de89d48c85996d6f7e5b3f7993be22f61bc7d3b3572fd9b40b111d1b9bdfe |
|
MD5 | 5802a1c496f170514c87b25a76748030 |
|
BLAKE2b-256 | d10b74f6c74f8e1da36ff3ceb25127c3ac01d9d9394ebe712ade6836349cffc3 |
Hashes for yapic.json-1.7.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c5c1bfe5e3bcf25cf7e82d233e2a0399f9abbd1fbcf3a37980242c565252d27 |
|
MD5 | 6369a8b1b0bcb66f6efd04bd914bf279 |
|
BLAKE2b-256 | 085d2a783963ea5aa0f792cc937dac3a88cc986c484914e05523bee90e0a112e |
Hashes for yapic.json-1.7.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0357182f710c01b87352c6da992f0ee0ad693d6743b12dab976899bab1bb79dd |
|
MD5 | edbf81076f39016f7a81333e31e7579d |
|
BLAKE2b-256 | 44b78250c13c26d5973b5383beeeeff75fa1f2a38bf92f1b25ba5288330592ab |
Hashes for yapic.json-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84c3cdaa3fdfdebdb11f9887c7f9d0bf696612511b617afa356c3a34dbe14e3 |
|
MD5 | e9014460c56fdf18c1195c0b04ea7438 |
|
BLAKE2b-256 | 77c076770c8c0281f95310e22cb7348c73c6d97acea0f1b329f03f04d9b35bab |
Hashes for yapic.json-1.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 608b04450f4db27ebbe0d13f66dad7a3be360dea635f34be2149ae9139f77777 |
|
MD5 | 1ece8679455a885f71d5ab35697a5cca |
|
BLAKE2b-256 | c5642b5d03214f53537cdaeff349035df7ac73302f3323ba8ab8b91e80eb6e43 |
Hashes for yapic.json-1.7.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf62438499de299c24c7f05360d268baca6c8a389db7b68ddf04702b3a0b6f8b |
|
MD5 | 413948472635d79f9f656666b924a57a |
|
BLAKE2b-256 | 69201cb0c0f4c2237eec4d7640b54d5dfba89b810ca25e0d0bde7c7258f6ac03 |
Hashes for yapic.json-1.7.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae75affef3f6f4baea5baebd6ade79ecd53d36f1d04c9d374ac20a617a54b3a |
|
MD5 | a5facbdae718f49574f7c66d6df3c0a6 |
|
BLAKE2b-256 | 888d24767a343ccedeecd465fbc98212c59bad71a2df094d553f3ec560beb65e |
Hashes for yapic.json-1.7.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6509c79c0e747791c93a0e9e89f2bdbcdb4e5a5da832cddc2f2dd4dcb4fb3216 |
|
MD5 | 7ebf9313b611ae54b2ac84088a606e4f |
|
BLAKE2b-256 | b301a775d42ce73005bd1aeaa21ad1e2f6890cae789e1766fdbf07f01d290337 |
Hashes for yapic.json-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 651d3e1ede93f105d0f476ca4aa29b0c0db57766b82910d1d55876271703d8e9 |
|
MD5 | a3f8e2c4088712a1787cb3223115b074 |
|
BLAKE2b-256 | 5e841fbe32a9af951ea76149420c0c216185b54618a838c001dc6da13510df70 |
Hashes for yapic.json-1.7.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2372062d74a18bc1dfbfbcd418dd4c2b89ad90f29551f2bdc2dd6c5307b86ee5 |
|
MD5 | 4807a20d55a4554f89bd5bc262b4d99e |
|
BLAKE2b-256 | 3f923c0925afeed9696563fdfaf6d7bed63b10475da23f4d98d9f51770818859 |
Hashes for yapic.json-1.7.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce633f5051b442e57dd09f5de9e49b47af1b16fc99991ab2200ff23ad4375e86 |
|
MD5 | 65a327430f6f1d3cc2c17feb295019ce |
|
BLAKE2b-256 | 9fd2aa1c25506e5ec7b8ced8a588d50c8dbd3117614ee7c1947f6c02a02d93bf |
Hashes for yapic.json-1.7.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16603b45295eca1b758b70ad3db8ce32274b7e17058b0dc11e48e5e35f462d7c |
|
MD5 | 73a5e8d829599caf62ce0f806aadaacf |
|
BLAKE2b-256 | 226c6e0db1833d9d8d93b93e6e20d2a03ab138f48193d8174ca7f63db9fa9e34 |
Hashes for yapic.json-1.7.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d59e7c70c23f315e42f4b435740a8d221aa56d06c39e7e0cc7a6e7eb42b61d9d |
|
MD5 | e25ffca8124a225751999c1db772dfaa |
|
BLAKE2b-256 | 75a08c3978b5c70dff514af9039b34f5a26e1245e966e6a53c11862e5bf11e6e |
Hashes for yapic.json-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 081c196898973d3db1c4f02ebcb57a602146dbbcec41ec6da1fd791441762ce2 |
|
MD5 | 47b5b3573451577396b168ba62f525db |
|
BLAKE2b-256 | 7af701dedc7c6a65df7e2e4063a1b0772d8e67b7ff2863ef21744466976727af |
Hashes for yapic.json-1.7.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4435a8fda2bfc26840fab72da441fce68ae0e2c1a0b935e30527989be919ee68 |
|
MD5 | 8d2d3d09e0e88ad3b63735d965242c75 |
|
BLAKE2b-256 | 52d591f3dac638b3e3d63a1d73d05b597d01e7ea038c2eb1180f39503d8110f3 |