Skip to main content

Simple universal binary json decoder/encoder for Python.

Project description

Simple UBJSON in Python

UBJSON[1] is the universally compatible format specification for binary JSON[2]. It’s pretty and simple data format and simpleubjson aims to be also the same:

>>> import simpleubjson
>>> ubjdata = simpleubjson.encode({'hello': 'world', 'тест': [1, 2, 3]})
>>> ubjdata
b'o\x02s\x05hellos\x05worlds\x08\xd1\x82\xd0\xb5\xd1\x81\xd1\x82a\x03B\x01B\x02B\x03'

simpleubjson.encode function transforms Python objects into UBJSON binary string data. To decode it back to Python objects use simpleubjson.decode function:

>>> simpleubjson.decode(ubjdata)
{'hello': 'world', 'тест': [1, 2, 3]}

Moreover, you may also introspect UBJSON data via simpleubjson.pprint function:

>>> simpleubjson.pprint(ubjdata)
[o] [2]
  [s] [5] [hello]
  [s] [5] [world]
  [s] [8] [тест]
  [a] [3]
      [B] [1]
      [B] [2]
      [B] [3]

This representation is a bit more human friendly than traditional hexview and designed specially for UBJSON format.

Currently simpleubjson follows Draft-8 specification by default, but you already may use Draft-9 version by passing spec="draft-9" argument for decode, encode and pprint functions. Please check breaking changes[3] before switching to it.

Changes

0.6.1 (2013-04-29)

  • Fix compatibility with Python 3.x;

  • Force binary strings have utf-8 charset on encoding;

  • Improve UBJSON decoding performance;

0.6.0 (2013-04-10)

  • Project refactoring and code cleanup;

  • Raise overall performance for 100-400% times depending on test case;

  • Update Draft-9 support to RC state: handle new containers markers;

0.5.0 (2012-07-07)

  • Fix encoding of unsized objects;

  • Fix pprinting containers with NoOp markers;

  • Fix markers of integers values for Draft-9 spec;

0.4.0 (2012-06-29)

  • Encode set and frozenset types;

  • Experimental implementation of Draft-9 specification;

  • Fix encoding of dict iterators;

  • Support Python 3.x;

0.3.0 (2012-03-03)

  • Add simpleubjson.pprint function to dump UBJSON data using [ ]-notation;

  • Allow decode standalone NoOp values;

  • Encode inf and -inf values as null;

  • Remove support of custom markers and handlers;

  • Wrap HUGE values with Decimal class and encode Decimal instances back to HUGE;

0.2.0 (2011-11-30)

  • Allow decoder produce NoOp values;

  • Allow to specify custom decoding/encoding handlers;

  • Fix float/double values handling;

0.1.0 (2011-10-13)

  • First version with support Draft-8 specification.

Project details


Download files

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

Source Distribution

simpleubjson-0.6.1.tar.gz (30.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page