termformat

Erlang External Term Format (de)serialization module


License
MIT
Install
pip install termformat==0.1.9

Documentation

termformat Build Status

Erlang External Term Format (de)serialization module.

Installation

termformat supports both Python 2.7+ and 3.3+ versions including PyPy.

$ apt-get install python-dev
$ pip install termformat

Usage

import termformat

binary = termformat.encode(20) # => b'\x83a\x14'
print termformat.decode(binary) # => 20
print termformat.is_atom(":foo") # => True
print termformat.atom_to_binary(":foo") # => "foo"
print termformat.binary_to_atom("foo") # => ":foo"

data = [0 for _ in range(1024)]
compressed = termformat.encode(data, compressed=6)
assert len(compressed) < len(termformat.encode(data))

Datatypes representation

Type Python Erlang
Integer int, long SMALL_INT_EXT, INT_EXT, SMALL_BIG_EXT, LARGE_BIG_EXT
Float float FLOAT_EXT, NEW_FLOAT_EXT*
String str, unicode, bytes BINARY_EXT, STRING_EXT*
Atom String with ":" prefix ATOM_EXT
Tuple tuple SMALL_TUPLE_EXT, LARGE_TUPLE_EXT
List list LIST_EXT, NIL_EXT

[1] Only decoding support
[2] If you need to encode/decode more complex types (such as booleans, datetime objects and dictionaries), see beretta