Skip to main content

pyutil-cfg

python utilility for configurations.

This package helps parsing .toml configurations and json-like configurations in .ini.

Usage

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename)

File Formats

.toml

For the .toml files, the format follows TOML specification.

You can check production.tmpl.toml or test/data for more details.

.ini

For the .ini files, you can check production.tmpl.ini or test/data for more details.

Assume that you have the following development.ini:

[demo]
VAR_INT = 1
VAR_BOOL = true
VAR_DICT = {"A": 1, "B": "a"}
VAR_LIST = [
    {"A": 2, "B": "b"},
    {"A": 3, "B": "c"},
    {"A": 4, "B": "d"}]

Then with the following code:

import pyutil_cfg as cfg

logger, config = cfg.init('demo', 'development.ini')

logger is a logger with name = 'demo'

config ia as follow:

config = {
    "VAR_INT": 1,
    "VAR_BOOL": true,
    "VAR_DICT": {"A": 1, "B": "a"},
    "VAR_LIST": [
        {"A": 2, "B": "b"},
        {"A": 3, "B": "c"},
        {"A": 4, "B": "d"}
    ],
}

Advanced Usage

Separated log configuration filename

import pyutil_cfg as cfg


logger, config = cfg.init(name, filename, log_name, log_filename)

With default parameters

import pyutil_cfg as cfg

default_params = {'test_params': 'default'}

logger, config = cfg.init(name, filename, default_params=default_params)

Additional customized config parameters (specified as dict)

import pyutil_cfg as cfg

extra_params = {'test_params': 'test'}

logger, config = cfg.init(name, filename, extra_params=extra_params)

Ok if extra parameters are already in the configuration file (default: True)

It is usual that we would like to temporarily change the configuration settings through command-line variables.

Because usually we still want to continue the process even if the extra parmeters are accidentally in the configuration file. Only warning logs if this parameter is set as False and some extra parameters are already in configuration file.

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename, is_extra_params_in_file_ok=True)

Skip extra parameters if already in the configuration file. (default: False)

Skip extram parameters if they are already in the configuration file.

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename, is_skip_extra_params_in_file=True)

Show configuration before returning. (default: False)

Setup the log-level to show the computed configurations before return. None as no-show.

Do not show the configuration before return.

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename)

Show the configruration if the logger is set to logging.DEBUG

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename, show_config=logging.DEBUG)

Show the configuration if the logger is set to logging.INFO or logging.DEBUG.

import pyutil_cfg as cfg

logger, config = cfg.init(name, filename, show_config=logging.INFO)

Misc

  • Reason retaining pyutil_ prefix: cfg is an extremely common name. Retaining pyutil_ to avoid naming conflict.
  • Reason not including .json: not a good file format for config.
  • Reason not including .yaml: not the standard library.

Metadata

Release files for pyutil-cfg 0.2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for pyutil-cfg 0.2.0
File Interpreter ABI Platform Actions
pyutil_cfg-0.2.0-py3-none-any.whl Python 3 none any Details for pyutil_cfg-0.2.0-py3-none-any.whl

Release files / pyutil_cfg-0.2.0-py3-none-any.whl

Download URL pyutil_cfg-0.2.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cc98894e83c6289c61be0e3bfafcb74c904b4fffa8b5417460e2dbd40ce49a4
BLAKE2b-256 checksum
How to use checksums
93a1f8f20e8e9972cee5e792369ce3406137624b782fda59b3432edde0d97513
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for pyutil-cfg 0.2.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.

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