FHConfParser
raw JSON → 2024.1 verified Mon Apr 27 auth: no python
Provides a config language independent way to read a config file. Supports multiple config formats (YAML, TOML, JSON, etc.) under a unified API. Current version: 2024.1. Released on 2024-01-24, active maintenance, monthly/irregular releases.
pip install fhconfparser Common errors
error ModuleNotFoundError: No module named 'fhconfparser' ↓
cause Package not installed or installed in wrong Python environment.
fix
Run 'pip install fhconfparser' in the correct environment.
error fhconfparser.exceptions.UnsupportedFormatError: Unsupported config format ↓
cause File extension not recognized or missing required library (e.g., PyYAML for YAML, toml for TOML).
fix
Install necessary dependencies: 'pip install pyyaml toml' and ensure file has correct extension.
error AttributeError: module 'fhconfparser' has no attribute 'Config' ↓
cause Importing incorrectly; fhconfparser doesn't expose Config directly if imported as module.
fix
Use 'from fhconfparser import Config'
Warnings
gotcha The Config object is not a singleton; each instance has its own state. Do not assume shared state across modules. ↓
fix Create a single Config instance and pass it explicitly.
gotcha File format detection is based on file extension. Ensure your config file has a recognized extension (e.g., .yaml, .toml, .json, .ini) or use the correct loader. ↓
fix Use explicit loader: config.load_config('config.txt', loader='yaml')
deprecated The 'load' method (without 'config' suffix) is deprecated in v2023 and may be removed in future. ↓
fix Use load_config() instead.
Imports
- Config wrong
import fhconfparser config = fhconfparser.Config()correctfrom fhconfparser import Config
Quickstart
from fhconfparser import Config
config = Config()
# Load a config file (supports YAML, TOML, JSON, etc.)
data = config.load_config('config.yaml')
print(data)