Registry / serialization / pytoolconfig

pytoolconfig

JSON →
library1.3.1pypypi✓ verified 25d ago

pytoolconfig is a Python library designed for simple and declarative definition of tool configurations, typically read from `pyproject.toml` or other config files. It provides a `ToolConfig` class to define configuration schemas with type hints and default values. The current version is 1.3.1, and it maintains a moderate release cadence, with minor updates every few months addressing features and maintenance.

pip install pytoolconfig
INSTALL
IMPORT
SIG · PYTOOLCONFIG
P
pytoolconfig
serializationpythonv1.3.1
Install
1.7s avg
Import
178ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.184s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.172s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PyToolConfig
from pytoolconfig import PyToolConfig
from pytoolconfig import ToolConfig

This quickstart demonstrates how to define a configuration schema using `ToolConfig` and `Field`. It then shows how to load configuration data, respecting default values and showing how environment variables or file-based settings would override defaults. `pytoolconfig` automatically looks for configuration in various places like `pyproject.toml` or `.{app_name}.yaml` when `ToolConfig.load()` is called without `config_data`.

from pytoolconfig import ToolConfig, Field import os # Define your configuration schema class MyToolConfig(ToolConfig): project_name: str = Field(default="my-default-project", help="Name of the project") debug_mode: bool = Field(default=False, help="Enable debug logging") output_dir: str = Field(default="./output", help="Directory for output files") # Simulate a configuration file (e.g., .toolconfig.yaml or pyproject.toml) # In a real scenario, this would be loaded from disk. # For demonstration, we'll manually create a dummy config. # In practice, `from_file`, `from_pyproject`, or `load` would be used. # Example of loading from a dictionary, simulating file content: dummy_config_data = { "tool": { "mytool": { "project_name": os.environ.get("MYTOOL_PROJECT_NAME", "override-from-env"), "debug_mode": True } } } # Load configuration for 'mytool' # The library would typically discover this automatically from `load()` or `from_pyproject()` config = MyToolConfig.load(app_name="mytool", config_data=dummy_config_data) print(f"Project Name: {config.project_name}") print(f"Debug Mode: {config.debug_mode}") print(f"Output Directory: {config.output_dir}") # Demonstrating default value for output_dir which was not in dummy_config_data assert config.output_dir == "./output" # Demonstrating override from dummy_config_data (or environment variable if set) assert config.project_name == (os.environ.get("MYTOOL_PROJECT_NAME", "override-from-env")) assert config.debug_mode is True
Debug
Known issues
breakingPython 3.7 support has been officially dropped starting with version 1.3.1. Users on Python 3.7 will need to upgrade their Python interpreter to 3.8 or newer to use the latest versions of pytoolconfig.
fix
Upgrade Python to version 3.8 or higher. If unable to upgrade, pin pytoolconfig to `<1.3.1` (e.g., `pytoolconfig<1.3.1`).
affects: >=1.3.1
gotchaWhen using `ToolConfig.load()`, pytoolconfig attempts to load configuration from multiple sources (e.g., command line arguments, environment variables, configuration files like `pyproject.toml` or `.{app_name}.yaml`). The order of precedence for these sources can be crucial and might lead to unexpected values if not understood.
fix
Consult the official documentation for the precise loading order. Typically, CLI arguments take precedence over environment variables, which take precedence over configuration files, which in turn override schema defaults. Explicitly pass `config_data` to `ToolConfig.load()` for specific control.
affects: All versions
gotchaThe `Field` object from `pytoolconfig` is used to provide metadata (like `default` and `help`) alongside type hints. Users familiar with `dataclasses.field` or `pydantic.Field` should note the specific parameters and behavior, as they may not be fully interchangeable.
fix
Always import `Field` from `pytoolconfig` and refer to `pytoolconfig`'s documentation for the correct arguments and usage, especially for `default` and `default_factory`.
affects: All versions
Upgrade
Version history
1.3.1latest on PyPI · released Jan 11, 2024
Audit
Dependencies
typing_extensionsrequiredRequired for Python versions < 3.9 for `pytoolconfig`'s type hinting features. Pip handles conditional installation automatically.
Agent activity
11 hits · last 30 days
node
10
Resources
pytoolconfig — pip install pytoolconfig · libregistry