This project has been archived by its maintainers, and is no longer receiving any updates.
rarg-multiton
A small, self-contained implementation of the Multiton pattern with TTL-based cache expiry.
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_multiton 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-multiton
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-multiton 0.0.1
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_multiton-0.0.1.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rarg_multiton-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.6 kB
Release files / rarg_multiton-0.0.1.tar.gz
| Download URL | rarg_multiton-0.0.1.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31d0b4de55211d3ee4a1671ec978cb102599ee2e33884c6b874824de8a9b4fc2
|
|
BLAKE2b-256 checksum How to use checksums |
91c52ec18cb903e44c124daf25f68a2a21f13a10d1379ec856ca4001d5cf8dcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 4, 2026.
Transparency logRelease files / rarg_multiton-0.0.1-py3-none-any.whl
| Download URL | rarg_multiton-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
894dee6a1eafdfc0b525679c07a5188148091f50cab6abd75d4c92afc73771be
|
|
BLAKE2b-256 checksum How to use checksums |
1616d89e7d7c27ef338fd46746cf4f56638a51fff041def5ccd10b649449fb35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 4, 2026.
Transparency log