Skip to main content

Erlang port protocol

Project description

Project URLs:

Description

The erlport Python library implements Erlang external term format and Erlang port protocol for easier integration of Python and Erlang.

The library exports the following classes and functions:

  • Port(packet=1, use_stdio=False) - class implementing port which connects with the corresponding Erlang port. See open_port/2 for description of packet and use_stdio arguments.

  • Protocol() - class which simplifies creation of request-response protocols.

  • Atom(str) - class which represents an Erlang atom.

  • String(unicode | list) - class representing an Erlang string. Must be used as a wrapper if Unicode string expected instead of a list.

  • BitBinary(str) - class representing an Erlang bitstring whose length in bits is not a multiple of 8.

  • decode(str) - function to convert binary data into a term.

  • encode(term) - function to convert a term into the external format.

  • IncompleteData - exception raised by decode() in case of incomplete input data.

Installation

Prerequisites:

  • Erlang >= R11B-4

  • Python >= 2.4

To install the library use easy_install from setuptools package like this:

$ easy_install erlport

Examples

See examples directory in the source distribution for additional examples.

For simple request-response protocol use Port and Protocol on the Python side like this:

from erlport import Port, Protocol

class HelloProtocol(Protocol):

    def handle_hello(self, name):
        return "Hello, %s" % name

if __name__ == "__main__":
    proto = HelloProtocol()
    proto.run(Port(use_stdio=True))

On the Erlang side function hello() can be called like this:

-module(hello).
-export([hello/1]).

hello(Name) ->
    Port = open_port({spawn, "python -u hello.py"}, [{packet, 1}, binary]),
    port_command(Port, term_to_binary({hello, Name})),
    receive
        {Port, {data, Data}} ->
            binary_to_term(Data)
    end.

Test it in the Erlang shell:

1> c(hello).
{ok,hello}
2> hello:hello("Bob").
"Hello, Bob"

Notes for Windows users

  • It seems Erlang’s open_port function ignores nouse_stdio option on Windows. So the Port class must be instantiated with use_stdio=True argument.

  • Python must be ran with -u option to open stdin/stdout in binary mode.

Feedback

Please report bugs, offer suggestions or feedback at:

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

erlport-0.4.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

erlport-0.4-py2.6.egg (13.7 kB view details)

Uploaded Egg

File details

Details for the file erlport-0.4.tar.gz.

File metadata

  • Download URL: erlport-0.4.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for erlport-0.4.tar.gz
Algorithm Hash digest
SHA256 a0d16c28eeb3e698bbbd66dbbd502a5e23ffc7e3f1ee7e2bbabe74746d0767af
MD5 117ffb28637eca8edeff508f1e332bcf
BLAKE2b-256 bb25bab1e493e5d27aff8d59a95de54c774d70c2b8fabaa0d3bbcf8a451283fe

See more details on using hashes here.

File details

Details for the file erlport-0.4-py2.6.egg.

File metadata

  • Download URL: erlport-0.4-py2.6.egg
  • Upload date:
  • Size: 13.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for erlport-0.4-py2.6.egg
Algorithm Hash digest
SHA256 8a1e9b22e03f184494ae6d64c767443990ffadaf3df1132bd5f6b45ba88228de
MD5 f4a0b292a70e074af9ad832c81915a49
BLAKE2b-256 1f37122e1c9ae1a3c79e308d5b115e3de7a25e41fa67fb6907193ef96136b710

See more details on using hashes here.

Supported by

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