Skip to main content

Erlang port protocol

Project description

Erlang port protocol for Python simplify interoperability between Erlang and Python. On the Python side write a processor object and pass it to erlport.PortProtocol like this:

from erlport import PortProtocol

class Processor(object):

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

if __name__ == "__main__":
    PortProtocol(Processor()).start()

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

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

hello(Name) ->
    Port = open_port({spawn, "python hello.py"},
        [{packet, 1}, nouse_stdio, 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"

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.2.tar.gz (6.5 kB view hashes)

Uploaded source

Built Distribution

erlport-0.2-py2.6.egg (10.5 kB view hashes)

Uploaded 2 6

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page