{"id":4975,"library":"libconf","title":"libconf","description":"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.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/Grk0/python-libconf","tags":["config","libconfig","parser","configuration","reader","writer","pure-python"],"install":[{"cmd":"pip install libconf","lang":"bash","label":"Install libconf"}],"dependencies":[],"imports":[{"symbol":"libconf","correct":"import libconf"},{"note":"Used for fine-grained control over integer output formatting.","symbol":"LibconfInt64","correct":"from libconf import LibconfInt64"},{"note":"Used for fine-grained control over list output formatting.","symbol":"LibconfList","correct":"from libconf import LibconfList"},{"note":"Used for fine-grained control over array output formatting.","symbol":"LibconfArray","correct":"from libconf import LibconfArray"}],"quickstart":{"code":"import libconf\nimport io\n\n# Example libconfig string\nconfig_string = \"\"\"\nversion = 2;\nwindow : {\n  title = \"My Application\";\n  position = { x = 10; y = 20; w = 800; h = 600; };\n};\ncapabilities = (\n  true,\n  1234567890123456789L,\n  [1, 2, 3]\n);\n\"\"\"\n\n# Load configuration from a string\nconfig = libconf.loads(config_string)\nprint(\"Loaded Config:\", config)\nprint(\"Window Title:\", config.window.title)\n\n# Modify and dump configuration back to a string\nconfig.window.title = \"Updated App Title\"\nconfig.capabilities = ('new_list_item', 42)\n\n# Demonstrate LibconfInt64 for explicit long suffix\nfrom libconf import LibconfInt64\nconfig['large_number_forced_L'] = LibconfInt64(123)\n\ndumped_string = libconf.dumps(config, indent=2)\nprint(\"\\nDumped Config:\\n\", dumped_string)","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Starting with version 2.0.0, `libconf` introduced output validation for `dump()` and `dumps()`. These functions will now raise exceptions if attempting to dump data that cannot be correctly read by a standard C libconfig implementation.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"To explicitly dump an integer as a 64-bit value with an 'L' suffix, use `config_data['key'] = LibconfInt64(your_int_value)` before dumping.","message":"Python integer values are dumped without an 'L' suffix if they fit within a C/C++ 32-bit integer range. For larger Python integers, an 'L' suffix is automatically appended. If you need to force an 'L' suffix for a number within the 32-bit range (e.g., for explicit 64-bit representation in libconfig), wrap the integer with `libconf.LibconfInt64`.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"libconfig distinguishes between 'lists' (enclosed by parentheses `()`, arbitrary values) and 'arrays' (enclosed by brackets `[]`, scalar values of the same type). `libconf` maps libconfig `()`-lists to Python `tuples` and libconfig `[]`-arrays to Python `lists`. This distinction is important when round-tripping data or ensuring compatibility with C libconfig.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"It is strongly recommended to use Unicode objects (Python 3 `str`) for all input strings or streams passed to `load()` and `loads()`, and for any strings within data structures passed to `dump()` and `dumps()`. `libconf` handles standard escape sequences (`\\n`, `\\r`, `\\t`, `\\xNN`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}