Data types

Messages are encoded and decoded by Term. Its Data types page has the full mapping in both directions and the options of the codec; this page is what a Pyrlang user meets first.

Erlang

In a Python process

atom()

Atom, a str subclass: msg == "ok" works

true, false, undefined

True, False, None

integer(), float()

int, float

binary()

bytes

bitstring()

BitString

tuple(), list(), map()

tuple, list, dict

pid(), port(), reference()

Pid, Port, Reference

fun M:F/A, other funs

Export, Fun

native record (OTP 29)

Record

Things to know:

  • Strings. An Erlang string is a list of integers. A list of up to 65535 integers that are all below 256 arrives as a Python str, even when Erlang meant numbers: [1, 2, 3] arrives as '\x01\x02\x03'. Any other list arrives as a list. A Python str is sent as an Erlang string. To pass text without surprises, send UTF-8 binaries (<<"text"/utf8>>, Python bytes).

  • None is sent as the atom undefined, and undefined arrives as None.

  • Atoms as dict keys. An Atom equals the str of the same text. A map that has both an atom and a string of the same text as keys cannot become a dict and is refused; the connection that sent it is closed.

  • Bitstrings arrive as BitString (Term’s own default is a tuple), so one that is sent back is a bitstring again.

  • A Process object inside a message is sent as its pid.

  • Other Python objects are sent as {ClassName, #{Field => Value}} of their public attributes, or as what their __etf__() method returns.

A message that cannot be decoded is treated as a protocol error: it is logged and the connection to that node is closed, as an Erlang node does.