Provides decorators and utilities for implementing the singleton pattern.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file any_singleton-1.1.0.tar.gz.
File metadata
- Download URL: any_singleton-1.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd4b8352a2ec49e9b193257112e44f842c42a546dc2cb800b094b7e34df95528
|
|
| MD5 |
d7a9a11fa0476705cda6b829fd74a682
|
|
| BLAKE2b-256 |
e0b106590377e8d614c4cfcb8039aa8433d7b1fc8d69f4f4cb3a9fb46f4db4e0
|
Provenance
The following attestation bundles were made for any_singleton-1.1.0.tar.gz:
Publisher:
publish-pypi.yml on Orange23333/any-singleton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
any_singleton-1.1.0.tar.gz -
Subject digest:
fd4b8352a2ec49e9b193257112e44f842c42a546dc2cb800b094b7e34df95528 - Sigstore transparency entry: 1074919477
- Sigstore integration time:
-
Permalink:
Orange23333/any-singleton@1e483771c2b21ba49e4f6fe5b26931f1ed86a2a8 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Orange23333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1e483771c2b21ba49e4f6fe5b26931f1ed86a2a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file any_singleton-1.1.0-py3-none-any.whl.
File metadata
- Download URL: any_singleton-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ce19c60c9c2ad3c1da4b55d7714fea99fbae1ddd7a2b95c6e499ff7971ae37
|
|
| MD5 |
de6200619ed329d335fce15c408cb88e
|
|
| BLAKE2b-256 |
aeef9b73e4d92554d2cb9a0f10ee4364f0506f5e7d297663012a39c10458e7cc
|
Provenance
The following attestation bundles were made for any_singleton-1.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on Orange23333/any-singleton
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
any_singleton-1.1.0-py3-none-any.whl -
Subject digest:
47ce19c60c9c2ad3c1da4b55d7714fea99fbae1ddd7a2b95c6e499ff7971ae37 - Sigstore transparency entry: 1074919480
- Sigstore integration time:
-
Permalink:
Orange23333/any-singleton@1e483771c2b21ba49e4f6fe5b26931f1ed86a2a8 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Orange23333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1e483771c2b21ba49e4f6fe5b26931f1ed86a2a8 -
Trigger Event:
release
-
Statement type: