The `vdf` library is a pure Python module for serialization and deserialization of Valve's KeyValue (VDF) text and binary formats. It provides an interface similar to Python's built-in `json` module. The current version is 3.4, and it is actively maintained with an irregular release cadence, supporting KV1 format while KV2 and KV3 are not supported.
pip install vdfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse and dump VDF data, including handling text and binary formats. It highlights the use of `vdf.VDFDict` for correctly managing duplicate keys and preserving order, which are common challenges with the VDF format.
Use `vdf.loads(vdf_string, mapper=vdf.VDFDict)` or `vdf.loads(vdf_string, mapper=collections.OrderedDict)` to preserve all duplicate keys as a list of values, or to maintain insertion order, respectively. `vdf.VDFDict` is specifically designed to handle VDF's duplicate key behavior.
Always use `collections.OrderedDict` or `vdf.VDFDict` as the `mapper` when loading VDF data if key order is important, especially on Python versions older than 3.6. For example: `vdf.loads(vdf_text, mapper=collections.OrderedDict)`.
This is a fundamental behavior of the library; if comment preservation is critical, `vdf` might not be the suitable tool, or comments would need to be handled by a separate parsing layer before passing data to `vdf`.
Ensure `vdf` is installed for your active Python interpreter using `pip install vdf`. If using virtual environments, activate the correct environment first. If using tools like `protontricks`, verify that the Python environment it targets has `vdf` installed, potentially by forcing installation for a specific Python version or ensuring path consistency.
Inspect the structure of your VDF data after deserialization. Remember that `VDFDict` works like `dict`, and nested values are accessed sequentially (e.g., `data_vdfdict['Config']['Key1']`). If duplicate keys exist, `VDFDict` stores them as a list of values, so you might need to iterate or access by index (e.g., `data_vdfdict['Config']['Key1'][0]`) if you're expecting a single string.
No dependency data recorded yet.