Decorator for implementing singleton pattern
## Usage
To install, add `pygleton` module to your project. Then add
`from pygleton import singleton` to your file.
There are two ways to use the decorator: without repetetive `__init__()` calls
and with them (you do not want this unless you know what are you doing).
### Main scenario: call init only the first time
Do not pass any parameter to the decorator:
```python
@singleton()
class Foo:
...
```
Now, when you do `Foo(...)` for the first time, object instance will be created,
and `Foo` init method would be called. Any subsequent `Foo(...)` calls will
return the same instance, and `Foo.__init__` will be completely ignored.
### I know what I am doing: I want to call init every time
Pass truthy value to `recall_init` parameter of the decorator:
```python
@singleton(recall_init=True)
class Foo:
...
```
Now, when you do `Foo(...)` for the first time, object instance will be created,
and all subsequent `Foo(...)` calls will return the same instance. However,
**init method will be called every time.**
### Usage example
See test file.
## Development
The project uses poetry (highly recommended) and you should know your way
around. The supplied `Makefiles` allows to run linters, check formatting, and
run tests (100% coverage is required!) simply by typing `make`. Everything
should pass.
Raw data
{
"_id": null,
"home_page": "https://github.com/pragmatic-fi/pygleton",
"name": "pygleton",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "decorator, singleton",
"author": "The Pragmatic Solutions",
"author_email": "contact@thepragmatic.fi",
"download_url": "https://files.pythonhosted.org/packages/3f/80/17bc4629d9acf4601e69d00c1af8f7d5fe767028b9d2dfeaf9cf0eb81b06/pygleton-1.0.1.tar.gz",
"platform": null,
"description": "Decorator for implementing singleton pattern\n\n## Usage\n\nTo install, add `pygleton` module to your project. Then add\n`from pygleton import singleton` to your file.\n\nThere are two ways to use the decorator: without repetetive `__init__()` calls\nand with them (you do not want this unless you know what are you doing).\n\n### Main scenario: call init only the first time\n\nDo not pass any parameter to the decorator:\n\n```python\n@singleton()\nclass Foo:\n ...\n```\n\nNow, when you do `Foo(...)` for the first time, object instance will be created,\nand `Foo` init method would be called. Any subsequent `Foo(...)` calls will\nreturn the same instance, and `Foo.__init__` will be completely ignored.\n\n### I know what I am doing: I want to call init every time\n\nPass truthy value to `recall_init` parameter of the decorator:\n\n```python\n@singleton(recall_init=True)\nclass Foo:\n ...\n```\n\nNow, when you do `Foo(...)` for the first time, object instance will be created,\nand all subsequent `Foo(...)` calls will return the same instance. However,\n**init method will be called every time.**\n\n### Usage example\n\nSee test file.\n\n## Development\n\nThe project uses poetry (highly recommended) and you should know your way\naround. The supplied `Makefiles` allows to run linters, check formatting, and\nrun tests (100% coverage is required!) simply by typing `make`. Everything\nshould pass.\n",
"bugtrack_url": null,
"license": null,
"summary": "Decorator for implementing singleton classes",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/pragmatic-fi/pygleton",
"Repository": "https://github.com/pragmatic-fi/pygleton.git"
},
"split_keywords": [
"decorator",
" singleton"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "825eeb4775bc4a947cb52e97141c5abee85cbf7c6ca9a6d839f434de2913fcea",
"md5": "aa4bad979fdf16d3db68e395a26aca34",
"sha256": "3a95e60eb4fbc7b14382c268e2709a9cbae7deb931a58e79c03d41d1ff1c96f7"
},
"downloads": -1,
"filename": "pygleton-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aa4bad979fdf16d3db68e395a26aca34",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 3440,
"upload_time": "2024-07-11T12:13:05",
"upload_time_iso_8601": "2024-07-11T12:13:05.497115Z",
"url": "https://files.pythonhosted.org/packages/82/5e/eb4775bc4a947cb52e97141c5abee85cbf7c6ca9a6d839f434de2913fcea/pygleton-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3f8017bc4629d9acf4601e69d00c1af8f7d5fe767028b9d2dfeaf9cf0eb81b06",
"md5": "8f464522d94fbc048de25440fda541a5",
"sha256": "b92298b54fe54ef8d98b77c40ceda5d0eb762050949ab281757905b05a0f812b"
},
"downloads": -1,
"filename": "pygleton-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "8f464522d94fbc048de25440fda541a5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 3048,
"upload_time": "2024-07-11T12:13:07",
"upload_time_iso_8601": "2024-07-11T12:13:07.320427Z",
"url": "https://files.pythonhosted.org/packages/3f/80/17bc4629d9acf4601e69d00c1af8f7d5fe767028b9d2dfeaf9cf0eb81b06/pygleton-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-11 12:13:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pragmatic-fi",
"github_project": "pygleton",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pygleton"
}