scoped-singleton
Easier sharing data between objects
Installation
pip3 install scoped-singleton
How to use it
from dataclasses import dataclass
from scoped_singleton import context_scoped_singleton
@context_scoped_singleton
@dataclass
class Account:
uuid: str
use it with cached_property to stop repeated requests
from dataclasses import dataclass
from cached_property import cached_property
from scoped_singleton import context_scoped_singleton
@context_scoped_singleton
@dataclass
class Account:
uuid: str
@cached_property
def credit_limit(self):
return rpc(self.uuid)["credit_limit"]
@dataclass
class Transaction:
id: int
account_uuid: str
@property
def account(self):
return Account(uuid=self.account_uuid)
txn1 = Transaction(id=1, account_uuid="123")
txn2 = Transaction(id=2, account_uuid="123")
txn3 = Transaction(id=3, account_uuid="124")
assert txn1.account is txn2.account
assert txn1.account is not txn3.account
Release files for scoped-singleton 1.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| scoped-singleton-1.1.7.tar.gz | 2.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scoped_singleton-1.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.9 kB
Release files / scoped-singleton-1.1.7.tar.gz
| Download URL | scoped-singleton-1.1.7.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a613c5de036144edd7ab05d08e2caf6ec981e091737d2a51a591c2b8c6a2bcab
|
|
BLAKE2b-256 checksum How to use checksums |
3da986794d295c0b145c751ff571958320e125f68f2fde967934674e2ff310cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|
Release files / scoped_singleton-1.1.7-py3-none-any.whl
| Download URL | scoped_singleton-1.1.7-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
391a304c888b889a639da6f947f1d75214c75090baed6da4859d4246761090be
|
|
BLAKE2b-256 checksum How to use checksums |
7822157a6ce194c5b72f63512efd6ef6292780a6c99b1c04f6500898eb396e64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|