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
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
yapic.json.JsonError: base exception class
yapic.json.JsonEncodeError: exception class for encoding errors
yapic.json.JsonDecodeError: exception class for decoding errors
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” |
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.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5966d57ba4e11195eab27af8378caf2ce8b71ac910ec7d441e45c77127261dc6 |
|
MD5 | d5fa8b4936942fc81c1b1b08b6f055aa |
|
BLAKE2b-256 | cfe54132a872af7802bf99e0ba809d7d9d2f10d9609a9549b6936f698423c459 |
Hashes for yapic.json-1.5.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c783f7545030931353847e488ae72c18e64ac4b61eeba5dc25e22795e44b4d7f |
|
MD5 | c05d52856689480fe4dc7df8e93c9dbc |
|
BLAKE2b-256 | 13c479d7e67a840a7769d5ab28df58be10944e1bdc78315fb89de1ac01010930 |
Hashes for yapic.json-1.5.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8e11fef7862a0008087b9878eb30b0d09478a2763d122764159b0a879f90ed5 |
|
MD5 | 3137a7a91d6d902e54025873de95e417 |
|
BLAKE2b-256 | b7ab4fd68f9da0f9acab0f7ab32b46848dfba8d96ea816d8346cf672b46c997b |
Hashes for yapic.json-1.5.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e0e28a91e917bc18dee859ca89eb80b0c2b330259d7305ee76bb98542bbc784 |
|
MD5 | 54cb80a09b70d41c7ef27d4cf9f6d5e7 |
|
BLAKE2b-256 | 451b312215b7b5fb8037cdc2e1697fb32e0c9e373c81b38ed53530a55e519745 |
Hashes for yapic.json-1.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03b5a2c38c1dce46e8e1c97b35fb4e971ab5f67a6afcd3a9fb9d523c7c7f2589 |
|
MD5 | 8a31648091ce48ad4ce0d058441a8b55 |
|
BLAKE2b-256 | e30b7dc7ee2c79c2dfc72735c5998778556a24d59370b3fc6be84b008fab6600 |
Hashes for yapic.json-1.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a158b7842ef137b910ba881f4bd5d2baee35f0df26aee5d55f50876446619fe0 |
|
MD5 | b0450493f5524a3ede06cb749fff5d74 |
|
BLAKE2b-256 | 9e61e906d2638d436bbe139d0250d32a5fd666f0d77a5cb40c2fb86222c962d1 |
Hashes for yapic.json-1.5.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff2929910eec8842b69621b46304de211412b83e14be0a9add3266467b4fbfe |
|
MD5 | a75212fd9fc345ea2ba5770773ef774c |
|
BLAKE2b-256 | 198a84f7da2deb79cbe263523b697692cfa7e6ac783986ea0f51250cf707b0cc |
Hashes for yapic.json-1.5.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9295111c9ce2200368968c2941d685a00d11916ec388bfd8c61407853cf4c92 |
|
MD5 | 8381f9874f4eb3ae93642de43384cd76 |
|
BLAKE2b-256 | fe3b033117e33ed9f4c9681cd93b082f0cfc42762484114b4244e0d123d92ec7 |
Hashes for yapic.json-1.5.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4efe6f7dfe35498abaa022cf5ccc774cd14ad9dbfaf1c6f3f1d383b153669ebc |
|
MD5 | d702d167e6740794a22f70afd038f385 |
|
BLAKE2b-256 | be80de507150877a5e3075bb29309adbb5604f4b1cc1474ed1a484cab76c069a |
Hashes for yapic.json-1.5.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fa0c6b8a48e86e8af27807e7a2f96c0a6225d61c9fb2e83fc61362edb190cde |
|
MD5 | c72b212c8a8a3dc002b5cc9bb7d0d3d7 |
|
BLAKE2b-256 | c7e96a4875886ad68a9b704cea7148835ee3042abe42400c72db199676edeb14 |
Hashes for yapic.json-1.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee8746f2248ecf5de1b5d2915cac589f1d0faadabc615760e835a1d15b5059db |
|
MD5 | 30838f34c75fde538a7ef28e0ea3b229 |
|
BLAKE2b-256 | 83b7f5406221685b4e8ccba6b49c8c76a6a7d75985f4bf463af98dd8e2610f63 |
Hashes for yapic.json-1.5.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54fc97273684cabb622eb93e28432834a2ea1102f794ea3cdd205bc2c77a0580 |
|
MD5 | e880f37c074c2d54fe73ea2960ce0a48 |
|
BLAKE2b-256 | 74246acd2d3bbc088260d55ba9b56b329c5c0c4264219c79e15a89a9507b2328 |
Hashes for yapic.json-1.5.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb4df7261ca189f530cee187daab67bc0084ca21361e97bf1f761694665763e |
|
MD5 | 1cf99d6c1fbd50929d6bee8929b7fdb2 |
|
BLAKE2b-256 | f131e8d0fb88e1311a7ba5ec47d4def10dbea3968a6029040cc3f0654f64fdd4 |
Hashes for yapic.json-1.5.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368eeb87598beb078e9608af40cd8f6a415e2d5debfadc9664043d5fc16dc17e |
|
MD5 | ce0116341fa9773fb25e56131cd71158 |
|
BLAKE2b-256 | bf6e27ee2559235b60c9a69b87d3b457bab58d0e418ab0696bac2928e991b588 |
Hashes for yapic.json-1.5.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72a6332cae89ee975b1503a463610586fc9672c4ca9fae3b67eb55a97899f35d |
|
MD5 | c85626ad1b0eaae7253fdd831be2e471 |
|
BLAKE2b-256 | c19526db393cf49f55976d0b8774a4e019d5fc1b8e089cbc1d186448ba24e505 |
Hashes for yapic.json-1.5.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938a6890e4983ed0453c51bf6463fc56381617e5407e4def0687dde910ea99d5 |
|
MD5 | 588bf3fe7b2b9812a6026a664f89e63a |
|
BLAKE2b-256 | 098ef61d403dead6f446ccf6b9cc34ee63c2ee8ea5e2c0c885474b8a22aef6b3 |
Hashes for yapic.json-1.5.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0639776be375d278f217797d83adbd824544d0836d8d43efe877d8420360659b |
|
MD5 | 5cb1af8065b010923f0fd93686ac27bd |
|
BLAKE2b-256 | 546064cc99eab55916623fd879d171c511869ba7cfcd7220cebfa9e0da5b893a |
Hashes for yapic.json-1.5.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d51e9b37f8866ac97d7834cdbb4e0994c54a53a93b799c172c3b92501e20241 |
|
MD5 | 045b2f4a5c63af5b1de920b0e9bde5ae |
|
BLAKE2b-256 | 10ce57eb50a8cedb60e6f6ba551e9475070013dac1e0f6fd93972ceeee7ded91 |
Hashes for yapic.json-1.5.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3adf1f7255be13e532d578c88f9cdabde3fdb6f6100916473bf6c0cfbea240b7 |
|
MD5 | d56289ae7fb7c627eb0e5ef2a31073b0 |
|
BLAKE2b-256 | a657ceeb1218e6fc5cfcf9ac5929aeb593919b6385e9472a812cfe779076de18 |
Hashes for yapic.json-1.5.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94d68d64c7ce51ed5d74215cae447b4a0c5b0a9897b68c484b4e8a6790ab62ee |
|
MD5 | a709db67b90d86ce3ea5b4eb181d7abc |
|
BLAKE2b-256 | 234f2e2945b7be3c728ca4605020b140ce47ae7d2cd26fd860bf8f21a64bf8c7 |