Skip to content
/ envtoml Public

A simple way of using environment variables in TOML configs (via interpolation)

License

Notifications You must be signed in to change notification settings

mrshu/envtoml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envTOML

PyPI Status Build Status Code coverage Status License Status

envTOML is an answer to a fairly simple problem: including values from environment variables in TOML configuration files. In this way, it is very similar to both envyaml and varyaml which provide very similar functionality for YAML and which greatly inspired this small package.

Example

Suppose we have the following configuration saved in config.toml

[db]
host = "$DB_HOST"
port = "$DB_PORT"
username = "$DB_USERNAME"
password = "$DB_PASSWORD"
name = "my_database"

with the environment variables being set to the following

DB_HOST=some-host.tld
DB_PORT=3306
DB_USERNAME=user01
DB_PASSWORD=veryToughPas$w0rd

this config can then be parsed with envTOML in the following way:

import envtoml

cfg = envtoml.load(open('./config.toml'))

print(cfg)
# {'db': {'host': 'some-host.tld',
#   'port': 3306,
#   'username': 'user01',
#   'password': 'veryToughPas$w0rd',
#   'name': 'my_database'}}

Tests

As this project makes use of Poetry, after installing it the tests can be ran by executing the following from the project's root directory:

poetry run nosetests tests

They can also be ran with coverage:

poetry run nosetests --with-coverage tests

License

Licensed under the MIT license (see LICENSE file for more details).

Releases

No releases published

Packages

No packages published

Languages