Name | thecodecrate-builderable JSON |
Version |
1.6.0
JSON |
| download |
home_page | None |
Summary | This package provides a builder pattern implementation |
upload_time | 2024-10-02 11:21:38 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | The MIT License (MIT) Copyright (c) 2024 TheCodeCrate <loureiro.rg@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
builder pattern
python
library
python-builderable
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Python-Builderable
Builderable is a modular class for implementing the Builder pattern in Python.
The library is designed to allow developers to compose builder classes using pre-defined partials (mixins) or implement their own.
## Installation
```bash
pip install thecodecrate-builderable
```
## Usage Example
Here's a simple example of how to implement a builder class with builderable:
```python
from builderable import Builderable, WithListMixin
class MyBuilder(Builderable[int]):
def build(self) -> int:
return sum(self.get_items())
# Usage
builder = MyBuilder()
result = builder.add_item(5).add_item(10).build()
print(result) # Outputs: 15
```
## Immutability Trait
In some cases, you may want to enforce immutability, meaning each modification creates a new instance of the builder, rather than modifying the current one. This can be achieved by including the immutability trait in your builder class.
When using the `HasImmutability` trait, methods like "add_item" will clone the self object, append the new item to the clone's list, and return the cloned object. Without this trait, "add_item" will modify the current object directly.
Here's how to use the immutability feature:
```python
class ImmutableBuilder(
HasImmutability[int, int], # Enforces immutability
Builderable[int, int],
):
def build(self) -> int:
return sum(self.get_items())
# Usage
builder = (ImmutableBuilder()).add_item(5).add_item(10)
# The original builder remains unchanged
new_builder = builder.add_item(7)
print(new_builder.get_items()) # Outputs: [5, 10, 7]
print(builder.get_items()) # Outputs: [5, 10]
```
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "thecodecrate-builderable",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "builder pattern, python, library, python-builderable",
"author": null,
"author_email": "TheCodeCrate <loureiro.rg@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e7/f8/5ca23bab17b2481ad830a84dfaa2b733474d78b67f1fa6765499dfbc4778/thecodecrate_builderable-1.6.0.tar.gz",
"platform": null,
"description": "# Python-Builderable\n\nBuilderable is a modular class for implementing the Builder pattern in Python.\n\nThe library is designed to allow developers to compose builder classes using pre-defined partials (mixins) or implement their own.\n\n## Installation\n\n```bash\npip install thecodecrate-builderable\n```\n\n## Usage Example\n\nHere's a simple example of how to implement a builder class with builderable:\n\n```python\nfrom builderable import Builderable, WithListMixin\n\nclass MyBuilder(Builderable[int]):\n def build(self) -> int:\n return sum(self.get_items())\n\n# Usage\nbuilder = MyBuilder()\nresult = builder.add_item(5).add_item(10).build()\nprint(result) # Outputs: 15\n```\n\n## Immutability Trait\n\nIn some cases, you may want to enforce immutability, meaning each modification creates a new instance of the builder, rather than modifying the current one. This can be achieved by including the immutability trait in your builder class.\n\nWhen using the `HasImmutability` trait, methods like \"add_item\" will clone the self object, append the new item to the clone's list, and return the cloned object. Without this trait, \"add_item\" will modify the current object directly.\n\nHere's how to use the immutability feature:\n\n```python\nclass ImmutableBuilder(\n HasImmutability[int, int], # Enforces immutability\n Builderable[int, int],\n):\n def build(self) -> int:\n return sum(self.get_items())\n\n# Usage\nbuilder = (ImmutableBuilder()).add_item(5).add_item(10)\n\n# The original builder remains unchanged\nnew_builder = builder.add_item(7)\nprint(new_builder.get_items()) # Outputs: [5, 10, 7]\nprint(builder.get_items()) # Outputs: [5, 10]\n```\n\n## License\n\nThis project is licensed under the MIT License.\n",
"bugtrack_url": null,
"license": "The MIT License (MIT) Copyright (c) 2024 TheCodeCrate <loureiro.rg@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "This package provides a builder pattern implementation",
"version": "1.6.0",
"project_urls": {
"documentation": "https://github.com/thecodecrate/python-builderable",
"repository": "https://github.com/thecodecrate/python-builderable"
},
"split_keywords": [
"builder pattern",
" python",
" library",
" python-builderable"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1434b44f539e8e38cd44eda2921baf571171fafbdf99f4d84c470b0bd9229c6a",
"md5": "1eceed8e9eedbf36aaf9174e5d14d7a4",
"sha256": "3a3e0e36c62ce5826633a502487a197e77b1846ac28bcd4a9fd07153482ca2aa"
},
"downloads": -1,
"filename": "thecodecrate_builderable-1.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1eceed8e9eedbf36aaf9174e5d14d7a4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 9276,
"upload_time": "2024-10-02T11:21:36",
"upload_time_iso_8601": "2024-10-02T11:21:36.878570Z",
"url": "https://files.pythonhosted.org/packages/14/34/b44f539e8e38cd44eda2921baf571171fafbdf99f4d84c470b0bd9229c6a/thecodecrate_builderable-1.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e7f85ca23bab17b2481ad830a84dfaa2b733474d78b67f1fa6765499dfbc4778",
"md5": "1e2b69ee862e3fa9a0354edea9f5fdf9",
"sha256": "4ba57a8a1433c6f8c0f6bd7e531fe83b5197d97d0db40d7303d31798e868ca7e"
},
"downloads": -1,
"filename": "thecodecrate_builderable-1.6.0.tar.gz",
"has_sig": false,
"md5_digest": "1e2b69ee862e3fa9a0354edea9f5fdf9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7525,
"upload_time": "2024-10-02T11:21:38",
"upload_time_iso_8601": "2024-10-02T11:21:38.587044Z",
"url": "https://files.pythonhosted.org/packages/e7/f8/5ca23bab17b2481ad830a84dfaa2b733474d78b67f1fa6765499dfbc4778/thecodecrate_builderable-1.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-02 11:21:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thecodecrate",
"github_project": "python-builderable",
"github_not_found": true,
"lcname": "thecodecrate-builderable"
}