term

Erlang terms as Python values, and the External Term Format codec.

The classes for the Erlang types that Python has no equivalent of are exported here; the codec is term.codec.

class term.Atom

Bases: str, BaseTerm

An Erlang atom: a str that encodes back to an atom.

It is equal to, and hashes like, the string of the same text, so as a dict key the two are one key: {Atom('foo'): 1, 'foo': 2} is {'foo': 2}.

static from_string_or_atom(s)

Create an Atom from a string or return unchanged if it was an atom.

class term.BitString(val, last_byte_bits)

Bases: BaseTerm

A bitstring: bytes whose last byte holds only last_byte_bits (1..8) significant bits, the high ones. Encodes back to an Erlang bitstring. Decoded with the option "bitstring": "BitString".

class term.Export(module, function, arity)

Bases: BaseTerm

An external fun, fun Module:Function/Arity (EXPORT_EXT). Not callable from Python, but it can be sent back to Erlang unchanged.

Parameters:
  • module (str) – the module, an atom

  • function (str) – the function name, an atom

  • arity (int) – the number of arguments, 0 or more

class term.Fun(mod, arity, pid, index, uniq, old_index, old_uniq, free)

Bases: BaseTerm

Represents a pointer to a function in Erlang, with some variable values captured. Not callable from Python.

class term.ImproperList(elements, tail=<object object>)

Bases: List, BaseTerm

A simple data holder used to pass improper lists back to Erlang. An Erlang improper list looks like [1, 2, 3 | 4] where 4 takes tail slot of last list cell instead of NIL. This is a rare data type and very likely you will not ever need it.

class term.Pid(node_name, id, serial, creation)

Bases: BasePid

Represents Erlang-style process identifier with 3 components. Node component is always 0 for local node, otherwise it can take arbitrary integer values.

A pid is created by Erlang automatically. Pyrlang Process also generates one when it is born to register itself in the process registry. Pid uniquely identifies a running process in the cluster.

node_name_

NOTE: native encoder assumes this is a string.

is_local_to(node)

Compares self.node_name to other node.node_name :param node: Check whether pid is local to the node. :type node: pyrlang.node.Node

equals(other)

True if other is the same pid: node, id, serial and creation.

class term.Port(node_name, id, creation)

Bases: BaseTerm

An Erlang port identifier from another node. Python cannot use it, but it can store it and send it back unchanged: since OTP 26 every node must accept ports with 64-bit ids (DFLAG_V4_NC).

Parameters:
  • node_name (str) – the node that owns the port

  • id (int) – the port number, 0 .. 2^64-1

  • creation (int) – the incarnation of that node, 0 .. 2^32-1

class term.Record(module, name, exported, fields)

Bases: BaseTerm

A native record (EEP-79, OTP 29, RECORD_EXT): #Module:Name{...}. Native records are experimental in OTP 29 and 30.

Parameters:
  • module (str) – the module that defines the record, an atom

  • name (str) – the record name, an atom

  • exported (bool) – whether the module exports the record definition

  • fields (dict[str, Any]) – field name (atom) -> value, in the order of the definition; encoded in this order

class term.Reference(node_name, creation, refid)

Bases: BaseRef

Represents a reference value from Erlang, typically it has 12 bytes of unique data, but it might change.

static create(node_name, creation)

A new reference of node node_name, unequal to every other reference this process creates.

Its 3 ID words hold a per-process counter (the low 18 bits in the first word, the next 32 in the second) and 32 random bits (third), so a restarted node is unlikely to repeat references it made before.

Parameters:
  • node_name (str) – string, not a Node object

  • creation (int) – the creation of the node’s distribution

Return type:

term.reference.Reference

node_name_

Node the ref comes from. NOTE: native codec assumes this is a string.

id_

Identification bytes, guaranteed to be unique on the creating node

equals(other)

True if other is the same reference: node, creation and id.

Modules

atom

Erlang atoms: Atom and StrictAtom.

basetypes

Base classes of the term classes, and the type Term of a decoded value.

bitstring

Bitstrings whose length is not a whole number of bytes.

codec

The codec: Erlang External Term Format to Python values and back.

fun

Erlang funs: Fun (a closure) and Export (fun M:F/A).

list

Improper lists, and helpers for lists of code points.

pid

Erlang process identifiers.

port

Erlang port identifiers.

py_codec_impl

Module implements encoder and decoder from ETF (Erlang External Term Format) used by the network distribution layer.

record

Native records (Erlang/OTP 29).

reference

Erlang references.

util

Helpers for big-endian integers and for byte dumps.