Skip to main content

Typed Python design and dispatch patterns, pip one in or copy one in and own the file

Project description

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.

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 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

Command-line

pato description docs
StrFlag an enum Flag whose members carry a literal string, OR-combinable and iterable 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

This project uses uv.

  • Install: uv sync --extra dev
  • Lint: uv run ruff check . && uv run ruff format --check .
  • Typecheck: uv run pyrefly check
  • Test: uv run pytest
  • Docs: uv run --extra docs mkdocs build
  • Build: uv build

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

patos-0.0.4.tar.gz (481.4 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.4-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patos-0.0.4.tar.gz
  • Upload date:
  • Size: 481.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for patos-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7be737a59d27238c491811ef5890a305dfc2f4595d4f08479d5a4476e20d6464
MD5 ebea6925fb23e3e97e2eb9e97d247b10
BLAKE2b-256 2cdbe734358204cc99bb892313b5b3c51649ce780a52311c31415d3469c786c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for patos-0.0.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: patos-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for patos-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9d030b0f020a462aa3d6e4c31484c49d8175b943cfca1fb108eafae221dbd6dc
MD5 d2e97279f15e9d79852f5ad3053fc2f8
BLAKE2b-256 b9b52ad79204e2ec692bef5ca26bcb75d39f4c211c4ad7668e14133bd8a90b08

See more details on using hashes here.

Provenance

The following attestation bundles were made for patos-0.0.4-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.

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