Skip to content

Conversation

@pgjones
Copy link
Member

@pgjones pgjones commented Oct 11, 2019

TOML is a very popular format now, and is taking hold in the Python
ecosystem via pyproject.toml (among others). This adds toml as an
extra dependency usuable if installed with the toml extra.

I've recently added similar code in Quart and I've been using toml configs with Flask and Quart for some time now. In my view TOML has crossed a threshold of usage to warrant direct support in Flask.

TOML is a very popular format now, and is taking hold in the Python
ecosystem via pyproject.toml (among others). This adds toml as an
extra dependency usuable if installed with the toml extra.
@davidism
Copy link
Member

I'm not super happy that from_json got in in the first place. The intention of Flask's built-in config always appeared to be that it should be Python. JSON is less expressive and more verbose, and while TOML is more expressive it still doesn't cover the types of config that are common now, such as loading values from the environment.

On the other hand, config.from_* does offer some functionality over loading a file yourself. Maybe we need a compromise instead, such as from_file(name, load_func)? That way anyone can use whatever loader they want, rather than having to write another function for each format.

@davidism
Copy link
Member

In a weird coincidence, here's a tweet from @jakevdp saying the same thing: https://twitter.com/jakevdp/status/1183241890289741825

@pgjones
Copy link
Member Author

pgjones commented Oct 13, 2019

I see this as a question of convenience and that there is a tipping point when something is so commonly used as warrant direct inclusion. Whilst it isn't clear, I think from_json reached this point in the community and adding it saved users writing very similar repeated code. My view is that TOML has also reached this point.

I think that from_mapping could work as the generic loader, in that you can do something like,

data = toml.load(something)
app.config.from_mapping(data)

although it doesn't include the useful error handling I presume from_file would.

@carc1n0gen
Copy link

Just wanted to add I really like using json files to configure flask. I prefer config files to not be executed code. Allowing any format the developer wants sounds like a cool idea.

@pgjones
Copy link
Member Author

pgjones commented Oct 15, 2019

See #3398 as the potentially better solution.

@davidism
Copy link
Member

Thanks, closing in favor of #3398.

@davidism davidism closed this Oct 15, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants