Skip to main content

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

Project description

PyPI Status Python Versions Wheel Status PyPI Downloads 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.

Under the hood it uses the standard library tomllib (and tomli as a fallback for Python < 3.11).

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', 'rb'))

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

To fail when a referenced env var is missing, pass fail_on_missing=True:

cfg = envtoml.load(open('./config.toml', 'rb'), fail_on_missing=True)

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.3.0.tar.gz (45.9 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.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: envtoml-0.3.0.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for envtoml-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d909f0c98aaab15060904eca124c053e5e27c87e4c01900f3548b483aabcd789
MD5 6eb09623369029c199c14c44aab8e6e5
BLAKE2b-256 ea77df8c14c250fafa30bea51b339572f7371708515fcec6ee4117dbf5b919cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envtoml-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for envtoml-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a78f453e9c119bac68a963e592f1ca1a3b1d537b1475a196a4129daf7986f15
MD5 ea3ed163c0ead4d66d953ff0ad98d102
BLAKE2b-256 931265326fe6b4f3dc30118d23e8000c3d168164ef65188acf583b4a178273a8

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