Skip to content

msgpack-python extension that provides support for Timestamp, Date, and 'naive' DateTime (UTC) Ext types

License

Notifications You must be signed in to change notification settings

aisrael/msgpack-python-ext

Repository files navigation

MsgPack Python Ext

PyPi

Travis CI

Documentation Status

Updates

msgpack-python extension that provides support for Timestamp, Date, and "Naive" DateTime (UTC) packed Ext types.

Usage

Until this project is published on PyPI, simply add the following to your requirements.txt:

git+https://github.com/aisrael/msgpack-python-ext

Then, instead of using msgpack.packb/msgpack.unpackb directly, you would use msgpack_ext.packb/msgpack_ext.unpackb as follows:

import datetime
import msgpack_ext

packed_date = msgpack_ext.packb(datetime.date(2008, 8, 16))
assert b'\xd6e\x07\xd8\x08\x10' == packed_date

date = msgpack_ext.unpackb(packed_date)
assert datetime.date(2008, 8, 16) == date

packed_datetime = msgpack_ext.packb(datetime.datetime(1879, 3, 14, 11, 30, 00))
assert b'\xc7\x07f\x07W\x03\x0e\x0b\x1e\x00' == packed_datetime

dt = msgpack_ext.unpackb(packed_datetime)
assert datetime.datetime(1879, 3, 14, 11, 30, 00) == dt

msgpack_ext.unpackb adds the ext_hook = msgpack_ext.msgpack_ext.ext_hook keyword option automatically to provide an ext_hook that can recognize and succesfully unpack date, datetime, and the MessagePack Timestamp Ext formats.

Date and DateTime formats

For all dates, times, and timestamps, assume UTC from the sender.

Dates are packed/unpacked using the Ext type with code 101 using the following format:

| year (uint16) | month (uint8) | day (uint8) |

DateTimes are Dates are packed/unpacked using the Ext type with code 102 using the following format:

| year (uint16) | month (uint8) | day (uint8) | hour (uint8) | minute (uint8) | second (uint8) |

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

msgpack-python extension that provides support for Timestamp, Date, and 'naive' DateTime (UTC) Ext types

Resources

License

Stars

Watchers

Forks

Packages

No packages published