Create singleton Equinox modules.
Project description
oncequinox
Create singleton Equinox modules.
This is a micro-package, containing the single metaclass SingletonModuleMeta.
SingletonModuleMeta can be used to create Equinox modules that are
singletons, meaning that only one instance of the module can exist at any given
time.
Installation
pip install oncequinox
Documentation
Basic Usage
Create a singleton Equinox module:
import equinox as eqx
from oncequinox import SingletonModuleMeta
class MySingletonModule(eqx.Module, metaclass=SingletonModuleMeta):
value: str = "this is a singleton module"
# Create the singleton instance
singleton1 = MySingletonModule()
# Attempt to create another instance
singleton2 = MySingletonModule()
print(singleton1 is singleton2) # True
Singleton Per Class
Different classes maintain separate singleton instances:
import equinox as eqx
from oncequinox import SingletonModuleMeta
class ConfigA(eqx.Module, metaclass=SingletonModuleMeta):
name: str = "A"
class ConfigB(eqx.Module, metaclass=SingletonModuleMeta):
name: str = "B"
config_a = ConfigA()
config_b = ConfigB()
print(config_a is config_b) # False
print(config_a.name) # A
print(config_b.name) # B
With Initialization Arguments
Arguments are only used for the first instantiation:
import equinox as eqx
from oncequinox import SingletonModuleMeta
class HasValue(eqx.Module, metaclass=SingletonModuleMeta):
value: int
def __init__(self, value: int):
self.value = value
v1 = HasValue(10)
print(v1.value) # 10
# Subsequent calls ignore arguments and return existing instance
v2 = HasValue(20)
print(v2.value) # 10
print(v1 is v2) # True
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 oncequinox-0.1.0.tar.gz.
File metadata
- Download URL: oncequinox-0.1.0.tar.gz
- Upload date:
- Size: 110.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ece50c70084893f5333b1346e8ac16ee6642291243159b5091ecbc0b728722f7
|
|
| MD5 |
32e3ed2c30bf2654168144c6cdcd7434
|
|
| BLAKE2b-256 |
5b2b9bb1b5d5a02c634df2a2c62113b071e046e594f3c74dbe4a947e751240fa
|
Provenance
The following attestation bundles were made for oncequinox-0.1.0.tar.gz:
Publisher:
cd.yml on GalacticDynamics/oncequinox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oncequinox-0.1.0.tar.gz -
Subject digest:
ece50c70084893f5333b1346e8ac16ee6642291243159b5091ecbc0b728722f7 - Sigstore transparency entry: 642091306
- Sigstore integration time:
-
Permalink:
GalacticDynamics/oncequinox@f23f8e4696ba98cb14b5d912bceaf16c7fcd0949 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@f23f8e4696ba98cb14b5d912bceaf16c7fcd0949 -
Trigger Event:
release
-
Statement type:
File details
Details for the file oncequinox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: oncequinox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 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 |
63f50a9af0ba1b0fa27b3e3ce85d004c4ceaee0ed8712fd3afd57d646e662502
|
|
| MD5 |
0c9366fd1fcd50768d8d0f9cbdb6d7ed
|
|
| BLAKE2b-256 |
75adf9a0314b32d6afee7b41b86172f9b0a60b974816675cde42bd34a41632c5
|
Provenance
The following attestation bundles were made for oncequinox-0.1.0-py3-none-any.whl:
Publisher:
cd.yml on GalacticDynamics/oncequinox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oncequinox-0.1.0-py3-none-any.whl -
Subject digest:
63f50a9af0ba1b0fa27b3e3ce85d004c4ceaee0ed8712fd3afd57d646e662502 - Sigstore transparency entry: 642091313
- Sigstore integration time:
-
Permalink:
GalacticDynamics/oncequinox@f23f8e4696ba98cb14b5d912bceaf16c7fcd0949 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@f23f8e4696ba98cb14b5d912bceaf16c7fcd0949 -
Trigger Event:
release
-
Statement type: