When you start writing code in Erlang… You’ll have lot of difficulty to reverse this process. Every piece of code you’ll write after get in Erlang world will be treated as complex piece of shit. Some languages were designed to fit all my needs, embedding lot of principle from actor model like Scala, Clojure, Racket or even Haskell. Unfortunately, sometime, you need to write code in some old fashion language like Perl, Python or Raw Shell. In this article, I will try to simulate an Erlang environment in Python, based on different Open-Source modules.

# Actor Model - Thespian or Pykka

If you have already done some code in Erlang, you should know every pieces of Erlang architecture are small processes running in background. All these processes can communicate only with a mailbox (a queue) and are totally isolated from each others. This feature is particularly interesting in case of crash, killing only one processes and not all your program. In Erlang we have a name for that: “Let it crash” philosophy. Unfortunately, OOP languages don’t care about isolation. Every object can be raped by another object, altering the state of the first one.

In Python, I’ve tested 2 libraries, Thespian (opens new window) (the more complete) and Pykka (opens new window) (a good one, but lake of features). Thespian was developed by Godaddy and seems production ready.

# FSM Design Pattern - Transitions

Another great feature of Erlang is its default programming pattern design based on Finite State Machine. Erlang uses a framework called OTP to standardize every piece of code and giving lot of great feature on this design (benchmarking, debugging and more). If you are searching an implementation of FSM pattern in Python, you will find a lot! The most complete I’ve currently found is transitions (opens new window)

# Local and Distributed Cache

A really nice feature of Erlang, coming from Prolog, is memory and disk cache directly integrated, named ETS and DETS. To make thing clear, its likes if you had a redis server directly integrated in your python interpreter. ETS and DETS give us ability to build distributed database easily, in fact, this distributed database already exist and is called “Mnesia”.

In Python, I don’t find any solution to this issue. You can use a local redis instance, memcached, or just a spawned actor from thespian/pykka acting as cache collector.

# Coherent Datastructure

Erlang External Term Format

# Metaprogramming

# Clustering Python