Skip to main content

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

pip install dataclasses-hjson

Usage

Example adding config using the using_config decorator:

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:

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:

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 file for details.

Metadata

Release files for dataclasses-hjson 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataclasses-hjson 0.0.3
File Size Uploaded Provenance Actions
dataclasses_hjson-0.0.3.tar.gz 2.9 kB Without provenance Details for dataclasses_hjson-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dataclasses-hjson 0.0.3
File Interpreter ABI Platform Actions
dataclasses_hjson-0.0.3-py3-none-any.whl Python 3 none any Details for dataclasses_hjson-0.0.3-py3-none-any.whl

Total release size: 6.3 kB

Release files / dataclasses_hjson-0.0.3.tar.gz

Download URL dataclasses_hjson-0.0.3.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
77f041d4e37bd1c111593304c77a5381d1805a128d6d3743a517e80322a877f7
BLAKE2b-256 checksum
How to use checksums
94fc411d3ff44d5ba2d1bfff5d5e099b6f3322644bd0ef677d95574c2e7f0747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.5 Windows/10

Release files / dataclasses_hjson-0.0.3-py3-none-any.whl

Download URL dataclasses_hjson-0.0.3-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d41920c324ad87f4f9fc3ed5e84189501261c24546b61b92f8297126e99ab885
BLAKE2b-256 checksum
How to use checksums
267106f50508612814e05ddfa6d950b018b7e3599b3bda0ee661e0776500d629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.5 Windows/10

Security for dataclasses-hjson 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page