{"library":"singleton-decorator","title":"A Testable Singleton Decorator","description":"The `singleton-decorator` is a Python library (version 1.0.0, last released in 2017) that provides a simple decorator to implement the singleton design pattern for classes. It aims to address common pitfalls of other singleton implementations, specifically making the decorated classes more amenable to unit testing by exposing the original class via a `__wrapped__` attribute. The library is stable but not actively developed.","language":"python","status":"maintenance","last_verified":"Sat May 16","install":{"commands":["pip install singleton-decorator"],"cli":null},"imports":["from singleton_decorator import singleton"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from singleton_decorator import singleton\n\n@singleton\nclass MyClass:\n    def __init__(self, value=0):\n        self.value = value\n        print(f\"MyClass initialized with value: {self.value}\")\n\n    def get_value(self):\n        return self.value\n\n# First instance creates and initializes\nobj1 = MyClass(10)\nprint(f\"Obj1 value: {obj1.get_value()}\")\n\n# Second instance returns the same object, __init__ is NOT called again\nobj2 = MyClass(20) # Arguments are ignored after the first call\nprint(f\"Obj2 value: {obj2.get_value()}\")\nprint(f\"Are obj1 and obj2 the same instance? {obj1 is obj2}\")\n\n# Accessing the original class for testing or static methods\n# Note: Use __wrapped__ for direct class method calls or inspection in tests\nprint(f\"Accessing original class via __wrapped__: {MyClass.__wrapped__.__name__}\")\n","lang":"python","description":"This example demonstrates how to apply the `@singleton` decorator to a class. It shows that only one instance of `MyClass` is ever created, and subsequent calls to the constructor will return the existing instance without re-running `__init__`. It also highlights how to access the original, undecorated class using `__wrapped__` for testing purposes.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"1.0.0","pypi_latest":"1.0.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.4,"avg_import_s":0,"wheel_type":"sdist"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"19.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":1.9,"import_time_s":0,"mem_mb":0,"disk_size":"20M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"21.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0,"mem_mb":0,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"18.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"singleton-decorator","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0,"mem_mb":0,"disk_size":"19M"}]}}