• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

py_ubjson.egg-info/H03-May-2022-11791

src/H18-Apr-2020-2,7911,992

test/H18-Apr-2020-739523

ubjson/H18-Apr-2020-997683

CHANGELOGH A D18-Apr-20202 KiB6149

LICENSEH A D08-Sep-201811.1 KiB202169

MANIFEST.inH A D08-Sep-2018106 43

NOTICEH A D30-Nov-2019341 1510

PKG-INFOH A D18-Apr-20204.7 KiB11791

README.mdH A D30-Nov-20192.9 KiB8762

UBJSON-Specification.mdH A D08-Sep-201812.4 KiB377314

ez_setup.pyH A D08-Sep-201811.8 KiB416315

setup.cfgH A D18-Apr-202038 53

setup.pyH A D18-Apr-20204.2 KiB12085

README.md

1# Overview
2
3This is a Python v3.2+ (and 2.7+) [Universal Binary JSON](http://ubjson.org) encoder/decoder based on the [draft-12](UBJSON-Specification.md) specification.
4
5
6# Installing / packaging
7```shell
8# To get from PyPI
9pip3 install py-ubjson
10
11# To only build extension modules inline (e.g. in repository)
12python3 setup.py build_ext -i
13
14# To build & install globally
15python3 setup.py install
16
17# To skip building of extensions when installing (or building)
18PYUBJSON_NO_EXTENSION=1 python3 setup.py install
19```
20**Notes**
21
22- The extension module is not required but provide a significant speed boost.
23- The above can also be run with v2.7+
24- This module is also available via [Anaconda (conda-forge)](https://anaconda.org/conda-forge/py-ubjson)
25- PyPI releases are signed with the [Iotic Labs Software release signing key](https://developer.iotic-labs.com/iotic-labs.com.asc)
26- At run time, one can check whether compiled version is in use via the _ubjson.EXTENSION_ENABLED_ boolean
27
28
29# Usage
30It's meant to behave very much like Python's built-in [JSON module](https://docs.python.org/3/library/json.html), e.g.:
31```python
32import ubjson
33
34encoded = ubjson.dumpb({u'a': 1})
35
36decoded = ubjson.loadb(encoded)
37```
38**Note**: Only unicode strings in Python 2 will be encoded as strings, plain *str* will be encoded as a byte array.
39
40
41# Documentation
42```python
43import ubsjon
44help(ubjson.dump)
45help(ubjson.load)
46```
47
48# Command-line utility
49This converts between JSON and UBJSON formats:
50```shell
51python3 -mubjson
52USAGE: ubjson (fromjson|tojson) (INFILE|-) [OUTFILE]
53```
54
55
56# Tests
57
58## Static
59This library has been checked using [flake8](https://pypi.python.org/pypi/flake8) and [pylint](http://www.pylint.org), using a modified configuration - see _pylint.rc_ and _flake8.cfg_.
60
61## Unit
62```shell
63python3 -mvenv py
64. py/bin/activate
65pip install -U pip setuptools
66pip install -e .[dev]
67
68./coverage_test.sh
69```
70**Note**: See `coverage_test.sh` for additional requirements.
71
72
73# Limitations
74- The **No-Op** type is only supported by the decoder. (This should arguably be a protocol-level rather than serialisation-level option.) Specifically, it is **only** allowed to occur at the start or between elements of a container and **only** inside un-typed containers. (In a typed container it is impossible to tell the difference between an encoded element and a No-Op.)
75- Strongly-typed containers are only supported by the decoder (apart from for **bytes**/**bytearray**) and not for No-Op.
76- Encoder/decoder extensions are not supported at this time.
77
78
79# Why?
80The only existing implementation I was aware of at the time of writing ([simpleubjson](https://github.com/brainwater/simpleubjson)) had the following limitations:
81
82- Does not support efficient binary encoding
83- Only supports draft-9
84- Only supports individual Python types rather than anything implementing an interface (e.g. _Mapping_)
85- Does not decode nested arrays or objects in expected form
86- Lacks C extension speed-up
87