Skip to main content

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.

Metadata

Release files for tomfig 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tomfig 0.1.0
File Size Uploaded Provenance Actions
tomfig-0.1.0.tar.gz 3.5 kB Without provenance Details for tomfig-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tomfig 0.1.0
File Interpreter ABI Platform Actions
tomfig-0.1.0-py3-none-any.whl Python 3 none any Details for tomfig-0.1.0-py3-none-any.whl

Total release size: 7.8 kB

Release files / tomfig-0.1.0.tar.gz

Download URL tomfig-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7b973dda53c88be860c621d5cb19145dc8bdf5344528de254d7c5aec78975aca
BLAKE2b-256 checksum
How to use checksums
9027c7a6bdfec013027e36f58bd1fa9b7d15d30880d04de65a09300bb37f3296
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-73-generic

Release files / tomfig-0.1.0-py3-none-any.whl

Download URL tomfig-0.1.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed4167ca4c93e990f94108091e15072afa2efff32d16c295d9f8dd916f67f7eb
BLAKE2b-256 checksum
How to use checksums
def1552f150751eb9d636f3a08677f3e648ff3b297ad4b5198aec35e83efa40d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-73-generic

Security for tomfig 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page