Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata for configuration data point #838

Open
ThomDietrich opened this issue Nov 28, 2022 · 5 comments
Open

Metadata for configuration data point #838

ThomDietrich opened this issue Nov 28, 2022 · 5 comments

Comments

@ThomDietrich
Copy link

Hey friends,
does Dynaconf support metadata alongside it's managed configuration? How would one go about adding further details about a data point? Examples would be the owner or source of a setting, range and restrictions, or a short description for UI explanation.

For my specific use case (data science lab work) I would prefer metadata alongside the value, however I can see that for many production software this might probably find its way into another related file in parallel.

Is there any support for metadata in the context of Dynaconf or would you guys have a recommendation for a best practice solution? Thanks!

@rochacbruno
Copy link
Member

This must be resolved with the 4.0 implementation of typing #683

@rochacbruno
Copy link
Member

Now with #1107 we can add Annotated[T, Metadata(x=y)]

@ThomDietrich
Copy link
Author

Hey Bruno,
fond to see this ticket is still considered.

Without deeper study of the change I am unsure whether this indeed resolves my question. I was hoping for the ability to add metadata in the settings.{toml|yaml|ini|json|py} file itself or a second file in parallel. The ability to do value validation is one obvious use case, but I would also find it useful to add documentation per parameter, e.g. for UI presentation or to show alongside a validation error.

I have to add that I am not a full-time software developer or current user of dynaconf. This ticket is from two years ago when I was happy to have found dynaconf and confused by the lack of metadata :)

Does that make sense? Cheers!

@rochacbruno
Copy link
Member

rochacbruno commented Jul 1, 2024

Hi @ThomDietrich, yes I think the new schema based settings will be the way to solve the issue

Example:

class Settings(Dynaconf):
    host: Annotated[str, Description("The server hostname"), Metadata(foo="bar")]
    post: Annotated[int, Description("Server port")] = 5050

With a schema class like the one above you will be able to run:

$ dynaconf template-settings-file yaml > settings.yaml

IT will output

# The server hostname
# foo: bar
# required: true
# type: str
host:

# Server port
# type: int
port: 5050

So with the information in a schema on a .py file we will be able to dump the information to multiple purposes, can be templating the settings file as above or generating a json-schema for UI purposes.

@ThomDietrich
Copy link
Author

I see. Amazing!! That looks great and does solve my request. If this is already documented please feel free to close the ticket :) Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants