Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Fastest JSON encode / decode library.

Project description

AppVeyor CircleCI Travis PyPI - Downloads

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 ‘/test/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

  • 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

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)

    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}'
    

Exceptions

  • yapic.json.JsonError: base exception class
  • yapic.json.JsonEncodeError: exception class for encoding errors
  • yapic.json.JsonDecodeError: exception class for decoding errors

Release Process

  • change VERSION in setup.py
  • git add setup.py
  • git commit -m "chore(bump): VERSION"
  • git checkout release
  • git merge master
  • git tag -a VERSION -m "chore(bump): VERSION"
  • git push && git push --tags
  • git checkout master
  • git merge release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for yapic.json, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size yapic.json-1.2.1-cp35-cp35m-manylinux1_i686.whl (361.1 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp35-cp35m-manylinux1_x86_64.whl (379.8 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp35-cp35m-win32.whl (52.6 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp35-cp35m-win_amd64.whl (63.8 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp36-cp36m-manylinux1_i686.whl (360.8 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp36-cp36m-manylinux1_x86_64.whl (374.7 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp36-cp36m-win32.whl (53.4 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp36-cp36m-win_amd64.whl (60.1 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp37-cp37m-manylinux1_i686.whl (361.1 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp37-cp37m-manylinux1_x86_64.whl (376.9 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp37-cp37m-win32.whl (53.4 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1-cp37-cp37m-win_amd64.whl (60.1 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size yapic.json-1.2.1.tar.gz (97.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page