A simple way of using environment variables in TOML configs (via interpolation)
Project description
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file envTOML-0.1.2.tar.gz
.
File metadata
- Download URL: envTOML-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.2 Linux/5.2.13-200.fc30.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c26e2a5e42b66d106ea7d6f7e2f993f7cbdd659837ffbc4a3dd8b68fa81f13 |
|
MD5 | b87fe0e68d067b0b78a6e313e9a45e3f |
|
BLAKE2b-256 | 7eff79aca9f9bf863d01aa1f2eb74a84ce3592fd528955decacfdae3922ed134 |
File details
Details for the file envTOML-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: envTOML-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.2 Linux/5.2.13-200.fc30.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f376003d907f02f623da82eaba98e287c03f10db0a9a0160adb8caf26256530 |
|
MD5 | 5d2fa09478eea26b48ac86e29bff3932 |
|
BLAKE2b-256 | 1a00d20326dd348b0ef0948003391278976d050b5e56b6c6ccebe61fa9776033 |