A Singleton python project
By CenturyBoys
Did you need help? Call meeseeks from a single box from anywhere
This is meeseeks a single class to do singletons. In the core meeseeks is a class decorator that allows you to have a global singleton scope or a specialized one, some configurations can be used to give more flexibility to your code.
Scopes
Each class with his decorator has a specialized scope, that is otherwise you create meeseeks object (OnlyOne) and this object will have your configuration and singletons
Specialized
import meeseeks
@meeseeks.OnlyOne()
class A:
def __int__(self, a):
pass
a1a = A(10)
a1b = A(10)
a1c = A(20)
assert a1a == a1b == a1c
or
import meeseeks
only_one = meeseeks.OnlyOne()
@only_one
class A:
def __int__(self, a):
pass
a1a = A(10)
a1b = A(10)
a1c = A(20)
assert a1a == a1b == a1c
On this example we register the class reference in the meeseeks class instance scope
Configuration
We provide two configuration options:
tll: int(time to live) in seconds. Setting a value greater than 0, the singleton reference will have a time to live in seconds (default 0). Obs: the expired time validation will be made only when you create a new instance of the registered class ie your object will still be in memoryby_args_hash: bool( a hash will be made of all args and kwargs ). Setting True, a singleton reference will be created for each arg + kwargs hash (default False). Obs: The kwargs`s order doesn't have influence
TTL
import meeseeks
import time
@meeseeks.OnlyOne(ttl=1)
class A:
def __int__(self, *args, **kwargs):
pass
a1a = A(1, var_a="a")
a1b = A(1, var_a="a")
time.sleep(1)
a1c = A(1, var_a="a")
assert a1a == a1b
assert a1b != a1c
In this example, we set the ttl to 1 second and validate if the first two calls result in the same object and after 1 second we validate if the object is different from the first two
BY_ARGS_HASH
import meeseeks
import time
@meeseeks.OnlyOne(by_args_hash=True)
class A:
def __int__(self, *args, **kwargs):
pass
a1a = A(1, var_a="a", var_b="b")
a1b = A(1, var_b="b", var_a="a")
a1c = A(10, var_b="b", var_a="a")
assert a1a == a1b
assert a1c != a1b
In this example, we set by_args_hash variable to True and validate if the first two calls result in the same object despite the kwargs order being different. The last validation shows us that different args and kwargs result in different objects.
Metadata
Release files for meeseeks-singleton 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| meeseeks_singleton-0.4.4.tar.gz | 7.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| meeseeks_singleton-0.4.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / meeseeks_singleton-0.4.4.tar.gz
| Download URL | meeseeks_singleton-0.4.4.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4683360f419abb22f4be1cbd1ae8a282e07304ee1ed61a85c844faf155153c6
|
|
BLAKE2b-256 checksum How to use checksums |
66fc7c930ef82677fda30dc8190c6cc3cc066deaafb06448beec7e8f69ebbfd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Linux/6.1.0-13-amd64
|
Release files / meeseeks_singleton-0.4.4-py3-none-any.whl
| Download URL | meeseeks_singleton-0.4.4-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e1ade489e9b9a76e9cc8a1e958d6749694bf35a71a0a273099b05c8579b301d4
|
|
BLAKE2b-256 checksum How to use checksums |
fe9fbdaa0d82337da6f2de17dd0e0a87093cef2de02a547af70cdaad5ab11818
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Linux/6.1.0-13-amd64
|
Security for meeseeks-singleton 0.4.4
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.