Skip to content

Suggestion: Use pydantic for configs #48

@MaciejKaszynski

Description

@MaciejKaszynski

Would be nice to have the configs structure in the code

Right now we are deserializing the config data dynamically:

def _dict_to_obj(data):
"""
Recursively convert a dictionary to an object with attributes.
Lists of dictionaries are converted to lists of objects.
"""
if isinstance(data, dict):
return SimpleNamespace(**{key: _dict_to_obj(value) for key, value in data.items()})
elif isinstance(data, list):
return [_dict_to_obj(item) for item in data]
else:
return data

I think having the structure described by the code is nice for self documenting code + validation of the config.

Pydantic is a common library for this however it would introduce another dependency.
Alternatively there are ways to do this without dependencies:
https://stackoverflow.com/a/72013768

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions