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
import json as py_json
class JsonError(ValueError):
"""Base exception for all json errors"""
class JsonEncodeError(JsonError):
"""Exception for encoding errors"""
class JsonDecodeError(JsonError, py_json.JSONDecodeError):
"""Exception for decoding errors
Can match python builtin ``json.JSONDecodeError``.
"""
# alias for easier switch from std json lib
JSONDecodeError = JsonDecodeError
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.8.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55d6ff27a0c309587e40b7dfccc06ea6f1d7e221778e544b72e217d58a232fb7 |
|
MD5 | 7cb378fb7f7dad824d3f3eb249af90f5 |
|
BLAKE2b-256 | cbd0a95c98eaaa2e18cb6fe3e9da31a44cea89a386fe6c85dd448269a22558a2 |
Hashes for yapic.json-1.8.1-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10aca46a76605bea8dde895123fae4cd4c427299ab5f4df8cadab63229089ab8 |
|
MD5 | 1895774eb2070b6286642d9f072faf81 |
|
BLAKE2b-256 | b424dff344b01c5a38e0535bd91f620d5221c62fb5e880c78757ff143c2bd1f1 |
Hashes for yapic.json-1.8.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4fcdfacb019423d8711d082a43e4a75228b257e6a0da9561dca35cac69773e |
|
MD5 | 982fa30a7c504862639c21f2fbf58584 |
|
BLAKE2b-256 | 5c8ab9077eaedce8505bb2afd314fe5b0ef2f3ad5c07aaa48eb3acca9c53614d |
Hashes for yapic.json-1.8.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 756a2ecce91b51e19e186ed785f134adef71d1d8514adec6525cc29554f92443 |
|
MD5 | 81f4863f465293ed76373915b42f4633 |
|
BLAKE2b-256 | a4e3193c895d01b0bfe58c26fb6ef74b9b4dec77959d3efae1fb456cd0f7be35 |
Hashes for yapic.json-1.8.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fb15129a88a14dd96f21c9eb6d9b49ae07786dbcd787c47e11f32eeb96929c8 |
|
MD5 | 9f59b64b1cc01f54616d0764ba159f30 |
|
BLAKE2b-256 | 75dfe39dca8c386d5f9f44e910618102b14f6873fbf61e90cfc190b8d8608041 |
Hashes for yapic.json-1.8.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296792ea64eb85cc52688b5b65bdc6fbd44bfa7ab3a76926af702cfb2fd7cef6 |
|
MD5 | 575bc4d4131c42e3cdd9becb6bb91951 |
|
BLAKE2b-256 | 91b3732ff7ad8ff0c9810537eba86b2ce37b17624e15eb6ed3ee45a59ff0a67c |
Hashes for yapic.json-1.8.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a839d39b5fbfed0f8fb2014105d9c1a0554cd53e4e074e7f33a21217a19c303 |
|
MD5 | 0a15ba955bc50cad592f41919d12acac |
|
BLAKE2b-256 | 82136676b69f1db3feb35b6a6a9aca552170c6eba9050bca105df57c66a3475e |
Hashes for yapic.json-1.8.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 648150da7176153f269efb7309e975e34010f3ab2145a0fb26e4ac8ad52f1d6f |
|
MD5 | 35cc4554c0fd3b71fda24e5a78a832a4 |
|
BLAKE2b-256 | f52f8b1fc6aa7b06a2a620d87a6a719662f176bec0ccdf833a8e55218183cc60 |
Hashes for yapic.json-1.8.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09f73f919f7272cb09c3dd03a4a9891efbfe0d11652a926aaf522eeca1df2ec0 |
|
MD5 | 918c0fe67bdb0d9c016f032b87626d7a |
|
BLAKE2b-256 | 26b81e21a8dbd73b1d17aa87de0b327cd84c81d74827026e3a9cb1657fe13c0d |
Hashes for yapic.json-1.8.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cefffdecc2f4ec8fd86fc13c293f727c9f6af843355bc05ee5a5b92d437aa9d |
|
MD5 | f6016abe2ccaf10554eb91cb79d8e3c9 |
|
BLAKE2b-256 | 25415e11805c8918524dcd954f988b3ebc3b2c78712f28519328a2a234719665 |
Hashes for yapic.json-1.8.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15b24a79772eb58dbbc7f3b9d2e07914b28b12e5e27dcb2a9c8c7583c68887c4 |
|
MD5 | 4648ff1b80e035b88a94c777649d49aa |
|
BLAKE2b-256 | a56528952bf710f62a02222fa0463b74ff53edeb9caf475f7e26009447fd09e9 |
Hashes for yapic.json-1.8.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29a54dfc56ffa2a1be4aa22f49aae9988fd27a007d5499074c24a5e97717120 |
|
MD5 | 259ef5a8e9de8ed601d577cc3523c70f |
|
BLAKE2b-256 | 6b7e5a1acd092370544c76205d6a6eb58ba14557fe102a86db027b478952eede |
Hashes for yapic.json-1.8.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f230203aa8c754efdb56209afdf6c136b218e6a60ca446b886c2d83bfdba54 |
|
MD5 | f5f8d20c8c666f002fbd698d233e31c1 |
|
BLAKE2b-256 | e90b28b9b89a09ec7939a2b8c80078c3fc7e4cb6ec95a4c3aecb7ad95844bc14 |
Hashes for yapic.json-1.8.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80358435683bcebb8d1a4b0f37f4dcbe324e4b56139e34662e8ea5517ffaffe9 |
|
MD5 | bbbeef9d5ce0967263a22b614a158285 |
|
BLAKE2b-256 | 4f282365b122c7886bc08ed93ab28972aec2cbe41f113bcd52822f6297f3c477 |
Hashes for yapic.json-1.8.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d22c30f97d4686dd345f263b48186e3edb024d5a8834d71a4f88137ce9d06f |
|
MD5 | a003a9cebf788e3fed746f0091d4d9fa |
|
BLAKE2b-256 | 8be4b30bdb960768f02b6eb64b9aed1833f2079b5a340bc4e2acf7ef28efe072 |
Hashes for yapic.json-1.8.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bd7230862d30dabf3fdf7b37211594a85ec2059ee31e1b1bb0baff3f9ea8ec0 |
|
MD5 | 4d0fe989f9a8dcbe93573f39d660a19f |
|
BLAKE2b-256 | 75aba7ffd136a896240470a53daf84a044c98060f4fc9c9704c2b1a8486c03ef |
Hashes for yapic.json-1.8.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7a1fd334370cf90b794faf6274c1faad850383f6c0ada4b4d80b75e39254f5c |
|
MD5 | 7767dbb6af4a80ae607bec1981989302 |
|
BLAKE2b-256 | a829c5fe83bca85e371d95e0c0a8e955e7d90f4bbc425f93372de8905064218a |
Hashes for yapic.json-1.8.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a0d7cb8c76a0bb97cc3c4bec65a89617a4d65aa450d3b1df6052f2cfefdf9f7 |
|
MD5 | be17cfb7c807a4cacf986ef544505884 |
|
BLAKE2b-256 | d716f889cecc7e01013e5484641d2d39910d2b14cba6f5e5df8a39918d4a2c7c |
Hashes for yapic.json-1.8.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60673a8113d59ced1eb9956bcb43018974457d6fe87cdf4358b43298e0e26a2b |
|
MD5 | a7f5eda8f98b88dcbf5f696199b6e22d |
|
BLAKE2b-256 | 7c02720e00d2e439c3a4479107aa8054a2ea3df83dd7b25fd426a4b098ae771d |