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.10-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138d175fbadb784ea6838d141c817ae1ac2c6e84017f3d80c045575ab0d4a5cc |
|
MD5 | a0ad9a03e4a73faac6749ee57b2c96d3 |
|
BLAKE2b-256 | ba949ad463cb76482c908c76e3883350602d73dcd5686ce2109af3a25d013cad |
Hashes for yapic.json-1.8.10-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99df3f26656dab5f27fd32417105811853ab7b4ad22318e7e727c2891651ab8c |
|
MD5 | 70a8a59ab06f56a9d148f3ab428e7bb9 |
|
BLAKE2b-256 | c4535461d7acbcd2c5e0d5a28399e59041a8506eac6c6930bb19d6ed3f2750ed |
Hashes for yapic.json-1.8.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c5930278a0d00864f4dff3aa54b2bad285e820564959efb6599935de6bee46c |
|
MD5 | 245fc80f83bd58e0905ca4767a924e83 |
|
BLAKE2b-256 | 5bc84a11cc287940f6f1349f08f6c872dcb568a2ace61ed4de5d27558f9cfbd9 |
Hashes for yapic.json-1.8.10-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff3d5d6c665c4261f1baef0a64a93b2951cf590dfbe550e785c7d8e7d0ceaa87 |
|
MD5 | f67c2f5693de7c8276d94db0f812ade3 |
|
BLAKE2b-256 | b833bc7da27f325827eb9649b5e6674c09046097411a1b518fd95da328f09a3b |
Hashes for yapic.json-1.8.10-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4546d6850030a3ce870dc878486e7b271f9ccac2334b5c643a0d2dc5465bb936 |
|
MD5 | 28f52ac9d993e16a9ceba6f89c79236a |
|
BLAKE2b-256 | 4eed7edd159b028c852e132312d271d04b6c7c802938cc2971b7344621602384 |
Hashes for yapic.json-1.8.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7237078e8ef8643fc05b43e16a399ffdd2cd293a2ddcde2b4a0edf4d02b48d9 |
|
MD5 | 2edfaa79c55476adb6fe892ea3f70b8a |
|
BLAKE2b-256 | 809a42bf30ec4313da9daabd54f38f5d50ef16c96a604f2f3e5a5157fd4e7c9e |
Hashes for yapic.json-1.8.10-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a815fc839881d5d8c998c81dd8e18b24163c5d03512c27248f2aa769137cfb |
|
MD5 | 6109cc39f5e7eacf5a56cb5a0edbbb0f |
|
BLAKE2b-256 | 639f8f4d0e1663e461099a27b4fb783751678524293e46512faa5e740f634c11 |
Hashes for yapic.json-1.8.10-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92940f904ea40d4f932642af79bcd0495dccb47bc85706f8b5c10853127afbf |
|
MD5 | 54e9fd8044f56e06bc99f80acfe87609 |
|
BLAKE2b-256 | 8bb348bbe504ebcd7e8741a4631fb3046c3aa9e56eac7aa8b18f386a6e9f5ffb |
Hashes for yapic.json-1.8.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b38ac9da2490a06f2dba4a10bc53d677fddbb2886c9bc4d4949907060578e93 |
|
MD5 | c80d449f8f01193ea93bc545e2020e6e |
|
BLAKE2b-256 | b22851bc6e2f424ea8382dd48426d7c804ec3e17ce4362a34cde0bb2ce11907f |
Hashes for yapic.json-1.8.10-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a7deeffb772f121579b176c05910f40a7f59665bbc1b5cef61f32bd2e104c0a |
|
MD5 | 647958bc2a2fa699d139a23fcf52aaaa |
|
BLAKE2b-256 | b55a23879b44c54e3bfac484a64704a9d32798a1bd9348bb2d236839eb66f934 |
Hashes for yapic.json-1.8.10-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5436ba66390dff115794d85eee06480b200ccbdccd233b6ed190b4caaf149c3 |
|
MD5 | b7cda03c1a1732ae02dc70edbfb0d866 |
|
BLAKE2b-256 | 5d3e98051d6e9b63f347077b6587dd1f89997b8c648cc535e53b13061e901ed3 |
Hashes for yapic.json-1.8.10-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea058870c5905b63e5b4a79d599536e1319acd5de1ffbf667be91e107b673a27 |
|
MD5 | 3903a28156c38b954e6becf0bdb82f3e |
|
BLAKE2b-256 | ec442ff4f73b38b232bcb444d834a0cda55f7db7909e14522e66a4ff480ef0fc |
Hashes for yapic.json-1.8.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52c54509dc19f982a0b378b3147e5ca829e7e67c47ef37beb446ed650d735ff4 |
|
MD5 | 348fcf60a4eafce00cfcb5b7b7a3f2c4 |
|
BLAKE2b-256 | bbb5355992a7445abc9f286be5b299790c37dfd5b9642433c0dab912f75edd09 |
Hashes for yapic.json-1.8.10-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8984d83c786633bceabaf6ba9bb39656211413e38b540c538e87d0ee15306269 |
|
MD5 | acf6e6578f7dab6f7599aed2bbd1cc86 |
|
BLAKE2b-256 | 56876ef44ef51c38b15d9ef484847d5970410a35b2f9c7bdfff8a7a2f28bda43 |
Hashes for yapic.json-1.8.10-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354fb905c5e52f6d6ee02210837f545e771d49c70d6f90d6b631388cdff53bfb |
|
MD5 | f0c887aebd78f6bb06652d6a22061da6 |
|
BLAKE2b-256 | e179b2dbee7ccf264b1bd119cd42f9728b2d4db7a62785b6c40e4a0d125940c6 |
Hashes for yapic.json-1.8.10-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b5cde3305ae1575a0665514af9a236930cc67d432801bcd38c84194e6a5310 |
|
MD5 | f45e7f754a7cdcfd4ca564f03d00e3aa |
|
BLAKE2b-256 | 706cdf4d11f35aa6b85612a46e9246dbc14987077e03de100748f65ff18b8a39 |
Hashes for yapic.json-1.8.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2494853d69e47bfc930dd18becb0309ee4b1ab65e5668543ea20ff6df2b4911b |
|
MD5 | 4b607a2ed7aa288324bc92c81fe0fd3e |
|
BLAKE2b-256 | 2698b049451f2d720c39ea007f6c8553554a501446aa1c60895733bc7e5c38d9 |
Hashes for yapic.json-1.8.10-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5846b8f6b28da716ec2245b9a3d569ce1670f29ab2470621d366736b94623c9f |
|
MD5 | e8a6cbd63d5629a945c32db52876dd58 |
|
BLAKE2b-256 | 43b404be2171584dd9adcf69876a832378a67d801a023ab8b3e04f79df04ec22 |