dataclasses-hjson


Namedataclasses-hjson JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/J0J0HA/dataclasses-hjson
SummaryA simple mixin that adds .to_hjson and .from_hjson to the dataclasses-json mixin
upload_time2024-04-03 18:16:31
maintainerNone
docs_urlNone
authorJ0J0HA
requires_python<4.0,>=3.7
licenseMIT
keywords dataclasses json hjson
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dataclasses-hjson

This package provides a simple way to serialize and deserialize dataclasses to and from Hjson.

This uses ``dataclasses-json`` to serialize and deserialize dataclasses, and ``hjson`` to parse and generate Hjson.

Opposed to ``dataclasses-json``, this package does only provide a mixin class to add the functionality to a dataclass, instead of a decorator. You can change the configuration of ``dataclasses-json`` by either using the ``using_config`` decorator or by manually setting the ``dataclasses_json_config`` attribute on the dataclass, using the ``hjson_config`` function.

If you have any problems, ideas or suggestions, feel free to open an issue or a pull request!

## Installation

```bash
pip install dataclasses-hjson
```

## Usage

Example adding config using the ``using_config`` decorator:

```python
from dataclasses import dataclass
from dataclasses_json import Undefined, LetterCase
from dataclasses_hjson import DataClassHjsonMixin, using_config


@using_config(
    undefined=Undefined.EXCLUDE, letter_case=LetterCase.CAMEL
)  # (These are the default values)
@dataclass
class Person(DataClassHjsonMixin):
    first_name: str
    age: int

```

Alternatively, you can use the ``hjson_config`` function:

```python
from dataclasses import dataclass
from dataclasses_json import Undefined, LetterCase
from dataclasses_hjson import DataClassHjsonMixin, hjson_config


@dataclass
class Person(DataClassHjsonMixin):
    dataclasses_json_config = hjson_config(undefined=Undefined.EXCLUDE, letter_case=LetterCase.CAMEL) # (These are the default values)

    first_name: str
    age: int
```

Adding the config is optional however!

Now you can serialize and deserialize the dataclass to and from Hjson:

```python
person = Person(first_name="Guido", age=42)
person_json = person.to_hjson()
print(person_json)
# {
#   firstName: Guido
#   age: 42
# }
person_copy = Person.from_hjson(person_json)
print(person_copy)
# Person(name='Guido', age=42)

```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/J0J0HA/dataclasses-hjson",
    "name": "dataclasses-hjson",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "dataclasses, json, hjson",
    "author": "J0J0HA",
    "author_email": "johannes@jojojux.de",
    "download_url": "https://files.pythonhosted.org/packages/94/fc/411d3ff44d5ba2d1bfff5d5e099b6f3322644bd0ef677d95574c2e7f0747/dataclasses_hjson-0.0.3.tar.gz",
    "platform": null,
    "description": "# dataclasses-hjson\n\nThis package provides a simple way to serialize and deserialize dataclasses to and from Hjson.\n\nThis uses ``dataclasses-json`` to serialize and deserialize dataclasses, and ``hjson`` to parse and generate Hjson.\n\nOpposed to ``dataclasses-json``, this package does only provide a mixin class to add the functionality to a dataclass, instead of a decorator. You can change the configuration of ``dataclasses-json`` by either using the ``using_config`` decorator or by manually setting the ``dataclasses_json_config`` attribute on the dataclass, using the ``hjson_config`` function.\n\nIf you have any problems, ideas or suggestions, feel free to open an issue or a pull request!\n\n## Installation\n\n```bash\npip install dataclasses-hjson\n```\n\n## Usage\n\nExample adding config using the ``using_config`` decorator:\n\n```python\nfrom dataclasses import dataclass\nfrom dataclasses_json import Undefined, LetterCase\nfrom dataclasses_hjson import DataClassHjsonMixin, using_config\n\n\n@using_config(\n    undefined=Undefined.EXCLUDE, letter_case=LetterCase.CAMEL\n)  # (These are the default values)\n@dataclass\nclass Person(DataClassHjsonMixin):\n    first_name: str\n    age: int\n\n```\n\nAlternatively, you can use the ``hjson_config`` function:\n\n```python\nfrom dataclasses import dataclass\nfrom dataclasses_json import Undefined, LetterCase\nfrom dataclasses_hjson import DataClassHjsonMixin, hjson_config\n\n\n@dataclass\nclass Person(DataClassHjsonMixin):\n    dataclasses_json_config = hjson_config(undefined=Undefined.EXCLUDE, letter_case=LetterCase.CAMEL) # (These are the default values)\n\n    first_name: str\n    age: int\n```\n\nAdding the config is optional however!\n\nNow you can serialize and deserialize the dataclass to and from Hjson:\n\n```python\nperson = Person(first_name=\"Guido\", age=42)\nperson_json = person.to_hjson()\nprint(person_json)\n# {\n#   firstName: Guido\n#   age: 42\n# }\nperson_copy = Person.from_hjson(person_json)\nprint(person_copy)\n# Person(name='Guido', age=42)\n\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple mixin that adds .to_hjson and .from_hjson to the dataclasses-json mixin",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/J0J0HA/dataclasses-hjson",
        "Repository": "https://github.com/J0J0HA/dataclasses-hjson"
    },
    "split_keywords": [
        "dataclasses",
        " json",
        " hjson"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "267106f50508612814e05ddfa6d950b018b7e3599b3bda0ee661e0776500d629",
                "md5": "7155fa0a38e2799a1e9dc507b2f191d8",
                "sha256": "d41920c324ad87f4f9fc3ed5e84189501261c24546b61b92f8297126e99ab885"
            },
            "downloads": -1,
            "filename": "dataclasses_hjson-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7155fa0a38e2799a1e9dc507b2f191d8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 3352,
            "upload_time": "2024-04-03T18:16:29",
            "upload_time_iso_8601": "2024-04-03T18:16:29.826371Z",
            "url": "https://files.pythonhosted.org/packages/26/71/06f50508612814e05ddfa6d950b018b7e3599b3bda0ee661e0776500d629/dataclasses_hjson-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94fc411d3ff44d5ba2d1bfff5d5e099b6f3322644bd0ef677d95574c2e7f0747",
                "md5": "d67724e8e51ff763a0dde30cac41a6a7",
                "sha256": "77f041d4e37bd1c111593304c77a5381d1805a128d6d3743a517e80322a877f7"
            },
            "downloads": -1,
            "filename": "dataclasses_hjson-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d67724e8e51ff763a0dde30cac41a6a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 2916,
            "upload_time": "2024-04-03T18:16:31",
            "upload_time_iso_8601": "2024-04-03T18:16:31.020609Z",
            "url": "https://files.pythonhosted.org/packages/94/fc/411d3ff44d5ba2d1bfff5d5e099b6f3322644bd0ef677d95574c2e7f0747/dataclasses_hjson-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-03 18:16:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "J0J0HA",
    "github_project": "dataclasses-hjson",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dataclasses-hjson"
}
        
Elapsed time: 0.21971s