pinstance


Namepinstance JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummarySimple singleton class and function decorators with 0 overhead
upload_time2023-05-04 13:29:56
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords decorator singleton
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pinstance",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "decorator,singleton",
    "author": "",
    "author_email": "Nazarov Pavel <unyite8@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/48/c4/e5d7b1278b86d897e34c444e89e9e964b4b5dde527a460afb3b658616b6a/pinstance-0.1.0.tar.gz",
    "platform": null,
    "description": "# Pinstance\n\nSimple [singleton](https://en.wikipedia.org/wiki/Singleton_pattern) class decorator with\nability to call bounded methods with 0 overhead.\n\nDecorated class can inherit other classes and can be inherited.\n\nDecorated class can not be collected till the end of a programm\n\n## Usage\n\nDecorate a class:\n\n```python\n@instanceclass\nclass MyClass:\n    def __init__(self, val):\n        self.class_var = val\n```\n\nNow you can instanciate it\n\n```python\ninst = MyClass(777)\ninst.class_var  ## 777\n```\nand access the instance anywhere via ```get_instance()``` class method:\n```python\nMyClass.get_instance().class_var  ## 777\nMyClass.get_instance().some_var = 555\nMyClass.get_instance().class_var  ## 555\n```\n\nFurthermore, to simplify calling methods via instance reference one can decorate desiered ```@instanceclass``` methods:\n\n```python\n@instancemethod\ndef my_function(self, param):\n    print(f'{self.class_var} | {param}')\n```\n\nand call them like static methods with ```0``` overhead:\n\n```python\nMyClass.my_function('example')  ## 555 | example\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple singleton class and function decorators with 0 overhead",
    "version": "0.1.0",
    "project_urls": {
        "homepage": "https://github.com/Nyite/Pinstance"
    },
    "split_keywords": [
        "decorator",
        "singleton"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7dba540271a11ca0d52590230d4672b3e2fd3e4e02879f06fde99e250dd3c2ad",
                "md5": "0a413f6ba3360b59695cc0cc0bafbdff",
                "sha256": "88cc0979c08350adda77d98fee0a80faded8cdb264679be36ece92a964f6d952"
            },
            "downloads": -1,
            "filename": "pinstance-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0a413f6ba3360b59695cc0cc0bafbdff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 2909,
            "upload_time": "2023-05-04T13:29:54",
            "upload_time_iso_8601": "2023-05-04T13:29:54.291762Z",
            "url": "https://files.pythonhosted.org/packages/7d/ba/540271a11ca0d52590230d4672b3e2fd3e4e02879f06fde99e250dd3c2ad/pinstance-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48c4e5d7b1278b86d897e34c444e89e9e964b4b5dde527a460afb3b658616b6a",
                "md5": "e14998d7de5053f01e65d7309bb25c11",
                "sha256": "d60146d42ed711cd87ab499dbcb5e2cbc88d1e5fe7f80ad9cdf9dfacd4380b28"
            },
            "downloads": -1,
            "filename": "pinstance-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e14998d7de5053f01e65d7309bb25c11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 2426,
            "upload_time": "2023-05-04T13:29:56",
            "upload_time_iso_8601": "2023-05-04T13:29:56.303127Z",
            "url": "https://files.pythonhosted.org/packages/48/c4/e5d7b1278b86d897e34c444e89e9e964b4b5dde527a460afb3b658616b6a/pinstance-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-04 13:29:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Nyite",
    "github_project": "Pinstance",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pinstance"
}
        
Elapsed time: 1.28585s