Skip to main content

Pattern Singleton

Python PyPi License Build Coverage

Description

Singleton is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance. This implementation of Singleton Design Pattern is based on metaclass method.

  • Free software: MIT license

  • But I would appreciate a star on GitHub

Multithreaded

This method provide proper handling for multi-thread environment by closing public threading lock while creating instance of Singleton subclass.

Installation

Just use (No other package is needed):

$ pip install pattern-singleton

Example Usage

from pattern_singleton import Singleton


class Example(metaclass=Singleton):
    def __init__(self):
        self.variable = 1


if __name__ == '__main__':
    example_01 = Example()
    example_02 = Example()

    print(example_01.variable)  # displays 1
    print(example_02.variable)  # displays 1

    example_01.variable = 2     # changes value for every instance of Example class

    print(example_01.variable)  # displays 2
    print(example_02.variable)  # displays 2

Credits

This package was created by Marcin Mysliwiec with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Metadata

Release files for pattern-singleton 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pattern-singleton 1.2.0
File Size Uploaded Provenance Actions
pattern_singleton-1.2.0.tar.gz 10.7 kB Without provenance Details for pattern_singleton-1.2.0.tar.gz

Release files / pattern_singleton-1.2.0.tar.gz

Download URL pattern_singleton-1.2.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d3ee5b5885fd0ac0dbfc16abda31e36e10e180797c44fcb32c7b8347a227d75c
BLAKE2b-256 checksum
How to use checksums
5c521531bd435ddba56d996a5c706184ef93eecfc6318ef0a069a9ecf5ef1b73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Security for pattern-singleton 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page