Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pattern-singleton

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pattern-singleton

Metaclass Singleton Pattern (supports Multi-thread).

  • 1.2.0
  • PyPI
  • Socket score

Maintainers
1

================= Pattern Singleton

.. image:: https://img.shields.io/pypi/pyversions/pattern_singleton :target: https://pypi.python.org/pypi/pattern_singleton :alt: Python

.. image:: https://img.shields.io/pypi/v/pattern_singleton.svg?color=brightgreen :target: https://pypi.python.org/pypi/pattern_singleton :alt: PyPi

.. image:: https://img.shields.io/pypi/l/pattern_singleton?color=brightgreen :target: https://github.com/MarcinMysliwiec/pattern_singleton/blob/master/LICENSE :alt: License

.. image:: https://travis-ci.com/MarcinMysliwiec/pattern_singleton.svg :target: https://travis-ci.com/MarcinMysliwiec/pattern_singleton :alt: Build

.. image:: https://codecov.io/gh/MarcinMysliwiec/pattern_singleton/branch/master/graph/badge.svg?token=ZJCBWXAJPR :target: https://codecov.io/gh/MarcinMysliwiec/pattern_singleton :alt: 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 <https://github.com/MarcinMysliwiec/pattern_singleton/blob/master/LICENSE>`__ license
* But I would appreciate a star on `GitHub <https://github.com/MarcinMysliwiec>`__

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):

.. code-block:: sh

    $ pip install pattern-singleton


Example Usage

.. code-block:: python

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 <https://github.com/MarcinMysliwiec>__ with Cookiecutter_ and the audreyr/cookiecutter-pypackage_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter .. _audreyr/cookiecutter-pypackage: https://github.com/audreyr/cookiecutter-pypackage

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc