Apistar MessagePack Renderer and Parser pluggable components for Python 3.6+.
/usr/lib/python3.6/site-packages/apistar_msgpack.py
pip install apistar-msgpack
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.
Alternatively it also works with u-msgpack-python (Unofficial, Slower, Unsupported).
Optional:
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.