Skip to main content

Papyra

Papyra

Durable persistence, retention and compaction for actor systems

Test Suite Package version Supported Python versions


Documentation: https://papyra.dymmond.com 📚

Source Code: https://github.com/dymmond/papyra

The official supported version is always the latest released.


Durable persistence, retention, recovery, and observability for actor systems.

Papyra is a production-grade persistence layer designed specifically for actor-based runtimes. It provides durable system history, audits, dead-letter tracking, retention + compaction, startup health checks, recovery orchestration, and operational tooling.

Papyra is not an actor framework. It's the persistence and observability backbone that makes an actor system operationally safe.


Why Papyra?

Actor systems are excellent at concurrency and fault isolation, but production operators eventually need:

  • A durable history of lifecycle events (start/stop/crash/restart)
  • Audit snapshots for “what's running and what's broken?”
  • Dead letters for undeliverable messages
  • Retention to prevent unbounded growth
  • Compaction to physically reclaim disk space
  • Startup checks and deterministic recovery
  • Metrics for observability
  • CLI tools for real-world operations

Papyra solves this explicitly and safely.


Features

🧱 Persistence backends

  • JSON NDJSON file backend (simple, readable, portable)
  • Rotating files backend (bounded disk usage)
  • Redis Streams backend (production, distributed, consumer-groups)
  • In-memory backend (tests, ephemeral)

♻️ Retention & compaction

  • Record-count, age, and size-based retention
  • Explicit physical compaction / vacuum
  • Crash-safe atomic rewrite semantics where applicable

🩺 Health, startup checks & recovery

  • Scan for corruption / anomalies
  • Recovery modes: IGNORE / REPAIR / QUARANTINE
  • Startup orchestration to guarantee a clean persistence layer before actors start

📊 Metrics & integration

  • Backend metrics (writes, errors, scans, recoveries, compactions)
  • CLI metrics output
  • Optional OpenTelemetry integration

🛠️ CLI

  • persistence scan | recover | compact | inspect | startup-check
  • doctor run
  • inspect events | audits | dead-letters | summary
  • metrics …

Installation

pip install papyra

Optional extras:

pip install papyra[redis]

ActorSystem + Papyra: the mental model

An ActorSystem emits observable facts while it runs:

  • Events: lifecycle transitions (started, stopped, crashed, restarted)
  • Audits: point-in-time health snapshots (counts, registry status, dead letters)
  • Dead letters: messages that couldn't be delivered

Papyra persists these facts using the configured backend.

A key guarantee: startup checks happen before any actor is allowed to run. If the persistence layer is corrupted and startup mode is strict, ActorSystem.start() fails.


Quickstart (with ActorSystem)

1) Pick a persistence backend

JSON file backend

from papyra.persistence.json import JsonFilePersistence

persistence = JsonFilePersistence("./papyra.ndjson")

Redis Streams backend

from papyra.persistence.backends.redis import RedisStreamsConfig, RedisStreamsPersistence

persistence = RedisStreamsPersistence(
    RedisStreamsConfig(url="redis://localhost:6379/0", prefix="papyra", system_id="local")
)

2) Start the ActorSystem with startup checks

from papyra.system import ActorSystem
from papyra.persistence.startup import PersistenceStartupConfig, PersistenceStartupMode
from papyra.persistence.models import PersistenceRecoveryConfig, PersistenceRecoveryMode

system = ActorSystem(
    persistence=persistence,
    # Ensure the persistence layer is clean *before* any actor starts
    persistence_startup=PersistenceStartupConfig(
        mode=PersistenceStartupMode.RECOVER,
        recovery=PersistenceRecoveryConfig(mode=PersistenceRecoveryMode.REPAIR),
    ),
)

await system.start()
  • fail_on_anomaly → start fails if corruption is detected
  • recover → attempt recovery, then require a clean post-scan
  • ignore / scan_only → don't fail startup

3) Spawn actors after the system starts

from papyra.actor import Actor

class Echo(Actor):
    async def receive(self, message):
        return message

ref = system.spawn(Echo, name="echo")

4) Shut down cleanly

await system.aclose()

Operational CLI

Health check (Doctor)

papyra doctor run

Fail hard if there are anomalies:

papyra doctor run --mode fail_on_anomaly

Attempt recovery:

papyra doctor run --mode recover --recovery-mode repair

Persistence maintenance

Scan:

papyra persistence scan --path ./papyra.ndjson

Recover:

papyra persistence recover --mode repair --path ./papyra.ndjson

Compact:

papyra persistence compact --path ./papyra.ndjson

Inspect summary:

papyra persistence inspect --path ./papyra.ndjson --show-metrics

Documentation

The full documentation covers:

  • Core concepts and actor lifecycle observability
  • All persistence backends (JSON, rotation, Redis, memory)
  • Retention and compaction strategies
  • Failure scenarios and recovery playbooks
  • Startup guarantees
  • Metrics + OpenTelemetry integration
  • Extending Papyra with custom backends

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

papyra-0.2.0.tar.gz (90.9 kB view details)

Uploaded Source

Built Distribution

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

papyra-0.2.0-py3-none-any.whl (120.1 kB view details)

Uploaded Python 3

File details

Details for the file papyra-0.2.0.tar.gz.

File metadata

  • Download URL: papyra-0.2.0.tar.gz
  • Upload date:
  • Size: 90.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.10.20"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.10.20","system":{"name":"Linux","release":"6.17.0-1018-azure"}} HTTPX2/2.5.0

File hashes

Hashes for papyra-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f6a27472fa7e68726dd9f79feec95f28c1a79e55debc05dc9f4db68a6e1bc219
MD5 f6a5e031b94ee10b55b0b3d3040f66c2
BLAKE2b-256 cf0b4b92607e2070fe71e57db05e55e6fe0bd6bf18c85710737049726cc00213

See more details on using hashes here.

File details

Details for the file papyra-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: papyra-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 120.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.10.20"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.10.20","system":{"name":"Linux","release":"6.17.0-1018-azure"}} HTTPX2/2.5.0

File hashes

Hashes for papyra-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fa6f21e20f34d0875168ed60f95d03c1849d43e6864049d7031f08c11aed78c
MD5 c05fbb963f5c037897e8aceefd285e8f
BLAKE2b-256 5737677edcc37734a257e5d4dad73700bd6bcaf6cfd0af8174de491fa5d92634

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 Sentry Error logging StatusPage Status page