1
0
Fork
You've already forked dataclasses-reverse-cli
2
Dataclass to be CLI and logger compatible
  • Python 100%
Malcolm Mielle 55bcb8fbd6
All checks were successful
Python / Test (pull_request) Successful in 36s
Publish to Pypi / Lint and Install (release) Successful in 32s
Update pipelines
2025年12月16日 10:14:55 +01:00
.forgejo/workflows Update pipelines 2025年12月16日 10:14:55 +01:00
.vscode first commit 2025年06月01日 19:38:51 +02:00
dataclasses_reverse_cli Fix spaced strings parsing 2025年12月15日 17:10:00 +01:00
tests Fix spaced strings parsing 2025年12月15日 17:10:00 +01:00
.gitignore Add the abillity to ignore some attributes 2025年07月03日 20:34:53 +02:00
.python-version first commit 2025年06月01日 19:38:51 +02:00
LICENSE.md Add LICENSE and urls 2025年06月01日 22:18:36 +02:00
pyproject.toml Add the abillity to ignore some attributes 2025年07月03日 20:34:53 +02:00
README.md first commit 2025年06月01日 19:38:22 +02:00
uv.lock Add the abillity to ignore some attributes 2025年07月03日 20:34:53 +02:00

Dataclass to be CLI and logger compatible

This package does only two things:

  1. it takes a dataclass and converts it to a command line str.
  2. it takes a dataclass and converts it to a loggable dict for 3rd party logging like MLFlow. Contrary to asdict it 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.