Code Monkey home page Code Monkey logo

termformat's Introduction

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

termformat's People

Contributors

defineserious avatar dveselov avatar tyrannosaurus avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

defineserious

termformat's Issues

Merging

Hi,
I was wondering if you wanted to work together on code I have had here:
https://github.com/okeuday/erlang_py
I added it to PyPI so it does have more visibility now. The BSD license is similar to your MIT licensed code. The code could benefit from the same testing you are currently doing. I have been using this code with Python 2 and it should work fine with Python 3. I wanted to have a common erlang module for handling all binary erlang term format encoding. Tell me what you think.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.