Skip to main content

Environment Wrapped TOML

Project description

TOMLenv

GitHub Workflow Status PyPI - Version PyPI - Python Version PyPI - Downloads License

Environment wrapped TOML.

Package available in PyPI.

Getting Started

Install the library

Using pip:

$ pip install tomlenv

Using pipenv:

$ pipenv install tomlenv

Using poetry:

$ poetry add tomlenv

Basic Usage

Tomlenv takes advantage of modern Python features such as dataclasses and tomllib to create a simple yet powerful configuration library.

By default, tomlenv looks for a config.toml file in your project root:

token = "dev"
debug = false

Assuming this environment variable is set:

TOMLENV_DEBUG=true

Create your configuration dataclass and parse config and env into it:

import tomlenv
from dataclasses import dataclass

@dataclass
class Config:
    token: str = ''
    debug: bool = False

config = Config()
parser = tomlenv.Parser()

parser.load(config)

# You can now access the fields of your fully typed config Class
# that contains values from a TOML config file and the environment.

# For example:

token = config.token
debug = config.debug
print(token) # prints "dev"
print(debug) # prints True

Configuration

To configure the location of your toml file, set TOMLENV_CONF_FILEPATH.

For example if your config file is in configs/config.toml relative to the project root, then set TOMLENV_CONF_FILEPATH=configs/config.toml

Tests

This project uses Poetry and GNU Make.

Run tests from the project root with:

$ make test

To get a coverage report:

$ make cov

Issues

Feel free to send issues or suggestions to https://github.com/joaonsantos/tomlenv/issues.

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

tomlenv-0.2.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

tomlenv-0.2.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file tomlenv-0.2.2.tar.gz.

File metadata

  • Download URL: tomlenv-0.2.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Linux/5.15.0-1031-azure

File hashes

Hashes for tomlenv-0.2.2.tar.gz
Algorithm Hash digest
SHA256 79c2a81ee7b84a2917747a087f61ffaf89c8d74ab3a785c768bc97cc32548cd7
MD5 5643c6e67874b85fefa11ca17d7b0f31
BLAKE2b-256 4bb19390fde3564e44e14e012d02ef81786332f54e14a735b64d953644ee7c70

See more details on using hashes here.

File details

Details for the file tomlenv-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: tomlenv-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Linux/5.15.0-1031-azure

File hashes

Hashes for tomlenv-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05525cd3f026c8f1624dc2e5c1704c38d8877598ece4961a9f4640b335410a41
MD5 6649801e84ddddef31463a2bb1905d0c
BLAKE2b-256 691521bb30a4480c885004a99746f489fcb53bac598faab8cea20514f22c295b

See more details on using hashes here.

Supported by

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