def is_singleton(obj: Any, /) -> bool
Check if a given object is a dbzero singleton instance.
A class is designated as a singleton by passing singleton=True to the @dbzero.memo decorator. This ensures that only one instance of the class can exist within a single prefix.
Parameters
objAny
The object to inspect.
Returns
True if the provided object is an instance of a singleton class, False otherwise.
Example
import dbzero as db0
# Define singleton and regular classes
@db0.memo
class User:
def __init__(self, name: str):
self.name = name
@db0.memo(singleton=True)
class AppConfig:
def __init__(self, theme: str):
self.theme = theme
# Check singleton status:
assert db0.is_singleton(user_alice) is False
assert db0.is_singleton(app_settings) is True