https://github.com/juancarlospaco/apistar-msgpack
Apistar MessagePack Renderer and Parser pluggable components.
https://github.com/juancarlospaco/apistar-msgpack
Last synced: 4 months ago
JSON representation
Apistar MessagePack Renderer and Parser pluggable components.
- Host: GitHub
- URL: https://github.com/juancarlospaco/apistar-msgpack
- Owner: juancarlospaco
- License: gpl-3.0
- Created: 2017-11-07T02:43:07.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-20T05:43:11.000Z (almost 8 years ago)
- Last Synced: 2025-04-12T00:43:13.241Z (6 months ago)
- Language: Python
- Homepage:
- Size: 30.3 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
# apistar-msgpack
[Apistar](https://github.com/encode/apistar) [MessagePack](https://msgpack.org) 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`:
```python
from apistar_msgpack import MessagePackRenderersettings = {'RENDERERS': (MessagePackRenderer(), )}
```Alternatively we can specify the renderers to use on a specific handler function:
```python
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.](https://github.com/juancarlospaco/apistar-msgpack/blob/master/app.py)
Parser usage:
```python
from apistar_msgpack import MessagePackParsersettings = {'PARSERS': (MessagePackParser(), )}
```Alternatively we can specify the parsers to use on a specific handler function:
```python
from apistar import annotate
from apistar_msgpack import MessagePackParser@annotate(parsers=(MessagePackParser(), ))
def helloworld():
# Parses MessagePack, Return a Python dict, normal Python object types.
```- See [Apistar Docs for more info.](https://github.com/encode/apistar#configuring-the-installed-renderers)
### Requisites:
- [msgpack-python](https://github.com/msgpack/msgpack-python) Official Python MessagePack Lib.
Alternatively it also works with [u-msgpack-python](https://github.com/vsergeev/u-msgpack-python) (Unofficial, Slower, Unsupported).
**Optional:**
- Optionally (not required) it also works with [uJSON](https://github.com/esnme/ultrajson#ultrajson) (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](https://github.com/FasterXML/smile-format-specification) which is Faster and Smaller, but Development is dead.
Eg. its JavaScript Lib is incomplete and abandoned, No Python3 Lib, etc.