msgpack-python
MessagePack serializer implementation for Python msgpack.org[Python]
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
3 of 80 committers (3.8%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.8%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
MessagePack serializer implementation for Python msgpack.org[Python]
Basic Info
- Host: GitHub
- Owner: msgpack
- License: other
- Language: Python
- Default Branch: main
- Homepage: https://msgpack.org/
- Size: 2.94 MB
Statistics
- Stars: 2,009
- Watchers: 46
- Forks: 228
- Open Issues: 5
- Releases: 24
Topics
Metadata Files
README.md
MessagePack for Python
What's this
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. This package provides CPython bindings for reading and writing MessagePack data.
Install
$ pip install msgpack
Pure Python implementation
The extension module in msgpack (msgpack._cmsgpack) does not support PyPy.
But msgpack provides a pure Python implementation (msgpack.fallback) for PyPy.
Windows
When you can't use a binary distribution, you need to install Visual Studio or Windows SDK on Windows. Without extension, using pure Python implementation on CPython runs slowly.
How to use
One-shot pack & unpack
Use packb for packing and unpackb for unpacking.
msgpack provides dumps and loads as an alias for compatibility with
json and pickle.
pack and dump packs to a file-like object.
unpack and load unpacks from a file-like object.
```pycon
import msgpack msgpack.packb([1, 2, 3]) '\x93\x01\x02\x03' msgpack.unpackb(_) [1, 2, 3] ```
Read the docstring for options.
Streaming unpacking
Unpacker is a "streaming unpacker". It unpacks multiple objects from one
stream (or from bytes provided through its feed method).
```py import msgpack from io import BytesIO
buf = BytesIO() for i in range(100): buf.write(msgpack.packb(i))
buf.seek(0)
unpacker = msgpack.Unpacker(buf) for unpacked in unpacker: print(unpacked) ```
Packing/unpacking of custom data type
It is also possible to pack/unpack custom data types. Here is an example for
datetime.datetime.
```py import datetime import msgpack
useful_dict = { "id": 1, "created": datetime.datetime.now(), }
def decodedatetime(obj): if 'datetime' in obj: obj = datetime.datetime.strptime(obj["asstr"], "%Y%m%dT%H:%M:%S.%f") return obj
def encodedatetime(obj): if isinstance(obj, datetime.datetime): return {'datetime': True, 'asstr': obj.strftime("%Y%m%dT%H:%M:%S.%f")} return obj
packeddict = msgpack.packb(usefuldict, default=encodedatetime) thisdictagain = msgpack.unpackb(packeddict, objecthook=decodedatetime) ```
Unpacker's object_hook callback receives a dict; the
object_pairs_hook callback may instead be used to receive a list of
key-value pairs.
NOTE: msgpack can encode datetime with tzinfo into standard ext type for now.
See datetime option in Packer docstring.
Extended types
It is also possible to pack/unpack custom data types using the ext type.
```pycon
import msgpack import array def default(obj): ... if isinstance(obj, array.array) and obj.typecode == 'd': ... return msgpack.ExtType(42, obj.tostring()) ... raise TypeError("Unknown type: %r" % (obj,)) ... def exthook(code, data): ... if code == 42: ... a = array.array('d') ... a.fromstring(data) ... return a ... return ExtType(code, data) ... data = array.array('d', [1.2, 3.4]) packed = msgpack.packb(data, default=default) unpacked = msgpack.unpackb(packed, exthook=ext_hook) data == unpacked True ```
Advanced unpacking control
As an alternative to iteration, Unpacker objects provide unpack,
skip, read_array_header and read_map_header methods. The former two
read an entire message from the stream, respectively de-serialising and returning
the result, or ignoring it. The latter two methods return the number of elements
in the upcoming container, so that each element in an array, or key-value pair
in a map, can be unpacked or skipped individually.
Notes
string and binary type in old msgpack spec
Early versions of msgpack didn't distinguish string and binary types. The type for representing both string and binary types was named raw.
You can pack into and unpack from this old spec using use_bin_type=False
and raw=True options.
```pycon
import msgpack msgpack.unpackb(msgpack.packb([b'spam', 'eggs'], usebintype=False), raw=True) [b'spam', b'eggs'] msgpack.unpackb(msgpack.packb([b'spam', 'eggs'], usebintype=True), raw=False) [b'spam', 'eggs'] ```
ext type
To use the ext type, pass msgpack.ExtType object to packer.
```pycon
import msgpack packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy')) msgpack.unpackb(packed) ExtType(code=42, data='xyzzy') ```
You can use it with default and ext_hook. See below.
Security
To unpacking data received from unreliable source, msgpack provides two security options.
max_buffer_size (default: 100*1024*1024) limits the internal buffer size.
It is used to limit the preallocated list size too.
strict_map_key (default: True) limits the type of map keys to bytes and str.
While msgpack spec doesn't limit the types of the map keys,
there is a risk of the hashdos.
If you need to support other types for map keys, use strict_map_key=False.
Performance tips
CPython's GC starts when growing allocated object.
This means unpacking may cause useless GC.
You can use gc.disable() when unpacking large message.
List is the default sequence type of Python.
But tuple is lighter than list.
You can use use_list=False while unpacking when performance is important.
Major breaking changes in the history
msgpack 0.5
Package name on PyPI was changed from msgpack-python to msgpack from 0.5.
When upgrading from msgpack-0.4 or earlier, do pip uninstall msgpack-python before
pip install -U msgpack.
msgpack 1.0
Python 2 support
- The extension module does not support Python 2 anymore.
The pure Python implementation (
msgpack.fallback) is used for Python 2. - msgpack 1.0.6 drops official support of Python 2.7, as pip and GitHub Action (setup-python) no longer support Python 2.7.
- The extension module does not support Python 2 anymore.
The pure Python implementation (
Packer
- Packer uses
use_bin_type=Trueby default. Bytes are encoded in bin type in msgpack. - The
encodingoption is removed. UTF-8 is used always.
- Packer uses
Unpacker
- Unpacker uses
raw=Falseby default. It assumes str types are valid UTF-8 string and decode them to Python str (unicode) object. encodingoption is removed. You can useraw=Trueto support old format (e.g. unpack into bytes, not str).- Default value of
max_buffer_sizeis changed from 0 to 100 MiB to avoid DoS attack. You need to passmax_buffer_size=0if you have large but safe data. - Default value of
strict_map_keyis changed to True to avoid hashdos. You need to passstrict_map_key=Falseif you have data which contain map keys which type is not bytes or str.
- Unpacker uses
Owner
- Name: MessagePack
- Login: msgpack
- Kind: organization
- Website: http://msgpack.org/
- Repositories: 22
- Profile: https://github.com/msgpack
GitHub Events
Total
- Create event: 5
- Release event: 2
- Issues event: 14
- Watch event: 92
- Delete event: 3
- Issue comment event: 27
- Push event: 13
- Pull request review event: 15
- Pull request review comment event: 13
- Pull request event: 8
- Fork event: 5
Last Year
- Create event: 5
- Release event: 2
- Issues event: 14
- Watch event: 92
- Delete event: 3
- Issue comment event: 27
- Push event: 13
- Pull request review event: 15
- Pull request review comment event: 13
- Pull request event: 8
- Fork event: 5
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| INADA Naoki | s****y@g****m | 541 |
| Naoki INADA | i****n@e****e | 24 |
| Bas Westerbaan | b****s@w****e | 23 |
| Joel Nothman | j****n@g****m | 19 |
| Naoki INADA | i****n@k****p | 17 |
| Naoki INADA | i****n@g****r | 13 |
| Antonio Cuni | a****i@g****m | 12 |
| folz | j****z@d****e | 9 |
| YAMAMOTO Takashi | y****t@m****p | 7 |
| TW | tw@w****e | 7 |
| Alexei Romanoff | d****y@g****m | 5 |
| Naoki INADA | i****n@k****a | 5 |
| Omer Katz | o****w@g****m | 4 |
| Hugo | h****k | 4 |
| Andrey Bienkowski | h****n@g****m | 4 |
| palaviv | p****v@g****m | 4 |
| Steeve Morin | s****n@g****m | 4 |
| Pramukta Kumar | p****r@g****m | 3 |
| Spiros Eliopoulos | s****u@g****m | 3 |
| inada-n | o****e@u****p | 3 |
| Alex Willmer | a****x@m****k | 3 |
| Sadayuki Furuhashi | f****i@g****m | 2 |
| Alex Gaynor | a****r@g****m | 2 |
| Keiji Muraishi | k****i@g****m | 2 |
| Marc Abramowitz | m****c@m****m | 2 |
| Marty B | m****4@g****m | 2 |
| Peter Fischer | y****d | 2 |
| Wouter Bolsterlee | u****s@x****l | 2 |
| Alexey Popravka | a****a@l****m | 2 |
| Naoki INADA | o****e@s****p | 2 |
| and 50 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 96
- Total pull requests: 95
- Average time to close issues: 3 months
- Average time to close pull requests: about 2 months
- Total issue authors: 82
- Total pull request authors: 33
- Average comments per issue: 3.42
- Average comments per pull request: 1.16
- Merged pull requests: 77
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 12
- Pull requests: 10
- Average time to close issues: 23 days
- Average time to close pull requests: 1 day
- Issue authors: 12
- Pull request authors: 4
- Average comments per issue: 2.0
- Average comments per pull request: 0.7
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- methane (5)
- ThomasWaldmann (5)
- clin1234 (2)
- ZhouJiaZhi (2)
- edgimar (2)
- yurivict (2)
- rspeer (2)
- uyha (1)
- danpprince (1)
- caniko (1)
- JackStouffer (1)
- HanlinGao (1)
- sblondon (1)
- fabaff (1)
- cykerway (1)
Pull Request Authors
- methane (74)
- hexagonrecursion (8)
- ThomasWaldmann (4)
- clin1234 (3)
- kloczek (2)
- rtobar (2)
- hakanakyurek (2)
- edgarrmondragon (2)
- hauntsaninja (2)
- tacaswell (2)
- Aman-Clement (2)
- begelundmuller (1)
- vladima (1)
- fried (1)
- jensbjorgensen (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 4
-
Total downloads:
- pypi 140,171,111 last-month
- Total docker downloads: 2,526,930,332
-
Total dependent packages: 839
(may contain duplicates) -
Total dependent repositories: 28,971
(may contain duplicates) - Total versions: 66
- Total maintainers: 1
pypi.org: msgpack
MessagePack serializer
- Homepage: https://msgpack.org/
- Documentation: https://msgpack-python.readthedocs.io/
- License: Apache 2.0
-
Latest release: 1.1.1
published 8 months ago
Rankings
Maintainers (1)
conda-forge.org: msgpack-python
- Homepage: http://msgpack.org/
- License: Apache-2.0
-
Latest release: 1.0.4
published over 3 years ago
Rankings
proxy.golang.org: github.com/msgpack/msgpack-python
- Documentation: https://pkg.go.dev/github.com/msgpack/msgpack-python#section-documentation
- License: other
-
Latest release: v1.1.1
published 8 months ago
Rankings
anaconda.org: msgpack-python
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
- Homepage: https://msgpack.org
- License: Apache-2.0
-
Latest release: 1.1.1
published 8 months ago
Rankings
Dependencies
- Cython *
- black ==22.3.0
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v3 composite
- actions/setup-python v3 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v3 composite
- actions/setup-python v3 composite
- actions/upload-artifact v1 composite
- docker/setup-qemu-action v1 composite
- pypa/cibuildwheel v2.9.0 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite