Dataclass to be CLI and logger compatible
Project description
Dataclass to be CLI and logger compatible
This package does only two things:
- it takes a dataclass and converts it to a command line str.
- it takes a dataclass and converts it to a loggable dict for 3rd party logging like MLFlow.
Contrary to
asdictit also converts nested dataclasses by separting their attributes by prefix.
By inheriting from the class ReverseCli you can use the to_command_string method to get the command line str and the property loggable_dict to get the loggable dict.
Example
@dataclass(kw_only=True)
class Parameters(ReverseCli):
a: int
b: str
c: bool
d: list[int]
@dataclass(kw_only=True)
class Nested(ReverseCli):
a: int
b: Parameters
parameters = Nested(a=1, b=Parameters(a=1, b="2", c=True, d=[3, 4]))
print(parameters.to_command_string())
# --a 1 --b.a 1 --b.b 2 --b.c --b.d 3 --b.d 4
print(parameters.loggable_dict)
# {'a': 1, 'b.a': 1, 'b.b': '2', 'b.c': True, 'b.d': [3, 4]}
Installation
We use UV for installation and RUFF for formating and linting.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dataclasses_reverse_cli-0.0.7.tar.gz.
File metadata
- Download URL: dataclasses_reverse_cli-0.0.7.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a56b68a6286814c6e2ed0e0224b73bca98de86d7536bc9ea9339f607c1ba6cdc
|
|
| MD5 |
044cc0a7da9f954f060649783dda7803
|
|
| BLAKE2b-256 |
64f0e5fe4394b5b0470f575d1d3a393c464f4f1899426ab16df0b18d96888783
|
File details
Details for the file dataclasses_reverse_cli-0.0.7-py3-none-any.whl.
File metadata
- Download URL: dataclasses_reverse_cli-0.0.7-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea6ab7341172f5071225e71245f200a38ea4dd5ae2cff6efccb70696a6b7733b
|
|
| MD5 |
a1a3b5286ef4bf92aeaed7c35dcae1a4
|
|
| BLAKE2b-256 |
56a4872d435a34d458c7afd0898801c9de9cea4aa5e3f7c10ade21ef2b1726ee
|