Skip to main content

A Python library for serializing and deserializing object trees to JSON-compatable values (dicts, lists, strings, ints, floats, bools).

Project description

structpack
==========

A Python library for serializing and deserializing object trees to JSON-compatable values (dicts, lists, strings, ints, floats, bools).

[![Build Status](https://travis-ci.org/Knio/structpack.svg?branch=master)](https://travis-ci.org/Knio/structpack)
[![Coverage Status](https://coveralls.io/repos/Knio/structpack/badge.png)](https://coveralls.io/r/Knio/structpack)


Installation
------------

The recommended way to install structpack is with [pip](http://pypi.python.org/pypi/pip/):

pip install structpack

[![PyPI version](https://badge.fury.io/py/structpack.png)](http://badge.fury.io/py/structpack)


Examples
========

`structpack` is designed to be a base class (`msg`) that you inherit from and add properties to (`bool`, `int`, `float`, `string`, `list`, and `dict`).

The `msg` class adds methods `pack` and `load` which convert your object to and from native types, respectively.

The following is a trivial example of how to make a `Point` type using structpack

import structpack
class Point(structpack.msg):
x = structpack.float
y = structpack.float
z = structpack.float
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

>>> p1 = Point(1., 2., 3.)
>>> data = p1.pack()
>>> print data
(1.0, 2.0, 3.0)

>>> p2 = Point.load(data)
>>> print p2
<__main__.Point object at 0x0000000001EDA390>
>>> print p2.x, p2.y, p2.z
1.0 2.0 3.0


More
----

Please see the [test suite](https://github.com/Knio/structpack/blob/master/tests/test_structpack.py) for more examples until they are documented here.


TODO
====

- Docs / examples
- Type check values
- Benchmark & optimize

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

structpack-1.5.0.zip (6.7 kB view details)

Uploaded Source

File details

Details for the file structpack-1.5.0.zip.

File metadata

  • Download URL: structpack-1.5.0.zip
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for structpack-1.5.0.zip
Algorithm Hash digest
SHA256 403630063b1bac476b9b94c3a6483e72d497c97f929adfb452ba5b6a9ecd6468
MD5 df6c09d85547730db94c9ccec832e565
BLAKE2b-256 6822c418430d40968f0401924c1fb0fe43d73e3abeacf116f5625c864de249e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page