Installation
python -m pip install any-singleton
Documentation
Usage
Create a singleton
Register a singleton with a value:
from any_singleton import singleton
tea = singleton('my_project.main.coffee', 'tea')
Instantiate an object and register as a singleton:
from any_singleton import singleton
my_range = singleton('my_project.main.coffee', range, 123)
For disambiguating, you can use singleton_value() to instead singleton() when the value is a type:
from any_singleton import singleton_value
class Tea:
pass
tea = singleton_value('my_project.main.coffee', type(Tea))
Make a function can only be called once in global
Using @once to create a function that can only be called once in global.
import tomllib
from any_singleton import once, singleton
@once('my_project.initializations.init')
def init(config_path: str) -> None:
with open(config_path, 'rb') as f:
config = singleton('my_project.globals.config', tomllib.load(f))
init('config.toml')
Or just using @run_once to create a function as same as decorated with @once and calling it immediately.
import tomllib
from any_singleton import run_once, singleton
@run_once('my_project.initializations.init', 'config.toml')
def init(config_path: str) -> None:
with open(config_path, 'rb') as f:
config = singleton('my_project.globals.config', tomllib.load(f))
ATTENTION
any-singletonwill OCCUPY the global variable_any_singleton, seeany_singleton.singletons.GLOBAL_KEY.- DO NOT use
*.@cached_returnandany_singleton.nonreferenced_typesas a domain name. They're RESERVED words.
View this source code on GitHub.
Release files for any-singleton 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| any_singleton-1.1.0.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| any_singleton-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / any_singleton-1.1.0.tar.gz
| Download URL | any_singleton-1.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd4b8352a2ec49e9b193257112e44f842c42a546dc2cb800b094b7e34df95528
|
|
BLAKE2b-256 checksum How to use checksums |
e0b106590377e8d614c4cfcb8039aa8433d7b1fc8d69f4f4cb3a9fb46f4db4e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 10, 2026.
Transparency logRelease files / any_singleton-1.1.0-py3-none-any.whl
| Download URL | any_singleton-1.1.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47ce19c60c9c2ad3c1da4b55d7714fea99fbae1ddd7a2b95c6e499ff7971ae37
|
|
BLAKE2b-256 checksum How to use checksums |
aeef9b73e4d92554d2cb9a0f10ee4364f0506f5e7d297663012a39c10458e7cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 10, 2026.
Transparency log