Fastest JSON encode / decode library.
Reason this release was yanked:
Contains memory leak
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.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d91cd32c3be0cbb034de149129d53ac55a1eacbaa1c798fb194b26b81332bce |
|
MD5 | 8eaeeb7c9583d22dc9e55a6fbe6501d3 |
|
BLAKE2b-256 | 7bb7e580cb49c369a639b1c14b19bbdbe0a618587b556611371820ceee711918 |
Hashes for yapic.json-1.8.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230fea197a9b31d39d02da9be5d4abcfe995ad0a9f423d3bd8f280c1c68b0609 |
|
MD5 | 9c387d4208a534870b4837a1bd60714e |
|
BLAKE2b-256 | 08d8a8b9d303fb2c2f2d30989d5fa697eaf5c4e30134324e3c8ebb35c8cd475e |
Hashes for yapic.json-1.8.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1fbfa6cecf41926957781a2b0330a9b59da571a56123e4ed72c46ba5de9412 |
|
MD5 | 10965d7fbf533113c1c1dc4385259797 |
|
BLAKE2b-256 | 7708eb54c16b48de6a07098af113c3a7958e29c11a6b0c6c8ab9dd2856b666cc |
Hashes for yapic.json-1.8.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30b5f0d58037e0bb95ace2de315c289cc43f97cd901983f261285fbbc84ec40 |
|
MD5 | 08e9da78c2805220ab5081e6febeea2c |
|
BLAKE2b-256 | 4623214418931221902a1ef261a66a0c3729a7a27140a94b0a9941ddc1e00d33 |
Hashes for yapic.json-1.8.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9c59268d520d190794561bdddd05afa037d0d2255f18129b61c52032d4ff39b |
|
MD5 | a66cb1298b25f72958ab450ce960cd6e |
|
BLAKE2b-256 | caa3bb3d823b12e19c33353306bc50bd2d86196b21cc99fa13487baca41d09d4 |
Hashes for yapic.json-1.8.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 664bfe3be090e14aea786e9f2831dfe1095bac532168b812c7201bba99f1fa45 |
|
MD5 | 29a86bddb801a80cb8c05eb56b005574 |
|
BLAKE2b-256 | ce1b7d985aa97b83687c1bca86de39beaf7f942556c659daa61434e25f529d93 |
Hashes for yapic.json-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92de1842cd1ab0ccf8cbd415fe007b6055e2cb14a3f01d0509775a2bc69695de |
|
MD5 | 6202840fbc617b37e7cc393f3ee8267d |
|
BLAKE2b-256 | d32e16ffc8d0cd73cee8a65fde5611cf28fa511528e353ca00c501d254ce615e |
Hashes for yapic.json-1.8.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e696b44ced250269c3dfb4b63c89e2936c7cc88a5ddb10091b280943f2dcc20c |
|
MD5 | b32965bfcc064ac7d134b12bf9674026 |
|
BLAKE2b-256 | b7c5e7dbc84d244913b927e4ba48a7ec09c1218bec163126147e6fc2b314cf67 |
Hashes for yapic.json-1.8.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8b0b92b8986b71acc7f15ae2c46a0859483c506fcb9cbba111d56dd16a9aaf6 |
|
MD5 | 6b8c879e53aec3e7cbce1c9ebc3fee78 |
|
BLAKE2b-256 | 7722d050a70ff94f601bff21fd4c79d28dd1e90f1f4b16dcca8cdb49a6720104 |
Hashes for yapic.json-1.8.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3bb8bb341f734032dbd2a9443e0926a92841a2e81503c848479a960c83b3d0c |
|
MD5 | 7b58618e408e0b623e204b8d4537d902 |
|
BLAKE2b-256 | 58d1d32151cf554a74dd8838ecc4800ed47ef7df3a9442713b8966e851c8b678 |
Hashes for yapic.json-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cf0442ed1b843a4aceeaaf55e63cb211aec9f76505c10a34b3c6df57363d001 |
|
MD5 | 4c61a1c2c4683e4061a4a5426229dac3 |
|
BLAKE2b-256 | e706049bca68f88cb3f46eadb7b8274cf09ec3734dc9f04ffd92a4e5d3cb353b |
Hashes for yapic.json-1.8.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05af9bc990a10b22ad1d688f4a0354a433870b195a3f0f34a7cae46ba7a2c28b |
|
MD5 | f75f1607cb1667caca78cf21b5120114 |
|
BLAKE2b-256 | e305eec8250ec7f5eb7d29ac62c679616753805b9da4a1e82f743508cd8e5bf5 |
Hashes for yapic.json-1.8.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71bcfbc573d2f7fa69a95ee2c239a96c156cf4f810f23f827162fb48ddb7b503 |
|
MD5 | e9beac08c7634ac12245bc746ee958b2 |
|
BLAKE2b-256 | 31056c64a152bb6d712c2f3b5730b50abd59b62af4dc207cfa62ddb2d4fecf2c |
Hashes for yapic.json-1.8.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b78d0f91a3e0799c1c0c069b477f7e3951529aec64fab521f474a9b30231b1f3 |
|
MD5 | fd821d32ddb04206a85dcc76012878d9 |
|
BLAKE2b-256 | f80f3d7c112631d6323cb32cea849105fbcef86df4194e2ccd278c81f72e6e7c |
Hashes for yapic.json-1.8.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dbce7c329d549e24a56372ca1465ab592dffd74d96fcbb6c481a435457c2b57 |
|
MD5 | 4318b9fd899b36efd5475b07da0d08e6 |
|
BLAKE2b-256 | 8a497bd3574a5764f4cbf46463ab64d3b7b01168f39b216596f21884d3421f2e |
Hashes for yapic.json-1.8.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1de3903961db0a9d277ca768749dc4c4d972fe7c34b7a25ebc25bca1d41b151d |
|
MD5 | 083cce25b867cd8fa1eb8074de05924b |
|
BLAKE2b-256 | f0a76c1469466bb84c39a4eda2df7c3622d40a3cb9f0a973ab747ca7be24449a |
Hashes for yapic.json-1.8.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a31a8e4a6c8c9231477029914b79a88f88ea5da15998192d11edb1a5afdb49c5 |
|
MD5 | 1402cf2312d3825b60d8ba02ef570a50 |
|
BLAKE2b-256 | bc7a4851f781594dd5230ca41dee959f88b04156356d8c82a0055db85332cb62 |
Hashes for yapic.json-1.8.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20587b3e7ab9a939f44b439b2d2e2d3237307d9616ad951fbb8c58977d7e02f6 |
|
MD5 | e7c5c7df13ee644b049fee7635da6103 |
|
BLAKE2b-256 | d6f20d0263de87f7f8d2e5b93e1b1f412226d90efcb728666b12e2fe8af29d07 |
Hashes for yapic.json-1.8.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83f2482c7a9a8533a30ccf39932851f8c2e97c27fe3708cdb8b86d8c2dca242e |
|
MD5 | ee68e3330d6b53f02a884322696b0184 |
|
BLAKE2b-256 | 746d8123ffd04148d8ed18380a5e43650ddb68ae68fe740937d567e4f7ef0e0e |