The singleton_package
is a simple Python package that provides a Singleton
metaclass. This metaclass can be used to create singleton objects, ensuring that only one instance of a class exists throughout the application.
You can install the singleton_package
using pip:
pip install singleton_package
To use the Singleton metaclass in your classes, simply specify Singleton as the metaclass:
from singleton import Singleton
class MyClass(metaclass=Singleton):
def __init__(self):
# Your initialization code here
pass
# Usage
instance1 = MyClass()
instance2 = MyClass()
# instance1 and instance2 will be the same object
assert instance1 is instance2
Contributions are welcome! Please feel free to submit pull requests or report any issues you encounter.
This project is licensed under the MIT License - see the LICENSE file for details.