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, dataclass |
{…} |
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.9.5-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db5a5828efd0d207a74f71bd41ab7db995fe26920bff1e413b756b367691db2 |
|
MD5 | aa27e60386149da775bd83a1c8d825eb |
|
BLAKE2b-256 | cb6e664b9557cf99e34783da9f2cb384817379cea2b8d5f02f73fe119023c4dd |
Hashes for yapic.json-1.9.5-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63036af738ccd4d3cf5a3446a2867ad62e78f66af21dcd73b77992a19ee43e15 |
|
MD5 | 77db3a0f7bb0c1af550105a7b101ef92 |
|
BLAKE2b-256 | 263deedd25e7497d7e761907705b99f8fb452e27a24f54be9d4d4cd505eec1b6 |
Hashes for yapic.json-1.9.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8d37c115b31bdef135918a2f24e3bdbee128f16838ce44def5114dd48da2de1 |
|
MD5 | e9b89f56572ba48fb107ba88d506d50f |
|
BLAKE2b-256 | e9d44c7341485efead5d29d8230789fb44af3c6a27b57c54661aaf3e0bc389e6 |
Hashes for yapic.json-1.9.5-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 570a65975f312cf7118526e36349d914a3b736b79e6e005dae99e6dd1eb00fea |
|
MD5 | c524d9a460685769aa19f559a44db19d |
|
BLAKE2b-256 | 90c8f409a334fea320b3505812ed190559e0b62ef53cbabe19428615ad974634 |
Hashes for yapic.json-1.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cea756a8c786309690f95a76d49549094fc8c40ba8ea14b53cc484ffdbec885 |
|
MD5 | c7e6201284593d7d0c46902df5ac5831 |
|
BLAKE2b-256 | 6eedebc25d60204cff64ed2182ae819a92df06afd8b9a1ce067d9026d52e759e |
Hashes for yapic.json-1.9.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b5a42986def9908fab9da85ce35429f76a0f92b0c13e42660b5de921e0cb2b6 |
|
MD5 | dbcbdb39c18bffc768a02eab7a576069 |
|
BLAKE2b-256 | 89e34290f611ce9216af7252a07c7e08ea8831e83cab8d85925c9852f2b30f3f |
Hashes for yapic.json-1.9.5-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b69e9d7a84aac758883c47e4eff379b64283be34da9804a3ce19373d0bf7361 |
|
MD5 | 96319e2c1f6b3489b4fc8bca09c2570d |
|
BLAKE2b-256 | 11cef1630faee68721ce2d0d7a4864ba0b9454dc66ff5d56bfb623e40a47663d |
Hashes for yapic.json-1.9.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e2955502171738e9bfd367dfe4680f8a21eeec5b5cef84b4bafb6b487fa05bb |
|
MD5 | f058cde4ee2541ccbe6331a6bc6ee418 |
|
BLAKE2b-256 | 9b97cf6fed72febc22404ce36713653ec38715e1f73cfc63a58496bddd536482 |
Hashes for yapic.json-1.9.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be226bc8b20af020b2453c017ac753d5ae48cb5989386f0dc8910a861750f3f4 |
|
MD5 | e4e5181b8486e3ada407907fdfb37b5a |
|
BLAKE2b-256 | 02ac4b01db28bb6eb315c523c0210b32e723d4a3cecdae6ff155fa01777a2166 |
Hashes for yapic.json-1.9.5-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5abaa56b65cdb5d72fa6878339296edfb7702bb3893031662753fec52cb7fa12 |
|
MD5 | 00e295a2ed64448f814f8b7a6824c251 |
|
BLAKE2b-256 | c62aeccd59bf1411db491dcd33f9addacec2989193ab39142bb8464eace575bb |
Hashes for yapic.json-1.9.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c3cc99d44e57d1e214c9c2e0be70c98123e602efb7b2be0161268c456cfc4d5 |
|
MD5 | 775c947c34b7e214422fee4a6516e7ae |
|
BLAKE2b-256 | db4d37f0a6036e755a5f76eb2a3d1130384d3f00dcee3b9a0cbdc7aeabc87451 |
Hashes for yapic.json-1.9.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fefe71a6d64fbcd69ea12bfe820c91d7fa8148369970ff61fa7ac29456df92c4 |
|
MD5 | 0de2ab2b52006d7cfd87c55df553bd0f |
|
BLAKE2b-256 | 7cc1f4c4dff34dc6a6b39519d643dd8b147e2f93c49fb5c41068e3e25b5922c6 |
Hashes for yapic.json-1.9.5-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71e6eac1d1bead9ce1107312d567d0ba74802fe34e2db2dba50d24b9286551f5 |
|
MD5 | 69788281b127d2becdc8ed1a6a1d0ed6 |
|
BLAKE2b-256 | 28c8fb65c09a6f9724b2b6c70fb73519743b74754cfdaa702830b7cb51418567 |
Hashes for yapic.json-1.9.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d2ac05d561e13bb6364aa08b5afbddd4531968e434595ae99d1ec9fca23bf8 |
|
MD5 | 6e9d5860ad8775f6eed2eeb8df5334b1 |
|
BLAKE2b-256 | 78543b6baf1059ec582691dd7be210119e1acd3ac78b5805d6e3729e7ecbcd11 |
Hashes for yapic.json-1.9.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a6895cc0a8942202da85b64b3fbecfcdf1519676f92c539d89418df25e5845b |
|
MD5 | 98252085ab91f25dd455165267f7de4f |
|
BLAKE2b-256 | 4c513ce5602196422eb171004946762f1f019168e0f1e2297c6ce11f6347bb2f |