{"id":26483552,"url":"https://github.com/faucetsdn/python3-msgpack","last_synced_at":"2026-07-17T01:34:38.018Z","repository":{"id":45587367,"uuid":"431668523","full_name":"faucetsdn/python3-msgpack","owner":"faucetsdn","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-07T01:51:36.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-11T06:35:24.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faucetsdn.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.rst","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-25T00:40:23.000Z","updated_at":"2021-12-07T01:51:12.000Z","dependencies_parsed_at":"2022-09-10T17:21:43.084Z","dependency_job_id":null,"html_url":"https://github.com/faucetsdn/python3-msgpack","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/faucetsdn/python3-msgpack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faucetsdn%2Fpython3-msgpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faucetsdn%2Fpython3-msgpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faucetsdn%2Fpython3-msgpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faucetsdn%2Fpython3-msgpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faucetsdn","download_url":"https://codeload.github.com/faucetsdn/python3-msgpack/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faucetsdn%2Fpython3-msgpack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35563613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-16T02:00:06.687Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-20T04:55:55.620Z","updated_at":"2026-07-17T01:34:37.989Z","avatar_url":"https://github.com/faucetsdn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MessagePack for Python\n\n[![Build Status](https://travis-ci.org/msgpack/msgpack-python.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-python)\n[![Documentation Status](https://readthedocs.org/projects/msgpack-python/badge/?version=latest)](https://msgpack-python.readthedocs.io/en/latest/?badge=latest)\n\n## What's this\n\n[MessagePack](https://msgpack.org/) is an efficient binary serialization format.\nIt lets you exchange data among multiple languages like JSON.\nBut it's faster and smaller.\nThis package provides CPython bindings for reading and writing MessagePack data.\n\n\n## Very important notes for existing users\n\n### PyPI package name\n\nPackage name on PyPI was changed from `msgpack-python` to `msgpack` from 0.5.\n\nWhen upgrading from msgpack-0.4 or earlier, do `pip uninstall msgpack-python` before\n`pip install -U msgpack`.\n\n\n### Compatibility with the old format\n\nYou can use `use_bin_type=False` option to pack `bytes`\nobject into raw type in the old msgpack spec, instead of bin type in new msgpack spec.\n\nYou can unpack old msgpack format using `raw=True` option.\nIt unpacks str (raw) type in msgpack into Python bytes.\n\nSee note below for detail.\n\n\n### Major breaking changes in msgpack 1.0\n\n* Python 2\n\n  * The extension module does not support Python 2 anymore.\n    The pure Python implementation (`msgpack.fallback`) is used for Python 2.\n\n* Packer\n\n  * `use_bin_type=True` by default.  bytes are encoded in bin type in msgpack.\n    **If you are still using Python 2, you must use unicode for all string types.**\n    You can use `use_bin_type=False` to encode into old msgpack format.\n  * `encoding` option is removed.  UTF-8 is used always.\n\n* Unpacker\n\n  * `raw=False` by default.  It assumes str types are valid UTF-8 string\n    and decode them to Python str (unicode) object.\n  * `encoding` option is removed.  You can use `raw=True` to support old format.\n  * Default value of `max_buffer_size` is changed from 0 to 100 MiB.\n  * Default value of `strict_map_key` is changed to True to avoid hashdos.\n    You need to pass `strict_map_key=False` if you have data which contain map keys\n    which type is not bytes or str.\n\n\n## Install\n\n```\n$ pip install msgpack\n```\n\n### Pure Python implementation\n\nThe extension module in msgpack (`msgpack._cmsgpack`) does not support\nPython 2 and PyPy.\n\nBut msgpack provides a pure Python implementation (`msgpack.fallback`)\nfor PyPy and Python 2.\n\nSince the [pip](https://pip.pypa.io/) uses the pure Python implementation,\nPython 2 support will not be dropped in the foreseeable future.\n\n\n### Windows\n\nWhen you can't use a binary distribution, you need to install Visual Studio\nor Windows SDK on Windows.\nWithout extension, using pure Python implementation on CPython runs slowly.\n\n\n## How to use\n\nNOTE: In examples below, I use `raw=False` and `use_bin_type=True` for users\nusing msgpack \u003c 1.0. These options are default from msgpack 1.0 so you can omit them.\n\n\n### One-shot pack \u0026 unpack\n\nUse `packb` for packing and `unpackb` for unpacking.\nmsgpack provides `dumps` and `loads` as an alias for compatibility with\n`json` and `pickle`.\n\n`pack` and `dump` packs to a file-like object.\n`unpack` and `load` unpacks from a file-like object.\n\n```pycon\n\u003e\u003e\u003e import msgpack\n\u003e\u003e\u003e msgpack.packb([1, 2, 3], use_bin_type=True)\n'\\x93\\x01\\x02\\x03'\n\u003e\u003e\u003e msgpack.unpackb(_, raw=False)\n[1, 2, 3]\n```\n\n`unpack` unpacks msgpack's array to Python's list, but can also unpack to tuple:\n\n```pycon\n\u003e\u003e\u003e msgpack.unpackb(b'\\x93\\x01\\x02\\x03', use_list=False, raw=False)\n(1, 2, 3)\n```\n\nYou should always specify the `use_list` keyword argument for backward compatibility.\nSee performance issues relating to `use_list option`_ below.\n\nRead the docstring for other options.\n\n\n### Streaming unpacking\n\n`Unpacker` is a \"streaming unpacker\". It unpacks multiple objects from one\nstream (or from bytes provided through its `feed` method).\n\n```py\nimport msgpack\nfrom io import BytesIO\n\nbuf = BytesIO()\nfor i in range(100):\n   buf.write(msgpack.packb(i, use_bin_type=True))\n\nbuf.seek(0)\n\nunpacker = msgpack.Unpacker(buf, raw=False)\nfor unpacked in unpacker:\n    print(unpacked)\n```\n\n\n### Packing/unpacking of custom data type\n\nIt is also possible to pack/unpack custom data types. Here is an example for\n`datetime.datetime`.\n\n```py\nimport datetime\nimport msgpack\n\nuseful_dict = {\n    \"id\": 1,\n    \"created\": datetime.datetime.now(),\n}\n\ndef decode_datetime(obj):\n    if '__datetime__' in obj:\n        obj = datetime.datetime.strptime(obj[\"as_str\"], \"%Y%m%dT%H:%M:%S.%f\")\n    return obj\n\ndef encode_datetime(obj):\n    if isinstance(obj, datetime.datetime):\n        return {'__datetime__': True, 'as_str': obj.strftime(\"%Y%m%dT%H:%M:%S.%f\")}\n    return obj\n\n\npacked_dict = msgpack.packb(useful_dict, default=encode_datetime, use_bin_type=True)\nthis_dict_again = msgpack.unpackb(packed_dict, object_hook=decode_datetime, raw=False)\n```\n\n`Unpacker`'s `object_hook` callback receives a dict; the\n`object_pairs_hook` callback may instead be used to receive a list of\nkey-value pairs.\n\n\n### Extended types\n\nIt is also possible to pack/unpack custom data types using the **ext** type.\n\n```pycon\n\u003e\u003e\u003e import msgpack\n\u003e\u003e\u003e import array\n\u003e\u003e\u003e def default(obj):\n...     if isinstance(obj, array.array) and obj.typecode == 'd':\n...         return msgpack.ExtType(42, obj.tostring())\n...     raise TypeError(\"Unknown type: %r\" % (obj,))\n...\n\u003e\u003e\u003e def ext_hook(code, data):\n...     if code == 42:\n...         a = array.array('d')\n...         a.fromstring(data)\n...         return a\n...     return ExtType(code, data)\n...\n\u003e\u003e\u003e data = array.array('d', [1.2, 3.4])\n\u003e\u003e\u003e packed = msgpack.packb(data, default=default, use_bin_type=True)\n\u003e\u003e\u003e unpacked = msgpack.unpackb(packed, ext_hook=ext_hook, raw=False)\n\u003e\u003e\u003e data == unpacked\nTrue\n```\n\n\n### Advanced unpacking control\n\nAs an alternative to iteration, `Unpacker` objects provide `unpack`,\n`skip`, `read_array_header` and `read_map_header` methods. The former two\nread an entire message from the stream, respectively de-serialising and returning\nthe result, or ignoring it. The latter two methods return the number of elements\nin the upcoming container, so that each element in an array, or key-value pair\nin a map, can be unpacked or skipped individually.\n\n\n## Notes\n\n### string and binary type\n\nEarly versions of msgpack didn't distinguish string and binary types.\nThe type for representing both string and binary types was named **raw**.\n\nYou can pack into and unpack from this old spec using `use_bin_type=False`\nand `raw=True` options.\n\n```pycon\n\u003e\u003e\u003e import msgpack\n\u003e\u003e\u003e msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=False), raw=True)\n[b'spam', b'eggs']\n\u003e\u003e\u003e msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=True), raw=False)\n[b'spam', 'eggs']\n```\n\n### ext type\n\nTo use the **ext** type, pass `msgpack.ExtType` object to packer.\n\n```pycon\n\u003e\u003e\u003e import msgpack\n\u003e\u003e\u003e packed = msgpack.packb(msgpack.ExtType(42, b'xyzzy'))\n\u003e\u003e\u003e msgpack.unpackb(packed)\nExtType(code=42, data='xyzzy')\n```\n\nYou can use it with `default` and `ext_hook`. See below.\n\n\n### Security\n\nTo unpacking data received from unreliable source, msgpack provides\ntwo security options.\n\n`max_buffer_size` (default: `100*1024*1024`) limits the internal buffer size.\nIt is used to limit the preallocated list size too.\n\n`strict_map_key` (default: `True`) limits the type of map keys to bytes and str.\nWhile msgpack spec doesn't limit the types of the map keys,\nthere is a risk of the hashdos.\nIf you need to support other types for map keys, use `strict_map_key=False`.\n\n\n### Performance tips\n\nCPython's GC starts when growing allocated object.\nThis means unpacking may cause useless GC.\nYou can use `gc.disable()` when unpacking large message.\n\nList is the default sequence type of Python.\nBut tuple is lighter than list.\nYou can use `use_list=False` while unpacking when performance is important.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaucetsdn%2Fpython3-msgpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaucetsdn%2Fpython3-msgpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaucetsdn%2Fpython3-msgpack/lists"}