apistar-msgpack

Apistar MessagePack Renderer and Parser pluggable components.

GPL-3.0 License

Stars
5
Committers
1

apistar-msgpack

Apistar MessagePack Renderer and Parser pluggable components for Python 3.6+.

  • Change your Apistar App from JSON to MessagePack just adding 1 line.
  • Single file tiny module installs to /usr/lib/python3.6/site-packages/apistar_msgpack.py
  • 1 Dependency, the Official Python MessagePack Lib.

Install:

pip install apistar-msgpack

Usage:

Usage from settings:

from apistar_msgpack import MessagePackRenderer

settings = {'RENDERERS': (MessagePackRenderer(), )}

Alternatively we can specify the renderers to use on a specific handler function:

from apistar import annotate
from apistar_msgpack import MessagePackRenderer

@annotate(renderers=(MessagePackRenderer(), ))
def helloworld():
    return {'message': 'Hello World.'}  # Return a MessagePack.

The helloworld from Apistar Docs with MessagePackRenderer.

Parser usage:

from apistar_msgpack import MessagePackParser

settings = {'PARSERS': (MessagePackParser(), )}

Alternatively we can specify the parsers to use on a specific handler function:

from apistar import annotate
from apistar_msgpack import MessagePackParser

@annotate(parsers=(MessagePackParser(), ))
def helloworld():
    # Parses MessagePack, Return a Python dict, normal Python object types.

Requisites:

Alternatively it also works with u-msgpack-python (Unofficial, Slower, Unsupported).

Optional:

  • Optionally (not required) it also works with uJSON (Faster JSON load).

Notes:

Most of Databases and ORMs will have no problem storing MessagePack directly as strings UTF-8 (eg PostgreSQL).

We also look for other alternatives, like Smile which is Faster and Smaller, but Development is dead. Eg. its JavaScript Lib is incomplete and abandoned, No Python3 Lib, etc.