Skip to main content

The OTP framework for Python.

Project description

OtpyLib: OTP Framework for Python

An Erlang/Elixir OTP-inspired framework for Python's anyio async ecosystem.

License Development Status Latest release Supported Python versions Supported Python implementations Download format Downloads

Introduction

OtpyLib brings the proven patterns of Erlang/Elixir OTP to Python's async ecosystem. Built on anyio for cross-async-library compatibility, it provides battle-tested concurrency primitives for building fault-tolerant, distributed systems.

Stable APIs (v0.2.0):

  • genserver: Actor-model processes for stateful, message-passing services
  • supervisor: Fault-tolerant management of persistent services with restart strategies

Core Features:

  • mailboxes: Message-passing between async tasks
  • applications: Root of supervision trees
  • restart strategies: Permanent and Transient policies for service lifecycle management
  • fault tolerance: Automatic restart and failure isolation

Built on anyio

Unlike frameworks tied to specific async libraries, OtpyLib is built on anyio, providing compatibility across asyncio, Trio, and other async backends.

Design Philosophy

OtpyLib follows OTP's "let it crash" philosophy - instead of defensive programming, design systems that can fail safely and recover automatically. Services are organized in supervision trees where failures are isolated and handled at the appropriate level.

When to use Genserver vs Supervisor:

  • Genserver: For stateful services that handle messages (user sessions, caches, worker processes)
  • Static Supervisor: For managing long-running services that should restart on failure (web servers, database connections, message processors)

Quick Example

import anyio
from otpylib import genserver, supervisor
from otpylib.types import Permanent

# A simple counter genserver
class Counter:
    def __init__(self):
        self.count = 0
        
    async def handle_call(self, message, _from, state):
        if message == "get":
            return self.count, state
        elif message == "increment":
            self.count += 1
            return "ok", state

async def main():
    # Start a supervised counter service
    counter_spec = supervisor.child_spec(
        id="counter",
        task=genserver.start_link,
        args=[Counter, [], {}],
        restart=Permanent()
    )
    
    async with anyio.create_task_group() as tg:
        opts = supervisor.options()
        tg.start_soon(supervisor.start, [counter_spec], opts)

anyio.run(main)

Installation

pip install otpylib

Why OtpyLib?

Python's async ecosystem has powerful low-level primitives but lacks higher-level patterns for building reliable, concurrent systems. OtpyLib fills this gap by bringing OTP's proven supervision and actor-model patterns to Python.

Benefits:

  • Fault tolerance: Services that crash don't bring down the entire system
  • Supervision trees: Hierarchical failure handling and restart policies
  • Message passing: Clean, decoupled communication between services
  • Battle-tested patterns: Based on decades of Erlang/OTP production experience
  • Cross-platform async: Works with asyncio, Trio, and other anyio-compatible backends

The result is more reliable, maintainable concurrent code that handles failures gracefully and recovers automatically.

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

otpylib-0.5.15.tar.gz (121.7 kB view details)

Uploaded Source

Built Distribution

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

otpylib-0.5.15-py3-none-any.whl (148.3 kB view details)

Uploaded Python 3

File details

Details for the file otpylib-0.5.15.tar.gz.

File metadata

  • Download URL: otpylib-0.5.15.tar.gz
  • Upload date:
  • Size: 121.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for otpylib-0.5.15.tar.gz
Algorithm Hash digest
SHA256 d275a38890546a46293b39a0d4c6e7d3068676242ef31fac69de94187a1a0a64
MD5 9e0c29d3399174d1f8830941750b2880
BLAKE2b-256 6433f68f87989a8be8421952a10b3584ba6c1b10383a1f9683e47bee0408f337

See more details on using hashes here.

File details

Details for the file otpylib-0.5.15-py3-none-any.whl.

File metadata

  • Download URL: otpylib-0.5.15-py3-none-any.whl
  • Upload date:
  • Size: 148.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for otpylib-0.5.15-py3-none-any.whl
Algorithm Hash digest
SHA256 778ce842b1fd4b94f7eae4d527e45140ea8e177f08a28e597653bb9c2ed6a981
MD5 5a2efde5313343f5d772ce187b2a6e91
BLAKE2b-256 fa9be366618c036b3448fa6c6fd81c9b5f2b9385f7ab0c383ac564ee125759fc

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