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.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e9a2d28de834d37bf273d05a0b2bee4d75f16599e205e3cc542c144bfd8a3eb |
|
MD5 | b17cdb57d0b74777590499b1d41a75e3 |
|
BLAKE2b-256 | 19d05ddf9729afb5a5a95bc3e25a59f25f1173f424c71c64d70a6c9fb0bfa861 |
Hashes for yapic.json-1.7.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357c70f5e1e943747cbe025c35f3c456680998c3903c7eb45f10482398d97524 |
|
MD5 | 5d6884b45a1d3c72eecf5772a692dd59 |
|
BLAKE2b-256 | d267f02e3e12a8b0f8f1d0ebfa490d98f9cbad5286f7786aa1c9818883b92794 |
Hashes for yapic.json-1.7.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86a6a226c872fd06dc877fe29684ee9c61afca92086990403e46a2769dfa30cc |
|
MD5 | 44f5f57278082dc964820ed465abb347 |
|
BLAKE2b-256 | b2607edf898ecf029fe388c1cf717233da656dbfe9ef91e7cebac21c94157e9d |
Hashes for yapic.json-1.7.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867e9fe6aa4c2b15300978283862292c12cb0bd369e78494fbf3d552a483ba8c |
|
MD5 | 86e6cebaecf431d851b454cc3d637102 |
|
BLAKE2b-256 | dffa0b0e00525ae8e6a2015188e92a4aa5fc8bc61f5a7ffa7eb892ec1a091f21 |
Hashes for yapic.json-1.7.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58a65d41a40e14356be150cee8dde887b6a1f6a5c3ed8b15507b1b10626fa473 |
|
MD5 | 58b5e68d7434039dc714698240453f71 |
|
BLAKE2b-256 | 4e15549e18241c9e12f36d188a5ca9e5af651eb68f7735bb82cd9d23d54c2912 |
Hashes for yapic.json-1.7.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81e67620c5bec04d2400041e7ac8b161b17446bfa30ed2d8559e57ee6e79d093 |
|
MD5 | 4911eff9d830840cafae7c7e9d01b581 |
|
BLAKE2b-256 | 0ccfce007689e84d7a7c49b7b8c2cf589f0485d52be4ab2ba8de43666555692e |
Hashes for yapic.json-1.7.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb88068ea076ba9b8f5e9896c89bd8158a8d618569cee0ce158b97558f32bc27 |
|
MD5 | ddf81c8d9c5cf4aa90b0976081160810 |
|
BLAKE2b-256 | b98d707ca4696a71b2da55638ab62d836d18d7bfa4c138ddcbb19accbbeaf1b1 |
Hashes for yapic.json-1.7.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9de4592f3bcfaa2f276790fe9a049a7569825787b6dcfd9b1aa70b662c3443a0 |
|
MD5 | 2ecf440300bf7d50a584537f8981f265 |
|
BLAKE2b-256 | d13a03dbcd25732c965ea50fb1c4b906d260097c67a4ecb8ddd6c5b17cc45b3e |
Hashes for yapic.json-1.7.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1637308368bfa22b1d629090a12d79f615b4284cc770c81739ebe6a953dae5d9 |
|
MD5 | 973dcaab8f307ed2c751ee2e43211dfa |
|
BLAKE2b-256 | 79b8f3320392cea54bd906091b5a41ab0a875b4b634e8ad5cb059f2f352c9a86 |
Hashes for yapic.json-1.7.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 020d469969dee6422289c8276dcb8735b1b8d2c99fd0c431f12fe3d4fbdbdc09 |
|
MD5 | ec606d6fa45120d2dd5cd91242d5935c |
|
BLAKE2b-256 | 7084637bdc2d2aa5f1ff3be8f4fe9f91eae2eb8809713132cec8b99c9ac9e27a |
Hashes for yapic.json-1.7.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34330098b79e0f8e03de4cf0f9692241c37ee02fcbcd2a99deec3cdbe147c508 |
|
MD5 | 087929c89e81e13a3d04739a323cc757 |
|
BLAKE2b-256 | 5e99c24f0b67e028fa18ba628668345c7446780e638e88f9f8a224d544a3e953 |
Hashes for yapic.json-1.7.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2063631c636019da64e6cc9b2b7e722532478d405e8aeeb6e5b4c3e6462d385 |
|
MD5 | a5014506a59dcbe29cf759991278855e |
|
BLAKE2b-256 | 68ca6673395b5b9894e9e6221b45b7745fc9778196de47be020fd0f5477e6dac |
Hashes for yapic.json-1.7.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca9d08865b9fdfb08f78c50d19d5c8a479e65ba150056433bd928e8aa4039a5 |
|
MD5 | 71b0333b0524773c085e9a1e204e76be |
|
BLAKE2b-256 | 8a2e4b9dc398bd593c1d30b50e71a9366706b6c4495c6a4f81dc1effe2c7cae1 |
Hashes for yapic.json-1.7.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 830c3e74a2625f0b6fd07a6b585f8669a923fd099cc2fd730b0aab5cec881c12 |
|
MD5 | fb24a9b928959fdf1b7a255373478448 |
|
BLAKE2b-256 | 083e6685c95895c54d34f9db6808d807a45f8b073e9e5fe96dde563e5964b755 |
Hashes for yapic.json-1.7.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad5eeda64c36fdf261431acdf0e1ed32e48d2e6c2bd1e8bb0b0065abda4eca4c |
|
MD5 | a1d5348ab9158e8b911fe6297ebb0329 |
|
BLAKE2b-256 | 85f2470cb73c38dfed0fdf9cbca9c0883db966cac74cf39b210b3ba9b0645f86 |
Hashes for yapic.json-1.7.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3e6fd8f48095a4523f2c22479b99761797c15902fbb2abd9cd7ea4a4aaa59f |
|
MD5 | 1997c0c2c678b85cbc57082329566e30 |
|
BLAKE2b-256 | e865283531835cd62d7dcde03ba95d33966911cf770635a58be6d79e7b843ca8 |