Skip to main content

No project description provided

Project description

TOMFIG - Toml Config

The simplest TOML config manager for python!

This module borrows a little from config. The only argument needed during initialization is the config_path.

from tomfig import Config

# defaults to [cwd]/config
config = Config(config_path='/dir/with/config_files')

The module then loads configuration files and merges down the configs in the following order.

  1. default.toml
  2. [environment_config].toml where environment is whatever you pass to your script via the ENV environment variable. Default is development.toml

Accessing Config Values

There are two ways of accessing config values.

Imagine we have the following config file:

[APP]
name="My App"

[TOOLS.language-support]
python=">3.8"

[SERVER.API]
domain="localhost:3000/default"

1. Direct/Data Access

You can access config values directly using dot notation via the data property as follows.

config.data.APP.name 
# "My App"

However, this method is discouraged on production. This is because, if a key is missing, it returns None instead of throwing an error.

That behaviour is however intentional as it allows us an eay way to check is a config value exists. For example:

# Check if our app has a name
if not config.data.APP.name:
    # Use AI to generate and set APP name 

2. Safe/Get Access

This is the preferred method to access config values. This method immediately throws if a certain value is missing.

config.get("SERVER.API.domain")
# "localhost:3000/development"

Have a look at the tests for examples.

Thoughts

I have not implemented a .set() method and don't plan to. It is my considered view that configs should be static and only changed in the config files to ensure code functions in a predictable, easy to debug manner.

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

tomfig-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

tomfig-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file tomfig-0.1.0.tar.gz.

File metadata

  • Download URL: tomfig-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-73-generic

File hashes

Hashes for tomfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7b973dda53c88be860c621d5cb19145dc8bdf5344528de254d7c5aec78975aca
MD5 ae63b4b2a65b52c907067891bc36f657
BLAKE2b-256 9027c7a6bdfec013027e36f58bd1fa9b7d15d30880d04de65a09300bb37f3296

See more details on using hashes here.

File details

Details for the file tomfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tomfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-73-generic

File hashes

Hashes for tomfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed4167ca4c93e990f94108091e15072afa2efff32d16c295d9f8dd916f67f7eb
MD5 49b3bafc90cd35abb76d5ffeaa2e700d
BLAKE2b-256 def1552f150751eb9d636f3a08677f3e648ff3b297ad4b5198aec35e83efa40d

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