Metadata-Version: 2.1
Name: pinstance
Version: 0.1.0
Summary: Simple singleton class and function decorators with 0 overhead
Project-URL: homepage, https://github.com/Nyite/Pinstance
Author-email: Nazarov Pavel <unyite8@gmail.com>
License: MIT
License-File: LICENSE
Keywords: decorator,singleton
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# Pinstance

Simple [singleton](https://en.wikipedia.org/wiki/Singleton_pattern) class decorator with
ability to call bounded methods with 0 overhead.

Decorated class can inherit other classes and can be inherited.

Decorated class can not be collected till the end of a programm

## Usage

Decorate a class:

```python
@instanceclass
class MyClass:
    def __init__(self, val):
        self.class_var = val
```

Now you can instanciate it

```python
inst = MyClass(777)
inst.class_var  ## 777
```
and access the instance anywhere via ```get_instance()``` class method:
```python
MyClass.get_instance().class_var  ## 777
MyClass.get_instance().some_var = 555
MyClass.get_instance().class_var  ## 555
```

Furthermore, to simplify calling methods via instance reference one can decorate desiered ```@instanceclass``` methods:

```python
@instancemethod
def my_function(self, param):
    print(f'{self.class_var} | {param}')
```

and call them like static methods with ```0``` overhead:

```python
MyClass.my_function('example')  ## 555 | example
```
