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 |
{…} |
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.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cdc05edd40069ca7636ba76b72064d97a99b988fd5096929be6e626888712b6 |
|
MD5 | 8a0b181316612f5a13c068c7c93022d0 |
|
BLAKE2b-256 | 1dfbfd630be5de2ff4ffc9fb01bd71fe26b14033810a802e19439cb8240ebfc6 |
Hashes for yapic.json-1.8.3-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7903c6d1fed7469960b5773800dcbdc400a34ffe2f309f42ccbef1ba799ff7fe |
|
MD5 | 0211c989d0e8673c83c7ec54b6bac663 |
|
BLAKE2b-256 | 57186d3c9e80293f788f9ea1ee90ba3c25169cf55e4f5171eb22d65bd0f3e2c1 |
Hashes for yapic.json-1.8.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae560a25f8d1b352af42f35f592257592d526d5fe194ec4f5adfb36043fcb586 |
|
MD5 | cef8c5face2ebf501301f4d8d527a0bd |
|
BLAKE2b-256 | eb704192d18949dc2fe1c5bacf7cb8808fa84f5c2f15daa54eff353a33a7b63a |
Hashes for yapic.json-1.8.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a28c65184418a1dd8a022e7ff1a88233fd0595f96ae567ea49d83df76e82026e |
|
MD5 | b61309b0818b0221a954ad47b009b759 |
|
BLAKE2b-256 | 1e4ce6f999b19888a2e07f386f1cdde8be741d229062ea524cd22483c1007c5d |
Hashes for yapic.json-1.8.3-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae8e9e23fa888077774f4e9427681ba342a27571ad43150506d6aee0d57c5010 |
|
MD5 | e112b5465b93ce0084aea30b7bf1758e |
|
BLAKE2b-256 | 575f3d59c90654977be87b9a5efae836466a760547ef4ae7bac5538555f15d87 |
Hashes for yapic.json-1.8.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2a055bc1e6a5475d68eb352212ae5e9132790bea06eddaacd41a4a98c158758 |
|
MD5 | 99578b6de95af044f2c880f14b4c3b35 |
|
BLAKE2b-256 | 14c460f7c4c7257283d0e88e27d505b16eeb8bdae7d5dbc682b449387a8f4396 |
Hashes for yapic.json-1.8.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca9664616486f4ba060e9e9ac497892d35acead2caffddd5bcae5289862063e |
|
MD5 | 8fe5e86983f3c28fd110ee561bb923c3 |
|
BLAKE2b-256 | 9ba686819e1c17e2d279f0cd091ce13e42d60591295f523df0f5cf963cccb5d9 |
Hashes for yapic.json-1.8.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e74265bcce64075f7d198178b3857e4cd16b5fc101562d4b24cee3951e4873b2 |
|
MD5 | b1295776a2dc0f4e2a8e10584aa26489 |
|
BLAKE2b-256 | 91638ea140c4c47ace7dda95dcfb69fbf30a69c74197dd8b2b368eb079bdb8fc |
Hashes for yapic.json-1.8.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd5954cb3d48c2b5c3e933d9dc58cb22375717a92a0718c2446412e97f4b3189 |
|
MD5 | b0c71ffca3666be3e290849f398cfbdf |
|
BLAKE2b-256 | a53056d9cdabc07368c0deac0cbf9f63b52e1a86a8013ac345ce6994b292e1d5 |
Hashes for yapic.json-1.8.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd25f77f0dfad63fe96ce5ce27cece660e988f16f78e0e3db1529fe38133c8e4 |
|
MD5 | d4dd794b045e1bb4fcc0fe5b8b0bb211 |
|
BLAKE2b-256 | 297dcbb8a24c939968288d0f7e8f3be49b98cd568dc683cd7ccf6961064e8693 |
Hashes for yapic.json-1.8.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aac4f35b23ee6bffe6fff423859b6067a59842c460739c64678fbd32cfd9e0f |
|
MD5 | 8b23f865ed0e0fca21765421244ddbdc |
|
BLAKE2b-256 | 11114743038d73d0116ae645ec6430bdc916ee0143de70fe40f251821073b2aa |
Hashes for yapic.json-1.8.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dfa2e7b807502f9d596e74fd02d006dd9635966a33624d04c058875d9ccc2bd |
|
MD5 | 246654d03d679fc2a1bc4b68b3e83b6b |
|
BLAKE2b-256 | 142c4507fa7b0d6ded6b73eb134036e7db8bbd80adb30f27844311e17226872a |
Hashes for yapic.json-1.8.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2da3c140893b319a981b0379e75d26849ce00866fb74279e026a47a4fae419aa |
|
MD5 | 2af0d6c91eaa9c0f662dfcff9b411c9a |
|
BLAKE2b-256 | 22b5465ef945a5214382aa07252e753a78a2c543a666d38bef40cfea0326c23e |
Hashes for yapic.json-1.8.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7f214de11be5d6f42c8836ebfb7d98b4c57f4b90622c0059f42c965fb588217 |
|
MD5 | 6f2029fe15fe5d33f5353f205f4145a8 |
|
BLAKE2b-256 | 6f018ea862379f6ed338f57ab601885e070472eb1f286257fe3c9e1f86c42c8f |
Hashes for yapic.json-1.8.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9c03a1949c6dd86cbe859f0c3d198cb6a16832669dffe12ede6bf87bdd3b48 |
|
MD5 | da762e8f644f80866d275d95ffeeb216 |
|
BLAKE2b-256 | 0bccea7f36adc43c0685039cd59d58cfa7de603cd5150b2c6dcb1e7e2f0c66cc |
Hashes for yapic.json-1.8.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3967a98f1638fc558c0c364920301d04afc3957b83f6d8b84a3b4bb83528b74 |
|
MD5 | 8950351ba82e6080772e1e4fbca472bb |
|
BLAKE2b-256 | 487ffa06ad7c2522aa48295cddba8375dad53d0f2249b9852f9fe9cb992bf137 |
Hashes for yapic.json-1.8.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22e3af1d108d3097a88ba3e2ba77b230b9caa6de77f68c7e0af2802078ca48e4 |
|
MD5 | 07249177587fa4a04a2cb131bad3b1da |
|
BLAKE2b-256 | 7ef1cf4303bd29f957d82d39afaea8ad02bb3830d98eb73027e07f53a0f38aad |
Hashes for yapic.json-1.8.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da907d86397367d08fc2b8e5a52978de0b241748d3c25a6ec20ebca32a17544a |
|
MD5 | b42c102e4512416e167ce3398de1cc3d |
|
BLAKE2b-256 | 80b78c66de6795e94f2332ab631d0b7f8a1be48c83954e7b2632495919a1dc56 |
Hashes for yapic.json-1.8.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cae0b219b895f5f9d6e244d2a4f57d0985746525504588dc6dff25dfdc02c85b |
|
MD5 | 4590e810e4973ffbf4b32639b0eb222d |
|
BLAKE2b-256 | 4668825b86df4e7a329afe0715f9681bdeac79f61a1c08343478d87a0ebbfd30 |
Hashes for yapic.json-1.8.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 319d3d7d35c384291a94edac7d39449ce986b70b5eb47cf3bdc0583c1e59701f |
|
MD5 | 38c5b17350fdf81600c349ec5bd0325a |
|
BLAKE2b-256 | f129afee5abf85ad4e27e9693fd35e526b0bc4085db5a213fdb4aaf46ebaa9e1 |
Hashes for yapic.json-1.8.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce1518addb3c2e794174b68e9e5f9d9e92ba9240c1ca1ef866e673819806511d |
|
MD5 | 38cf532efdffe4f56a57d410f8c43eb7 |
|
BLAKE2b-256 | e5b868d26e406576b21c6c8b512db1d5666d55bca2c9f63b6f256babf93e0c3c |
Hashes for yapic.json-1.8.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d7d2768f43f2559ea1f8479ce4271b443dd63e6b3b5e93eb8165f86892edfd |
|
MD5 | cd595c2cc6040f7836de553a9022729e |
|
BLAKE2b-256 | 39ee28ff507f10d4ede0950ccf0402c9ce7cc4bd2422fc27953cb957375ec72d |