Skip to main content

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

PyPI platforms PyPI version

pip install oncequinox

Documentation

Actions Status

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oncequinox-0.1.0.tar.gz (110.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oncequinox-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for oncequinox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ece50c70084893f5333b1346e8ac16ee6642291243159b5091ecbc0b728722f7
MD5 32e3ed2c30bf2654168144c6cdcd7434
BLAKE2b-256 5b2b9bb1b5d5a02c634df2a2c62113b071e046e594f3c74dbe4a947e751240fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for oncequinox-0.1.0.tar.gz:

Publisher: cd.yml on GalacticDynamics/oncequinox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for oncequinox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63f50a9af0ba1b0fa27b3e3ce85d004c4ceaee0ed8712fd3afd57d646e662502
MD5 0c9366fd1fcd50768d8d0f9cbdb6d7ed
BLAKE2b-256 75adf9a0314b32d6afee7b41b86172f9b0a60b974816675cde42bd34a41632c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for oncequinox-0.1.0-py3-none-any.whl:

Publisher: cd.yml on GalacticDynamics/oncequinox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page