| Name | customdataclass JSON |
| Version |
0.1.2
JSON |
| download |
| home_page | |
| Summary | A custom dataclass implementation |
| upload_time | 2023-10-30 16:19:35 |
| maintainer | |
| docs_url | None |
| author | |
| requires_python | >=3.7 |
| license | MIT |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
PyYAML
toml
ujson
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Customdataclass
<p align="center">
<img src=https://img.shields.io/github/issues-raw/lorossi/customdataclass></img>
<img src=https://img.shields.io/pypi/l/customdataclass></img>
<img src=https://img.shields.io/pypi/pyversions/customdataclass></img>
<img src=https://img.shields.io/pypi/v/customdataclass></img>
<img src=https://img.shields.io/pypi/format/customdataclass></img>
<img src=https://img.shields.io/badge/dynamic/json?color=informational&label=code%20coverage&query=totals.percent_covered_display&suffix=%25&url=https%3A%2F%2Fraw.githubusercontent.com%2Florossi%2Fcustomdataclass%2Fmain%2Fcoverage.json></img>
<img src=https://img.shields.io/github/languages/top/lorossi/customdataclass></img>
</p>
Custom implementation of the `dataclass` module from the standard Python library as a base class for other dataclasses.
The documentation is available [here](https://lorossi.github.io/customdataclass).
## Details
A while back I was working on a project *(now lost in a dusty corner of my GitHub profile)* that required me to create a lot of data structures *(variables used only to hold complex data)* and I quickly realised that using dictionaries *(or named dictionaries)* was slowly becoming messy because:
- dictionaries are mutable
- dictionary keys are strings and there's no easy way to set a default value for a key
- there's no way to ensure that a dictionary is well-formed
- complex attributes that are needed once or twice cannot be generated on the fly and must be stored in the dictionary
After a quick Google-fu session, I found out the existence of the `dataclass` decorator, swiftly provided by the `dataclasses`. This decorator allows you to create a class that is used only to hold data, and it provides a lot of useful features, such as:
- default values for attributes
- pre-determined methods *(such as `__init__`, `__repr__`, etc.)*
However, it does not handle easily features like:
- complex attributes *(i.e. attributes that are dataclasses themselves)*
- nested dataclasses *(i.e. a dataclass that has another dataclass as an attribute)*
- serialization and deserialization
- hashing and equality
- type checking
- inheritance
All these were important for the project *(which once again will be finished, one day)* and so I decided to create a custom class that would handle all these features.
I chose to create a class *(and not a decorator)* because I wanted to be able to inherit from it and to be able to use it as a base class for other dataclasses, thus solving the aforementioned problems.
### Provided features
- default values for attributes
- type checking *(can be deactivated)*
- nested dataclasses *(i.e. a dataclass that has another dataclass as an attribute)*
- frozen dataclasses
- a dataclass cannot be modified after its creation *(if the parameter `frozen` is set to `True`, as per default)*
- otherwise, a dataclass can be manually frozen using the `freeze` method
- equality comparison *(via the `__eq__` method)*
- hashing *(via the `__hash__` method)*
- full support inheritance
- full support for methods overriding and custom properties
## Installing
The package is available on PyPI and can be installed using `pip`:
```bash
pip install -u customdataclass
```
## Examples
Examples can be found in the `examples` folder, both in a text file [EXAMPLES.md](EXAMPLES.md) and in a set of Python scripts.
## Tests
Unit tests can be found in the `tests` folder.
Currently, the code coverage for unit tests is close to 100%.
### Running the tests
To run the tests, simply run the following command from the root folder of the project:
```bash
python3 -m unittest discover -v -s ./tests -p "test*.py
```
If you're using VScode, you can also use the `Run Tests` command from the `Python Test Explorer for Visual Studio Code` extension.
### Computing the coverage
To compute the coverage, simply run the following commands from the root folder of the project:
- `coverage run -m unittest discover -s ./tests -p "test*.py"`
- `coverage report -m` to see the report in the terminal
- `coverage html` to see format the report in HTML and see it in the browser
## Documentation
Documentation can be found in the `docs` folder of the repo and on this [page](https://lorossi.github.io/customdataclass).
### Building the documentation
To build the documentation, simply run the following command from the `src` folder of the project:
```bash
pdoc --html -o ../docs customdataclass.py --force
```
## Contributing
Pull requests, bug reports and feature requests are more than welcome!
Thank you for your interest in this silly little project of mine!
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
Raw data
{
"_id": null,
"home_page": "",
"name": "customdataclass",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Lorenzo Rossi <pypi@lorenzoros.si>",
"download_url": "https://files.pythonhosted.org/packages/e1/df/b64ad6baf9f7034fadf9f9ebf1ee29ceb9403f26bcba16dcb2dfd5158372/customdataclass-0.1.2.tar.gz",
"platform": null,
"description": "# Customdataclass\n\n<p align=\"center\">\n<img src=https://img.shields.io/github/issues-raw/lorossi/customdataclass></img>\n<img src=https://img.shields.io/pypi/l/customdataclass></img>\n<img src=https://img.shields.io/pypi/pyversions/customdataclass></img>\n<img src=https://img.shields.io/pypi/v/customdataclass></img>\n<img src=https://img.shields.io/pypi/format/customdataclass></img>\n<img src=https://img.shields.io/badge/dynamic/json?color=informational&label=code%20coverage&query=totals.percent_covered_display&suffix=%25&url=https%3A%2F%2Fraw.githubusercontent.com%2Florossi%2Fcustomdataclass%2Fmain%2Fcoverage.json></img>\n<img src=https://img.shields.io/github/languages/top/lorossi/customdataclass></img>\n</p>\n\nCustom implementation of the `dataclass` module from the standard Python library as a base class for other dataclasses.\nThe documentation is available [here](https://lorossi.github.io/customdataclass).\n\n## Details\n\nA while back I was working on a project *(now lost in a dusty corner of my GitHub profile)* that required me to create a lot of data structures *(variables used only to hold complex data)* and I quickly realised that using dictionaries *(or named dictionaries)* was slowly becoming messy because:\n\n- dictionaries are mutable\n- dictionary keys are strings and there's no easy way to set a default value for a key\n- there's no way to ensure that a dictionary is well-formed\n- complex attributes that are needed once or twice cannot be generated on the fly and must be stored in the dictionary\n\nAfter a quick Google-fu session, I found out the existence of the `dataclass` decorator, swiftly provided by the `dataclasses`. This decorator allows you to create a class that is used only to hold data, and it provides a lot of useful features, such as:\n\n- default values for attributes\n- pre-determined methods *(such as `__init__`, `__repr__`, etc.)*\n\nHowever, it does not handle easily features like:\n\n- complex attributes *(i.e. attributes that are dataclasses themselves)*\n- nested dataclasses *(i.e. a dataclass that has another dataclass as an attribute)*\n- serialization and deserialization\n- hashing and equality\n- type checking\n- inheritance\n\nAll these were important for the project *(which once again will be finished, one day)* and so I decided to create a custom class that would handle all these features.\n\nI chose to create a class *(and not a decorator)* because I wanted to be able to inherit from it and to be able to use it as a base class for other dataclasses, thus solving the aforementioned problems.\n\n### Provided features\n\n- default values for attributes\n- type checking *(can be deactivated)*\n- nested dataclasses *(i.e. a dataclass that has another dataclass as an attribute)*\n- frozen dataclasses\n - a dataclass cannot be modified after its creation *(if the parameter `frozen` is set to `True`, as per default)*\n - otherwise, a dataclass can be manually frozen using the `freeze` method\n- equality comparison *(via the `__eq__` method)*\n- hashing *(via the `__hash__` method)*\n- full support inheritance\n- full support for methods overriding and custom properties\n\n## Installing\n\nThe package is available on PyPI and can be installed using `pip`:\n\n```bash\npip install -u customdataclass\n```\n\n## Examples\n\nExamples can be found in the `examples` folder, both in a text file [EXAMPLES.md](EXAMPLES.md) and in a set of Python scripts.\n\n## Tests\n\nUnit tests can be found in the `tests` folder.\nCurrently, the code coverage for unit tests is close to 100%.\n\n### Running the tests\n\nTo run the tests, simply run the following command from the root folder of the project:\n\n```bash\npython3 -m unittest discover -v -s ./tests -p \"test*.py\n```\n\nIf you're using VScode, you can also use the `Run Tests` command from the `Python Test Explorer for Visual Studio Code` extension.\n\n### Computing the coverage\n\nTo compute the coverage, simply run the following commands from the root folder of the project:\n\n- `coverage run -m unittest discover -s ./tests -p \"test*.py\"`\n- `coverage report -m` to see the report in the terminal\n- `coverage html` to see format the report in HTML and see it in the browser\n\n## Documentation\n\nDocumentation can be found in the `docs` folder of the repo and on this [page](https://lorossi.github.io/customdataclass).\n\n### Building the documentation\n\nTo build the documentation, simply run the following command from the `src` folder of the project:\n\n```bash\npdoc --html -o ../docs customdataclass.py --force\n```\n\n## Contributing\n\nPull requests, bug reports and feature requests are more than welcome!\n\nThank you for your interest in this silly little project of mine!\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A custom dataclass implementation",
"version": "0.1.2",
"project_urls": {
"Bug Tracker": "https://github.com/lorossi/customdataclass/issues",
"Homepage": "https://github.com/lorossi/customdataclass",
"documentation": "https://lorossi.github.io/customdataclass/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e0a5bf76e41e50c7186bf0892fa7cb30d6f38d3c45e9a29e4788a6b1e1d553c0",
"md5": "6e25b93dafd61da085b8437ee54c026e",
"sha256": "4cb76052e4e697a6f5216a25381f98bdb0afc2f41192125c2c87ebe69fa9eb6e"
},
"downloads": -1,
"filename": "customdataclass-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6e25b93dafd61da085b8437ee54c026e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8973,
"upload_time": "2023-10-30T16:19:33",
"upload_time_iso_8601": "2023-10-30T16:19:33.783561Z",
"url": "https://files.pythonhosted.org/packages/e0/a5/bf76e41e50c7186bf0892fa7cb30d6f38d3c45e9a29e4788a6b1e1d553c0/customdataclass-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e1dfb64ad6baf9f7034fadf9f9ebf1ee29ceb9403f26bcba16dcb2dfd5158372",
"md5": "399f41e86dcbf673e9fddd52ec7339cd",
"sha256": "88279e7fd033aeb72ae0d453c3e5a0f346231b51dbd402868f0517416fdb553c"
},
"downloads": -1,
"filename": "customdataclass-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "399f41e86dcbf673e9fddd52ec7339cd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13218,
"upload_time": "2023-10-30T16:19:35",
"upload_time_iso_8601": "2023-10-30T16:19:35.383657Z",
"url": "https://files.pythonhosted.org/packages/e1/df/b64ad6baf9f7034fadf9f9ebf1ee29ceb9403f26bcba16dcb2dfd5158372/customdataclass-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-30 16:19:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lorossi",
"github_project": "customdataclass",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "PyYAML",
"specs": [
[
"==",
"6.0.1"
]
]
},
{
"name": "toml",
"specs": [
[
"==",
"0.10.2"
]
]
},
{
"name": "ujson",
"specs": [
[
"==",
"5.8.0"
]
]
}
],
"lcname": "customdataclass"
}