{"id":4388,"library":"pytoolconfig","title":"Python Tool Configuration","description":"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.","status":"active","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/bageljrkhanofemus/pytoolconfig","tags":["configuration","tooling","schema","cli","declarative"],"install":[{"cmd":"pip install pytoolconfig","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Python versions < 3.9 for `pytoolconfig`'s type hinting features. Pip handles conditional installation automatically.","package":"typing_extensions","optional":false}],"imports":[{"symbol":"ToolConfig","correct":"from pytoolconfig import ToolConfig"},{"note":"All core components are exposed directly under the top-level `pytoolconfig` package.","wrong":"from pytoolconfig.field import Field","symbol":"Field","correct":"from pytoolconfig import Field"}],"quickstart":{"code":"from pytoolconfig import ToolConfig, Field\nimport os\n\n# Define your configuration schema\nclass MyToolConfig(ToolConfig):\n    project_name: str = Field(default=\"my-default-project\", help=\"Name of the project\")\n    debug_mode: bool = Field(default=False, help=\"Enable debug logging\")\n    output_dir: str = Field(default=\"./output\", help=\"Directory for output files\")\n\n# Simulate a configuration file (e.g., .toolconfig.yaml or pyproject.toml)\n# In a real scenario, this would be loaded from disk.\n# For demonstration, we'll manually create a dummy config.\n# In practice, `from_file`, `from_pyproject`, or `load` would be used.\n\n# Example of loading from a dictionary, simulating file content:\ndummy_config_data = {\n    \"tool\": {\n        \"mytool\": {\n            \"project_name\": os.environ.get(\"MYTOOL_PROJECT_NAME\", \"override-from-env\"),\n            \"debug_mode\": True\n        }\n    }\n}\n\n# Load configuration for 'mytool'\n# The library would typically discover this automatically from `load()` or `from_pyproject()`\nconfig = MyToolConfig.load(app_name=\"mytool\", config_data=dummy_config_data)\n\nprint(f\"Project Name: {config.project_name}\")\nprint(f\"Debug Mode: {config.debug_mode}\")\nprint(f\"Output Directory: {config.output_dir}\")\n\n# Demonstrating default value for output_dir which was not in dummy_config_data\nassert config.output_dir == \"./output\"\n# Demonstrating override from dummy_config_data (or environment variable if set)\nassert config.project_name == (os.environ.get(\"MYTOOL_PROJECT_NAME\", \"override-from-env\"))\nassert config.debug_mode is True","lang":"python","description":"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`."},"warnings":[{"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`).","message":"Python 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.","severity":"breaking","affected_versions":">=1.3.1"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always import `Field` from `pytoolconfig` and refer to `pytoolconfig`'s documentation for the correct arguments and usage, especially for `default` and `default_factory`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}