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.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7facaa6e0ebb1a3278d598e7b9582ec358e900f2aa9dd51e1f2cc92fd7d0278 |
|
MD5 | d5d6e95d56a25b0d95072b481ed67bfd |
|
BLAKE2b-256 | 714b5dcc281470f94d311b6dda0160359a697186a534ebb1a16ab7246f321083 |
Hashes for yapic.json-1.7.3-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b05f657d4f3c68bbeb4c99b24be6982bdc064dc707d6ab6d82fb746e9f1576e8 |
|
MD5 | fe6ea02190135ce3ad43536665f46498 |
|
BLAKE2b-256 | a52c736f8950e54db588dca8cbb0d13638dab447f87e78b503d590115473970d |
Hashes for yapic.json-1.7.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66c2b4797f46f7dac48814956505ae53ef43707f8625c208e44a9af1caddce8c |
|
MD5 | 54275a07a95fa45cd86156cd36af6092 |
|
BLAKE2b-256 | ac5e505f943a9bf079fd5b511796abbdf7f9c51a044baf854353df66b31f0530 |
Hashes for yapic.json-1.7.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bccbbb1282e387403934f323e367b340a57194c14cc39e1eba13abfb33eb82df |
|
MD5 | 7b9fdeccb72853e149a105f72c40840c |
|
BLAKE2b-256 | 58f18445ed9315862c880cfcb1f4cbd49dfa428c25edb57fe3834ce58548adba |
Hashes for yapic.json-1.7.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c52b8150b3cecc0560e2aef3aed1df2fc21ef81e3601c76959f95c3f938924d |
|
MD5 | 497c17962be4270daebbe3a8bc3d97ea |
|
BLAKE2b-256 | 44e7060eecfab3864730e076ee348505071578944478307eb3cf85fbd86c53c2 |
Hashes for yapic.json-1.7.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0477f16bf9af12fd22056b90ffa964ddb2fa936e1f3d9bbbde90168c78f64051 |
|
MD5 | a6d3ba722da5c4feef613151a4439d93 |
|
BLAKE2b-256 | 496275e5fec8156a24db085c483a9bfc7931047778d79cbb1a414e39db554510 |
Hashes for yapic.json-1.7.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 298d240111dfc023407af3ddec8d6ca4f0b9e65ec38fa9a99cd9e81af82b9e50 |
|
MD5 | c57c9a0bc07faadf119c45aec39dd879 |
|
BLAKE2b-256 | 8cb908078f3b2a8bf22f3cbdbd86d57e8edce0cd23b6ed2712c4edb5aecfecc4 |
Hashes for yapic.json-1.7.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a19c60e04c8698dd49bda34757c24a6b29732075e62df51f9178ce9457fa1c49 |
|
MD5 | fabc333cf14ac66c33781c3a730433e8 |
|
BLAKE2b-256 | bf0b3832b5452759ea989d660fc16541c74a7e8bca8ca30a9eadf9c6eb74d2e5 |
Hashes for yapic.json-1.7.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f6598613483afb50a7cf46d13f07a1dbcd1b62f968814bb158a56f2e69297b |
|
MD5 | 9c66aac3ec3ff3b2b1e8082eba5e1b2a |
|
BLAKE2b-256 | cd369997d4ebfb3bbe39a031476b8dd642b5b4d16012b6245d3502f050c490b9 |
Hashes for yapic.json-1.7.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3428485ad34b687ddb2c26e942b99ca9bb9e3e133f5b2f250acd6486e7cab4e |
|
MD5 | d09747ad8a89b8e53b4248c6a5b5ebaf |
|
BLAKE2b-256 | 8e5da26d2c0582a4c8ccc11a356e4dd8f976ccaacdba3cfa8ebab82e72058385 |
Hashes for yapic.json-1.7.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fee832140eb2d84a80c4b8f7816f012c4f14896aa0761074d73020ed26e46c93 |
|
MD5 | 4c9751a22a63abef0d3cedc864b5fd11 |
|
BLAKE2b-256 | 24ce16310ae0a547b3935865c5a238633ed1a973409a14400ba36c6934b86448 |
Hashes for yapic.json-1.7.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 097f940a21bd914a9d982e255a4f987967664da3ffecdb4fa1631f44b58b6ef8 |
|
MD5 | cef58eb4de97ebf665c2999b3c257042 |
|
BLAKE2b-256 | 4d3d121e62118cf9f8d3f35961544901bef291b989d351d2b5b7c9ccbeacb759 |
Hashes for yapic.json-1.7.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b4389b41a017df8350f639b060dd91d74d94ac2b374ad38b79dcc04c7a163df |
|
MD5 | 73e47245e3e9db9a1482fa831d4982fd |
|
BLAKE2b-256 | 05da8425eac57874b0431521975ffb3e5bc053f80851844bc33fab495593bba8 |
Hashes for yapic.json-1.7.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858934ea0ffe625c0d13dc66afbf87d748c8cf3ecfc2b1077ee052111b7c2660 |
|
MD5 | d6f0f3776155f31fcc11794889644db5 |
|
BLAKE2b-256 | a8b20bc3cae6dba24f59312cb87ec6727ba763d7aaf4515ef7f40dad99f87701 |
Hashes for yapic.json-1.7.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e125d481701d344041f52c3f35c9d7ecadb9ab90cc64ace334c0dc7a5f69e0a |
|
MD5 | 73a9f830ecaec572deef69d16774dcc7 |
|
BLAKE2b-256 | a5d8fabcbaf051227ca3978347bd2ea404a94c685f05b4a20c025518ab7e9181 |
Hashes for yapic.json-1.7.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e8a0bfdcf561b0bd63d6633441dba09db2496a1629699f378b992f65e5ab6b |
|
MD5 | 2a8ae30d039dbaa6adaaba582cbeee50 |
|
BLAKE2b-256 | 8007a660b35d757bd3e877c47309b1321848326976f37cd860544e5bc8755c88 |
Hashes for yapic.json-1.7.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff9195c74d40f47d5567d6c5d9e17982785c572959f30edbfc2a0862705badd2 |
|
MD5 | 886e857b646b015b13f60c124b1083cf |
|
BLAKE2b-256 | 120a7134bed662cb59adec7c30ffc8eeb1bf1e943257f91eb6f3afb17c37eccc |
Hashes for yapic.json-1.7.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e986f5a6490019f0b972c570df5368273a5d5c07f41807d017b7b5eeaf4d63ae |
|
MD5 | 477b163f4340b525e231048b69381153 |
|
BLAKE2b-256 | 64bbb5e68eca92ed233d7aa1a97b747f0874d1f1f4ba43eacf1835a6ad366d2b |
Hashes for yapic.json-1.7.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4816b0d444bd2651f84609ed06beaa94bc9cfad29d0e143136d5c850d7ec9fd7 |
|
MD5 | 220b7d62e5016227868923c0fc8404bf |
|
BLAKE2b-256 | 8e03702223813291c2d685c0470eaf7048c46962dead04b14eb4a541a9e3ad3b |