rarg-python-patterns
A small, self-contained collection of reusable Python patterns. The first (and
currently only) pattern is a Multiton: an implementation of the
Multiton pattern with
TTL-based cache expiry, importable from rarg_python_patterns.multiton.
Multiton
A Multiton wraps a factory function and its arguments. The underlying
instance is created lazily on first access to .instance and cached, keyed on
the (frozen, hashable) factory and arguments. Any Multiton constructed with
the same factory and arguments shares the cached instance. Multiton objects
are themselves hashable, equality-comparable and pickleable (with pickle,
cloudpickle and dill), provided their arguments are too.
Cached instances expire after ttl seconds of inactivity; accessing
.instance resets the TTL. Expired entries are swept on every access via a
min-heap ordered by expiry time.
from rarg_python_patterns import Multiton
def open_connection(url: str, timeout: float = 1.0) -> Connection:
...
# The resource is only created when `.instance` is first accessed.
resource = Multiton(open_connection, "https://www.python.org", timeout=10.0)
response = resource.instance.request("GET", "/foo/bar.html")
# Override the default TTL (300s) per-instance.
resource = Multiton(open_connection, "https://www.python.org").with_args(ttl=60.0)
Installation
pip install rarg-python-patterns
The package has no required runtime dependencies. numpy is an optional
dependency: when installed, numpy.ndarray factory arguments are frozen by
their bytes, shape and dtype so they can be used as cache keys.
Development
This package uses uv.
uv sync
uv run --group test py.test tests/
uv run --dev pre-commit run -a
Metadata
Release files for rarg-python-patterns 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rarg_python_patterns-0.0.5.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rarg_python_patterns-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / rarg_python_patterns-0.0.5.tar.gz
| Download URL | rarg_python_patterns-0.0.5.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b488b547969a8527cfe1b740759ed3cf1c2aa3c9a716f8526360f3914b0fc94
|
|
BLAKE2b-256 checksum How to use checksums |
bd7c948f578cf442e687c12499d7c604cbbb09fda26a4f22a5a4a043eb605700
|
| 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 28, 2026.
Transparency logRelease files / rarg_python_patterns-0.0.5-py3-none-any.whl
| Download URL | rarg_python_patterns-0.0.5-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f892845f2f26afa0b6309dd766965ac17764bef486407ada974fba468c0cb0a
|
|
BLAKE2b-256 checksum How to use checksums |
191db57ba40dccc7f93cba6740ab18639f29ac07ec0c9295916421ebac7b6d21
|
| 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 28, 2026.
Transparency log