Skip to main content

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

Project description

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

This project uses uv. After installing it, run the following from the project’s root directory:

uv sync --group dev
uv run pytest

For coverage:

uv run pytest --cov=envtoml

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envtoml-0.1.3.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envtoml-0.1.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file envtoml-0.1.3.tar.gz.

File metadata

  • Download URL: envtoml-0.1.3.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for envtoml-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8e3cc5dd79232e108d15f97727207bea6fd2f50a0cba441632cff6bcffa36249
MD5 d89fe7c30a46bfc49b928ba495cd4b66
BLAKE2b-256 5de40ef8a9f44b8b3c3e750fc9bf9ee16f78d4d9b7dbac24494cafa452cbe453

See more details on using hashes here.

File details

Details for the file envtoml-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: envtoml-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for envtoml-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ce0d5257743b2e07da92a0a051d7320e36f72d5e425245912daf4ad0865de5d
MD5 fb9539aaff2c9ce13b87708e5c6d9b16
BLAKE2b-256 5f8efbd6b90718ca7e06bc33121514f7e5279d86360f7dd1b0560779e8c096c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page