Skip to main content

patos

PyPI version Python versions License Docs

A flock of typed, zero-dependency Python design patterns. Each pattern is a single self-contained pato (a duck you adopt), fully typed, standard library only, and small enough to read in one sitting.

Install

pip install patos

Or copy a single duck. Open its docs page, copy the source from the Source section, and paste it into your own project. No dependency, no version pin, no tool, just one module you own.

The optional PostgreSQL toolkit installs SQLAlchemy, pgvector, and inflection only when a project asks for them.

pip install "patos[sql]"
from patos import sql

Patterns

Creational

pato description docs
Singleton one instance per class, __init__ runs once docs
FlyweightMeta a metaclass that interns instances by constructor args, build-once and immutable docs

Dispatch & selection

pato description docs
Registry self-registering class hierarchies via __init_subclass__, with try-each dispatch, select(predicate) and first_available() docs
Strategy a named family of interchangeable implementations, with first_available() docs
value_dispatch dispatch on a value the way singledispatch dispatches on a type docs
type_dispatch dispatch on the first argument's type, the open-type-ladder dual of value_dispatch docs

Structural & lifecycle

pato description docs
Decorator a transparent wrapper that forwards everything to the wrapped object but what it overrides docs
Pipeline a reversible stack of stages, applied forward and unwound in reverse around a core op docs
Lifecycle a typed state machine that permits only the transitions its table declares docs
DerivedCache a load-once cache of a derived value keyed by exactly what it depends on docs

Command-line

pato description docs
StrFlag an enum Flag whose members carry a literal string, OR-combinable and iterable docs

Research registration

pato description docs
SourceRegistration binds one research node to the exact source set governing a run and seals it
statement_bytes the sealed statement of a node file, front matter and settlement sections excluded
sha256_text_file, sha256_text_sources checkout-independent digests of registered text

The seal covers the node's statement and the whole bytes of every other registered source. The statement starts at the first ## heading after the front matter and ends before the first ## Evidence, ## Ledger or ## Log heading, matched without regard to case. Front matter is never sealed, so status, date and the registration_sha256 field itself move freely, and a node that settles and appends to its log still verifies against the claim it was registered under. Every source is hashed as relative POSIX path \0 LF-normalized bytes \0, ordered by path, which keeps one seal identical on Windows and POSIX checkouts alike.

Optional extensions

namespace description docs
sql typed SQLModel columns, native PostgreSQL enums, pgvector cosine distance, JSONB reads, and set based SQL helpers docs

Example

from patos import Singleton


class Settings(Singleton):
    def __init__(self) -> None:
        self.debug = False


a = Settings()
a.debug = True
b = Settings()      # same object, __init__ did not run again

assert a is b and b.debug

Documentation

Full documentation lives at phvv.me/patos.

Development

  • Install: pip install -e ".[dev]"
  • Lint: ruff check . && ruff format --check .
  • Typecheck: pyrefly check
  • Test: pytest
  • Docs: pip install -e ".[docs]" && mkdocs build
  • Build: python -m build

Metadata

Release files for patos 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for patos 0.0.14
File Size Uploaded
patos-0.0.14.tar.gz 551.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for patos 0.0.14
File Interpreter ABI Platform
patos-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 601.6 kB

Release files / patos-0.0.14.tar.gz

Download URL patos-0.0.14.tar.gz
Size 551.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9544b672d381d93655bfbca2646deb4a891c0039d5658f16f0aed3f5382b9a25
BLAKE2b-256 checksum
How to use checksums
b56e5072453eac758332d408467058e91e29d9c69f6dd8753366030d16187bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / patos-0.0.14-py3-none-any.whl

Download URL patos-0.0.14-py3-none-any.whl
Size 49.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae133a8612f3c6ddd5bd8f2800cba1718155301601d9a6c511ea8c1b15aef523
BLAKE2b-256 checksum
How to use checksums
287d19a34e43cae31cff07a9696637061a8bdc41f2595cccf71b0cfb422c2d9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.13

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page