Skip to content

Home

patos

A flock of typed, zero-dependency Python patterns. Pip one in, or copy one in and own the file.

Get started Browse the flock

Each pattern is a single self-contained pato (a duck). Adopt one, and you get a tiny, fully typed, standard-library-only module that does one thing well. The flock is patos. A single duck is a pato.

Two ways to use a pato

pip it in

Install the whole flock and import the patterns you want.

pip install patos
from patos import Registry, Singleton

copy it in

Open a duck's page, copy its source from the Source section, and paste it into your own tree. No runtime dependency, no version pin, no tool, just one module you own.

# paste src/patos/singleton.py
# the file is yours now

Why patos

  • Typed. Every pato ships full type hints and py.typed, so your checker sees through it.
  • Zero dependencies. Each duck is standard library only. Copying one in adds nothing to your lockfile.
  • You own the code. The copy-in path gives you a small, readable module instead of a black box.
  • One idea per duck. No god-objects, no framework. Reach for the one pattern you need.

The flock

Creational

  • singleton

    One instance per class, with __init__ running exactly once. Metaclass based, never a cached __new__.

  • flyweight

    A metaclass that interns instances by their constructor args. Build once, share forever, stay immutable.

Dispatch & selection

  • registry

    Self-registering class hierarchies. Subclasses enroll through __init_subclass__, and dispatch tries each one until it builds.

  • strategy

    A named family of interchangeable implementations, picked at runtime or by first_available().

  • dispatch

    Dispatch on a value the way singledispatch dispatches on a type.

Command-line

  • strflag

    An enum Flag whose members carry a literal string, OR-combinable and iterable.