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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a7de35dd774cf13950b356765dceab0b7c6abd4ff44a075598fff3b51914a9 |
|
MD5 | 1af9b9b7f8e1c310ad531eec4c293289 |
|
BLAKE2b-256 | 1e4aa9b7ed5b9de18d41507937556e51641c2e5e9372704d1d4e5d892e3d44dd |
Hashes for yapic.json-1.9.1-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f51f6306ead8ce7eca4cb4522dcdb6a3e01c18ae746cbb0c8ea2a64aa72a7c0 |
|
MD5 | d6b0be2d36edce58becb9907f872d053 |
|
BLAKE2b-256 | f11ebeec6ad2e8708c990cc1b8d46466fd969bb872b8913ba9afaca7244d9713 |
Hashes for yapic.json-1.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94f8b4f80260fdfda7a3eeea172960a485ef9d8d09db6e7839f09bdf450ce6f2 |
|
MD5 | 83eca6f0df83911700713142478b174e |
|
BLAKE2b-256 | d7bc93d0f0dfcdcf40f1d59893e77df2e153095a319d8f73878bc23ad21f13e5 |
Hashes for yapic.json-1.9.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b22a53f27d57f182e24f3dfb987451abd07e46986e42d3689f7802e215488f7a |
|
MD5 | 310a23a81c15d33eadbb0faa3bf1d1b1 |
|
BLAKE2b-256 | df70c8bbb7d8c6460a017561d4f2c8a4ad392240627a8ac69191a7751d0d4d56 |
Hashes for yapic.json-1.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f716072ceca2eded7c1b95f0dc20e72ae673ef2223fb05cbb38cd1a101fdb59c |
|
MD5 | 5bd55be4e424a5fb3322f3f4b44d7862 |
|
BLAKE2b-256 | 1f9f15563e7f6a2addfde3733887553bb07b3fcb0c1186e0d87bfe660e54fbd5 |
Hashes for yapic.json-1.9.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7ef9396d0ef58eaac43e99ba45c0f07dbbb6330be5eb1edd55c9655c3ec95be |
|
MD5 | b336853fb17be7932c64fba085cb04a6 |
|
BLAKE2b-256 | 828e26c87f234a9bc9288207a22a17e8f8071b9b170c57a655ee0afe64751e56 |
Hashes for yapic.json-1.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4b006ce83eb1b7d315c358a779b1ae5d282148da46758e553fedf4e199edb05 |
|
MD5 | 874347e44770d0fb6209f3af3ab1af82 |
|
BLAKE2b-256 | 39537e9b0429b66adf4896bdba9468dd3649d50b9ea92e5d84ad77c05e197fcf |
Hashes for yapic.json-1.9.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907331d5aefb4f553566e5c7cfebfcf5ccdfd64ef3c8557b5a1d3096537de8a0 |
|
MD5 | 32ebc7de05d98c2263a651917e84909d |
|
BLAKE2b-256 | 9c7638374d4eeebf819d1def66c53ed118fd28432031ced8b0bf23783d27671a |
Hashes for yapic.json-1.9.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5444a9dfe66743022834eb167fc5f264e70168bf169e911b3c6a97ad462f4a3f |
|
MD5 | 5faf521fda8b242d9f9f8aaed7e5b5e9 |
|
BLAKE2b-256 | e21bb3b3667ef159ff39f071779500aa77cc36def2ea86bd62dabdd1ef9ffeab |
Hashes for yapic.json-1.9.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e641bfbb0673a83853cac3a1b3c9a574e5665ae1092250b02b2c8b7c54ff0a44 |
|
MD5 | 31f81a00d9dd9ec503c6b7ea038276e4 |
|
BLAKE2b-256 | 3cd7a72ee6232ef64b1c48e0f8346b4159fc675d035627f8ccc589c2aa4ac169 |
Hashes for yapic.json-1.9.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a944c19a8cfd902cd26c5d06a9337f734b884cb9633fe73ae7befdb7282260dc |
|
MD5 | 0c23bbfd2c0456785cc344aebf577e04 |
|
BLAKE2b-256 | e273a634fd3a28a6cafe75ae340f7d88a48b3f093b702be09ba3fe236df697a0 |
Hashes for yapic.json-1.9.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b399d51b42023afd35c2c6b54e7d1ea2ef9eef00d78c222941145aa68794cae |
|
MD5 | be9c6f12cc5169f7da8e8aae8276c92c |
|
BLAKE2b-256 | 87d74d9a7bd27bfe7a3fc89fe8b3a31c0e83583afc1403c46e014c41accf2aad |
Hashes for yapic.json-1.9.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07eae5f8e3550a80228e17589a7af30b08b178c37340b2252a0ecfa4957ecb94 |
|
MD5 | c5ded104cef029e39491661eb1c33926 |
|
BLAKE2b-256 | 68d09d4d9132f64e4b914b69ba2db94a8e0401a711990cf3356185a32e9c47d0 |
Hashes for yapic.json-1.9.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96b96c7bdca8e24741b3345b37a64fc5e5ae3cd86517be8fffc72b47a85e56d0 |
|
MD5 | c7a6bcd2e364203b270715cf1de7aa74 |
|
BLAKE2b-256 | 431c97a576c8565fc2d99cace22e1b52327d65e94f21801df11a992689e99359 |
Hashes for yapic.json-1.9.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 056d0ac3b596d9ff401bf6c3a6aa0e4f98a9e3d1e1aa07597361406c9cc909d2 |
|
MD5 | 8d9c0801fe652a65de3e6e7eb17bbe07 |
|
BLAKE2b-256 | 722514e4859d1963e343c25f71eba0f84c7338cfe2d2119059536d12e1ae2c9f |