toml-lang / toml

Tom's Obvious, Minimal Language

Home Page:https://toml.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to import keys from another TOML file

venukasturi opened this issue · comments

Hi, we are planning to use TOML files for our python server's application configuration.
We would have different environments - production, staging, dev, local etc.

There would be a few keys different in each of the environments but majority of them would be the same.
Our goal is to do something like the following:

production.toml

`
service_name = "Friends.service"

environment = "production"

resource_A_url = "https://prod.resourceA.com"

cache_type_to_use = "redis"
`

staging.toml
`
import "production.toml"

environment = "staging"
resource_A_url = "https://prod.resourceA.com"
`

local.toml
`
import "production.toml"

environment = "local"
resource_A_url = "http://localhost:5252"
cache_type_to_use = "disk"
`

Is it possible to define such type of a hierarchy / inheritance structure using TOML files? If not, can you please recommend some open source alternatives that we can use?

Thank you.

A TOML parser by itself will never read any other file than the one you requested – and I'd say that's a feature, not a bug. It certainly makes TOML more predictable and secure.

But you can easily get the functionality you want by reading first a defaults file (production.toml in your example), then your primary TOML file, and then merging the two. See this recent discussion on how to do this – in Python, at least, it's trivially easy.