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

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

Download files

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

Source Distribution

patos-0.0.10.tar.gz (508.8 kB view details)

Uploaded Source

Built Distribution

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

patos-0.0.10-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file patos-0.0.10.tar.gz.

File metadata

  • Download URL: patos-0.0.10.tar.gz
  • Upload date:
  • Size: 508.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for patos-0.0.10.tar.gz
Algorithm Hash digest
SHA256 8b9ebefefe080f74ff0c62109a4b1f140c3ff878dbc5fa8782eb1bdc7d36dbaa
MD5 05a218a3119ff490be63c25c59e49d40
BLAKE2b-256 ba704258d6a4e90ee103af35f937962468707fedd06d8aab3696db741ff2c294

See more details on using hashes here.

Provenance

The following attestation bundles were made for patos-0.0.10.tar.gz:

Publisher: publish.yml on phvv-me/patos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patos-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: patos-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 39.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for patos-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 11e532c1adf14de298033ca46a0e29faaa5567cd55ad13772b85e3020afd06fe
MD5 c0be62797401dd54b875f50fc57190ba
BLAKE2b-256 8524690fd6c7cc81ad7a015c2b369e23c479c2efe735c9a1af584c8c6feaef44

See more details on using hashes here.

Provenance

The following attestation bundles were made for patos-0.0.10-py3-none-any.whl:

Publisher: publish.yml on phvv-me/patos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.0.13

2 files

0.0.12

2 files

This release

0.0.10 This release

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page