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.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f2da14318784c7f994032c30ed8e23b610015fda5a9ce3b872d71b24ba0b8a3 |
|
MD5 | 7d260c1b71a4d99407e703fed8593112 |
|
BLAKE2b-256 | 268d56e6e9756295f057dd47949c186f013c69f506445b63447ae2742226ecc4 |
Hashes for yapic.json-1.5.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57072721f5665025d6e26d9ac45ba1b4cfeeeb57e74940cc76fca6b24591477d |
|
MD5 | 1e8e28c784710bf2d7e7b4df4d38c3ca |
|
BLAKE2b-256 | fe94d5131bcfc8c0a9c7245c4079f92cc4f3155581ac12b0b84b054173c8f7f3 |
Hashes for yapic.json-1.5.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b5fdd18c3d5725fc8e36959a0e518200f07fb696b52662c61cbe0d0235b676c |
|
MD5 | 694bafd1d870219ab8cc695de608c9f6 |
|
BLAKE2b-256 | b73bc51b62265fa076be4ef3c83ae28c38c9dd78bc4ac121c225c99d898b9775 |
Hashes for yapic.json-1.5.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 058f06d3cf8dfbcceb2f999b1a4590be230afb843d442011ecb6770b619280d7 |
|
MD5 | 7bf893c13620ebcb73aae71e764ef94f |
|
BLAKE2b-256 | 7813ce52bf4ab8b03a824eed69d868560fac043b06149f7ad82669deed408d98 |
Hashes for yapic.json-1.5.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c47f6560639466565a9ff213d068592dd150fbd7906a612ca467f9403e375065 |
|
MD5 | 4c8f5c035a86add2db08fbaf1fee3dcb |
|
BLAKE2b-256 | 80f19a4d9f8b08aa92b2cac0250c98199ce0f2677cb5370a98e06280f0e729c2 |
Hashes for yapic.json-1.5.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b766986ce831eb41e66799922481cfcf77d9c9bb54a9966cbc36987fa5bbfca |
|
MD5 | d87c51843ea7e2f80bae605855c98b80 |
|
BLAKE2b-256 | 323e6f3c9af023659c632d13dd35ae6b31ad67ac8930d48abede84ddce13a1a7 |
Hashes for yapic.json-1.5.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ade4100d0d9b7c447f35c1b9afaf34b476b2426ae5083af5a0b4f9ec2536192 |
|
MD5 | 55934cbe4e4014da2a8a6e4325681161 |
|
BLAKE2b-256 | 5d2147774e55b722303c695f8998b1afa0d0cf99507cd90bf3086de535523bf8 |
Hashes for yapic.json-1.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e81768e81707916dad0644704cb041d22ee0f61c664be634672bce53758b5fea |
|
MD5 | 8422c8f7463d87b77412fc7953b3d398 |
|
BLAKE2b-256 | af9b8bfb88d74a8ebf9fb7bc8ec2f8f57541296e583fd58f564cd7b69c211586 |
Hashes for yapic.json-1.5.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ac757cfd39bfe205663df3bc8f133b8149637937378e4c3a7f9469241620558 |
|
MD5 | decb29247acb5b55b97626db3333bf7a |
|
BLAKE2b-256 | 0d57fea1cc21e00febde2898098b566c0bb1b9ee17e83095e34aba7b74c0c3db |
Hashes for yapic.json-1.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4314f668c42bafe6766515a20d37e98ea359040c55ee2aacc49cbbe9220700de |
|
MD5 | 904f1a353b8ce9cb17a0250ed3640199 |
|
BLAKE2b-256 | 0d979783386611d595db47e7165ec9e1c11acc4a252202cdaa6211fba5eedc13 |
Hashes for yapic.json-1.5.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae43f5bf6583494a946c05e130e771c3d28fb8e0980b8b1d5ceef248f266244 |
|
MD5 | 89630ed47cf0a715b38fcea5e44a49cb |
|
BLAKE2b-256 | 6ca456d425740cca3a076817d1bfc6d26ef92b2bbd1eff3e8781d15fb64ac787 |
Hashes for yapic.json-1.5.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3833c7d54e527809f996c043289b1e167a6a3b42c9fc502f2113916b8b2e384 |
|
MD5 | 1ad7c0b0e3f9298809ab9c35aaffd10e |
|
BLAKE2b-256 | 22873a68d046fef715815334329e58619c433a73a149acf1506ecf96a28b6708 |
Hashes for yapic.json-1.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 143c31e077da31fb608b0454738200b3a982e7da166c778874a75a158fd5ef9c |
|
MD5 | 606c291c126bc42b5793a0910be817d4 |
|
BLAKE2b-256 | 080c685d01eeb5acd1b581b81d0ad22cafdb479ce2c59c668fca414329cb585b |
Hashes for yapic.json-1.5.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fee329dae925fa71d05e0d64a2e0985db1c1e0f1cf0b478de1666ace5e642714 |
|
MD5 | e5ed07af6556d6788ab634f256a5cff8 |
|
BLAKE2b-256 | 731d27738371914a0f1da794d2904b7d6f42d7fc973a349039af83f6f3956a14 |
Hashes for yapic.json-1.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c9335a00805ea18ba0d8b5fa8acb3eae25cbb524305becf85df673dfd5befd |
|
MD5 | 65bed77bbf3f3a065a49c3ece31189af |
|
BLAKE2b-256 | cae2ba03f43e965f91dc09a611cba6f5f92d8fce8791fa94bdabb1acba34fe85 |
Hashes for yapic.json-1.5.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5316cc636f2f7f72e2bb64a5a77161ab4611c70bd9cfd06327e9cd88218a34d |
|
MD5 | 919d790f3182416fc029cf62605dfcba |
|
BLAKE2b-256 | c1d6828b0162115f8ac90f2c6dd3289834c99f39da73044a47ab9eb0c33a4314 |
Hashes for yapic.json-1.5.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4f1879725a3433bfd44db57bc77588135156088bc48bfbfdaa46b8afc178116 |
|
MD5 | f60c158a78d162427c249c03be7b3503 |
|
BLAKE2b-256 | caee4a2ad05ea9beb1ef8080ac2c128d04423a63bb1d5df8c7c30c7d2e983d8f |
Hashes for yapic.json-1.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7b4832919bcdeb7046b62c150c6b837489b5161310e7b7df22d238b5850c92 |
|
MD5 | f1dc4c8646c9d61a7a5fcb8bff05d15d |
|
BLAKE2b-256 | 755a76ce2b9ab2c1a0050993b65f7a78a730217c530986120301e2964fa1b953 |
Hashes for yapic.json-1.5.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ba09d27c14bc4508b6b79d64f6d3ef800c9c1fb1a959a3f9523b592509d6794 |
|
MD5 | 4e57b45a4aaf110e3ba3b7ed4c81993b |
|
BLAKE2b-256 | 4c837b3dac5b525b28c3429c43865cf02e18d8522ea6c3c8dd615b2908bc1065 |
Hashes for yapic.json-1.5.1-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e69523a26688427b6b7d900af460cbf59c3215934551906a5d87b3cd9566ce77 |
|
MD5 | 6636ef9282bc43cc011f15a8d0b3d1b0 |
|
BLAKE2b-256 | de77979613ec0fce7792161426b1af373b9c53c1c3855afcdf646baaa4f92331 |