libconf is a pure-Python reader/writer for configuration files in libconfig format, commonly used in C/C++ projects. Its interface is designed to be similar to Python's standard `json` module, providing `load()`, `loads()`, `dump()`, and `dumps()` methods. The library is currently at version 2.0.1 and appears to be actively maintained.
pip install libconfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load a libconfig string into a Python object, access its elements using attribute or dictionary-style access, modify values, and then dump the modified configuration back into a libconfig formatted string. It also shows the use of `LibconfInt64` for explicit control over integer suffixes. For file operations, `libconf.load()` and `libconf.dump()` are available, similar to the `json` module.
Review data structures being dumped for compatibility with the libconfig specification. Ensure that values and structures adhere to libconfig's rules to avoid `libconf.ConfigError` or similar exceptions.
To explicitly dump an integer as a 64-bit value with an 'L' suffix, use `config_data['key'] = LibconfInt64(your_int_value)` before dumping.
When reading, be aware that libconfig lists will become Python tuples. When writing, use Python tuples for libconfig lists and Python lists for libconfig arrays, keeping in mind the type homogeneity requirement for arrays.
Always ensure strings are Unicode/`str` type in Python 3. If dealing with byte strings or specific encodings, decode them to Unicode before passing to `libconf` functions.
Install the library using pip: `pip install libconf`
Review the configuration file or string for syntax errors, such as missing semicolons, incorrect grouping, or invalid characters, and correct them according to the libconfig format.
If the list contains mixed types or non-scalar elements, wrap it with `libconf.LibconfList` to ensure it's dumped as a `libconfig` list (enclosed in parentheses). If it should be a `libconfig` array, ensure all elements are scalar and of the same type. For explicitly forcing `int64`, use `libconf.LibconfInt64`.
No dependency data recorded yet.