### Install vdf Development Version from GitHub Source: https://github.com/valvepython/vdf/blob/master/README.rst Installs the current development version of the vdf package directly from its GitHub repository using pip. This is useful for testing the latest features or bug fixes. ```bash pip install git+https://github.com/ValvePython/vdf ``` -------------------------------- ### Install vdf Package using pip Source: https://github.com/valvepython/vdf/blob/master/README.rst Installs the latest release of the vdf package from PyPI using pip. This is the recommended way to install the package for general use. ```bash pip install vdf ``` -------------------------------- ### Convert VDF to JSON using vdf2json CLI Tool Source: https://context7.com/valvepython/vdf/llms.txt The `vdf2json` command-line tool, installed separately via `pip install vdf2json`, facilitates the conversion of VDF files to JSON format. It supports standard input/output redirection and options for pretty-printing the JSON output. ```bash # Basic conversion from stdin to stdout cat gameinfo.txt | vdf2json # Convert a VDF file to a JSON file vdf2json input.vdf output.json # Convert with pretty-printed JSON output vdf2json -p input.vdf output.json ``` -------------------------------- ### VDFDict Operations for Handling Duplicates Source: https://github.com/valvepython/vdf/blob/master/README.rst Provides examples of using the `vdf.VDFDict` class, which extends dictionary functionality to handle duplicate keys and maintain insertion order. It shows how to add, access, modify, and delete duplicate entries, as well as check for their existence and remove them. ```python d = vdf.VDFDict() d['key'] = 111 d['key'] = 222 # Accessing values print(d['key']) # Gets the first value print(d[(0, 'key')]) # Gets the first duplicate print(d[(1, 'key')]) # Gets the second duplicate print(d.get_all_for('key')) # Modifying specific duplicates d[(1, 'key')] = 123 # Adding new duplicates d['key'] = 333 # Deleting specific duplicates del d[(1, 'key')] # Checking for duplicates and removing them print(d.has_duplicates()) d.remove_all_for('key') print(len(d)) print(d.has_duplicates()) ``` -------------------------------- ### Load and Dump Binary VDF Data Source: https://github.com/valvepython/vdf/blob/master/README.rst Illustrates how to handle binary VDF data using `binary_loads` and `binary_dumps`. It also shows how to use the `alt_format=True` option for an alternative binary format and how to handle VBKV format with header and CRC checking. ```python # for binary representation d = vdf.binary_loads(vdf_bytes) b = vdf.binary_dumps(d) # alternative format - VBKV d = vdf.binary_loads(vdf_bytes, alt_format=True) b = vdf.binary_dumps(d, alt_format=True) # VBKV with header and CRC checking d = vdf.vbkv_loads(vbkv_bytes) b = vdf.vbkv_dumps(d) ``` -------------------------------- ### vdf.binary_load / vdf.binary_dump - Binary File I/O Source: https://context7.com/valvepython/vdf/llms.txt Provides functions to read and write binary VDF data directly from and to file objects, supporting both file paths and in-memory operations using BytesIO. ```APIDOC ## vdf.binary_load / vdf.binary_dump - Binary File I/O ### Description Read and write binary VDF format directly from/to file objects. ### Methods - `vdf.binary_dump(data, file_obj, alt_format=False)` - `vdf.binary_load(file_obj, mapper=dict, alt_format=False, raise_on_remaining=True)` ### Parameters #### `vdf.binary_dump` Parameters - **data** (dict) - Required - The Python dictionary to serialize. - **file_obj** (file object) - Required - The file object to write to. - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). #### `vdf.binary_load` Parameters - **file_obj** (file object) - Required - The file object to read from. - **mapper** (type) - Optional - The dictionary type to use for mapping (default: `dict`). - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). - **raise_on_remaining** (bool) - Optional - Whether to raise an error if there are remaining unparsed bytes (default: `True`). ### Request Example ```python import vdf from io import BytesIO # Write binary VDF to file data = { 'config': { 'version': 1, 'name': 'settings', 'enabled': 'true' } } with open('config.bin', 'wb') as f: vdf.binary_dump(data, f) # Read binary VDF from file with open('config.bin', 'rb') as f: loaded = vdf.binary_load(f) print(loaded) # Output: {'config': {'version': 1, 'name': 'settings', 'enabled': 'true'}} # Use BytesIO for in-memory operations buf = BytesIO() vdf.binary_dump(data, buf) buf.seek(0) result = vdf.binary_load(buf) ``` ### Response #### Success Response (dict for `binary_load`) - **dict** - A dictionary representing the loaded VDF data. #### Response Example ```json { "config": { "version": 1, "name": "settings", "enabled": "true" } } ``` ``` -------------------------------- ### Read/Write Binary VDF from Files with vdf.binary_load/dump Source: https://context7.com/valvepython/vdf/llms.txt Provides functions to read binary VDF data directly from file-like objects (using `vdf.binary_load`) and write Python dictionaries to binary VDF format into file-like objects (using `vdf.binary_dump`). Supports both file paths and in-memory operations using BytesIO. ```python import vdf from io import BytesIO # Data to be written to a binary VDF file data = { 'config': { 'version': 1, 'name': 'settings', 'enabled': 'true' } } # Write data to a binary file with open('config.bin', 'wb') as f: vdf.binary_dump(data, f) # Read data from the binary file with open('config.bin', 'rb') as f: loaded = vdf.binary_load(f) print(loaded) # Expected Output: {'config': {'version': 1, 'name': 'settings', 'enabled': 'true'}} # Use BytesIO for in-memory binary VDF operations buf = BytesIO() vdf.binary_dump(data, buf) buf.seek(0) result = vdf.binary_load(buf) print(result) # Expected Output: {'config': {'version': 1, 'name': 'settings', 'enabled': 'true'}} ``` -------------------------------- ### Handle Duplicate Keys in VDF Parsing with VDFDict Source: https://context7.com/valvepython/vdf/llms.txt Demonstrates how to use VDFDict to preserve duplicate keys when parsing VDF content. VDFDict allows for multiple values associated with the same key, which can be retrieved using get_all_for(). ```python from vdf import VDFDict # Example VDF content with duplicate keys vdf_with_duplicates = ''' "items" { "item" "health_potion" "item" "mana_potion" "item" "stamina_potion" } ''' # Parse VDF preserving duplicates data = vdf.loads(vdf_with_duplicates, mapper=VDFDict) # Retrieve all values for a specific key print(data['items'].get_all_for('item')) # Expected Output: ['health_potion', 'mana_potion', 'stamina_potion'] # Check if duplicates exist print(d.has_duplicates()) # Expected Output: True # Remove all entries for a specific key d.remove_all_for('weapon') print(len(d)) # Expected Output: 0 ``` -------------------------------- ### Using Custom Mappers with vdf.loads Source: https://github.com/valvepython/vdf/blob/master/README.rst Demonstrates how to use custom mapper objects like `collections.OrderedDict` or `vdf.VDFDict` with `vdf.loads` to preserve key order or handle duplicate keys. This is useful when the default dictionary behavior is insufficient. ```python import collections d = vdf.loads(vdf_string, mapper=collections.OrderedDict) d = vdf.loads(vdf_string, mapper=vdf.VDFDict) ``` -------------------------------- ### Load and Parse VDF Data in Python Source: https://github.com/valvepython/vdf/blob/master/README.rst Demonstrates how to load and parse VDF data from files or strings using the vdf module. It includes functions for loading from a file object and from a string, as well as parsing. ```python import vdf # parsing vdf from file or string d = vdf.load(open('file.txt')) d = vdf.loads(vdf_text) d = vdf.parse(open('file.txt')) d = vdf.parse(vdf_text) ``` -------------------------------- ### vdf2json CLI Tool Source: https://context7.com/valvepython/vdf/llms.txt A command-line utility for converting VDF files to JSON format. It can be used for basic conversion, file-to-file operations, and pretty-printed output. ```APIDOC ## vdf2json CLI Tool ### Description Command-line utility for converting VDF files to JSON format. Installed separately via `pip install vdf2json`. ### Usage #### Basic conversion (stdin to stdout) ```bash cat gameinfo.txt | vdf2json ``` #### File to file conversion ```bash vdf2json input.vdf output.json ``` #### Pretty printed JSON output ```bash vdf2json -p input.vdf output.json ``` ### Parameters #### Command-line Arguments - **input.vdf** - Optional - Path to the input VDF file. If not provided, reads from stdin. - **output.json** - Optional - Path to the output JSON file. If not provided, writes to stdout. - **-p, --pretty** - Optional - Enables pretty-printing of the JSON output. ### Example ```bash # Convert a VDF file to a pretty-printed JSON file vdf2json -p my_game_config.vdf my_game_config.json ``` ``` -------------------------------- ### Dump Python Dictionary to VDF Format Source: https://github.com/valvepython/vdf/blob/master/README.rst Shows how to serialize a Python dictionary into VDF format, both as a string and to a file. The `pretty=True` option enables indented output for better readability. ```python # dumping dict as vdf to string vdf_text = vdf.dumps(d) indented_vdf = vdf.dumps(d, pretty=True) # dumping dict as vdf to file vdf.dump(d, open('file2.txt','w'), pretty=True) ``` -------------------------------- ### vdf.binary_loads - Parse Binary VDF Source: https://context7.com/valvepython/vdf/llms.txt Deserializes binary VDF format into a Python dictionary. It supports various data types and can be configured to use OrderedDict or handle files with extra data. ```APIDOC ## vdf.binary_loads - Parse Binary VDF ### Description Deserialize binary VDF format to a Python dictionary. Supports various data types including strings, integers, floats, and 64-bit values. ### Method `vdf.binary_loads(data, mapper=dict, alt_format=False, raise_on_remaining=True)` ### Parameters #### Query Parameters - **data** (bytes) - Required - The binary VDF data to parse. - **mapper** (type) - Optional - The dictionary type to use for mapping (default: `dict`). - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). - **raise_on_remaining** (bool) - Optional - Whether to raise an error if there are remaining unparsed bytes (default: `True`). ### Request Example ```python import vdf from collections import OrderedDict # Parse binary VDF bytes binary_data = b'\x01key\x00value\x00\x08' result = vdf.binary_loads(binary_data) print(result) # Output: {'key': 'value'} # Parse with OrderedDict result = vdf.binary_loads(binary_data, mapper=OrderedDict) # Parse alternative format (used by some Valve files) alt_binary_data = b'\x01key\x00value\x00\x0b' result = vdf.binary_loads(alt_binary_data, alt_format=True) # Handle files with extra data (don't raise on remaining bytes) binary_with_extra = b'\x01key\x00value\x00\x08extradata' result = vdf.binary_loads(binary_with_extra, raise_on_remaining=False) print(result) # Output: {'key': 'value'} ``` ### Response #### Success Response (dict) - **dict** - A dictionary representing the parsed VDF data. #### Response Example ```json { "key": "value" } ``` ``` -------------------------------- ### Serialize Python Dictionary to Binary VDF with vdf.binary_dumps Source: https://context7.com/valvepython/vdf/llms.txt Serialize a Python dictionary into the binary VDF format, outputting bytes. Supports basic data types and special VDF types like POINTER, COLOR, UINT_64, and INT_64. Options for alternative format serialization are also available. ```python import vdf # Basic dictionary for serialization data = {'player': 'name', 'score': 100} binary_output = vdf.binary_dumps(data) print(binary_output) # Expected Output: b'\x01player\x00name\x00\x02score\x00d\x00\x00\x00\x08' # Dictionary with various VDF specific data types data_with_types = { 'name': 'test', 'count': 42, 'ratio': 1.5, 'pointer': vdf.POINTER(1234), 'color': vdf.COLOR(0xFF0000), 'big_num': vdf.UINT_64(9999999999), 'signed_big': vdf.INT_64(-1234567890) } binary_output = vdf.binary_dumps(data_with_types) # Serialize using an alternative format alt_output = vdf.binary_dumps(data, alt_format=True) ``` -------------------------------- ### vdf.vbkv_loads / vdf.vbkv_dumps - VBKV Format Source: https://context7.com/valvepython/vdf/llms.txt Handles the VBKV (Valve Binary Key-Value) format, which includes a header and CRC32 checksum for data integrity. Supports parsing and serialization. ```APIDOC ## vdf.vbkv_loads / vdf.vbkv_dumps - VBKV Format ### Description Parse and serialize VBKV format, which includes a header and CRC32 checksum for data integrity verification. ### Methods - `vdf.vbkv_dumps(data, alt_format=False)` - `vdf.vbkv_loads(data, mapper=dict, alt_format=False)` ### Parameters #### `vdf.vbkv_dumps` Parameters - **data** (dict) - Required - The Python dictionary to serialize. - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). #### `vdf.vbkv_loads` Parameters - **data** (bytes) - Required - The VBKV data to parse. - **mapper** (type) - Optional - The dictionary type to use for mapping (default: `dict`). - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). ### Request Example ```python import vdf from collections import OrderedDict # Serialize to VBKV format data = { 'inventory': { 'item1': 'sword', 'item2': 'shield', 'gold': 500 } } vbkv_bytes = vdf.vbkv_dumps(data) print(vbkv_bytes[:4]) # Output: b'VBKV' (header) # Parse VBKV format (validates header and CRC) parsed = vdf.vbkv_loads(vbkv_bytes) print(parsed) # Output: {'inventory': {'item1': 'sword', 'item2': 'shield', 'gold': 500}} # Use with OrderedDict parsed = vdf.vbkv_loads(vbkv_bytes, mapper=OrderedDict) # Invalid header raises ValueError try: vdf.vbkv_loads(b'INVALID_DATA') except ValueError as e: print(f"Error: {e}") # Output: Error: Invalid header # Invalid checksum raises ValueError try: vdf.vbkv_loads(b'VBKV\x00\x00\x00\x00corrupted_data') except ValueError as e: print(f"Error: {e}") # Output: Error: Invalid checksum ``` ### Response #### Success Response (bytes for `vbkv_dumps`, dict for `vbkv_loads`) - **bytes** - The serialized VBKV data. - **dict** - The parsed VBKV data. #### Response Example ```json { "inventory": { "item1": "sword", "item2": "shield", "gold": 500 } } ``` ``` -------------------------------- ### Control Duplicate Key Merging in VDF Parsing Source: https://context7.com/valvepython/vdf/llms.txt Demonstrates the `merge_duplicate_keys` option in `vdf.loads`. When `True` (default), duplicate keys result in a merged dictionary. When `False`, later occurrences of a duplicate key overwrite earlier ones. ```python import vdf vdf_with_duplicates = ''' "config" { "setting" "value1" "option" "A" } "config" { "setting" "value2" "extra" "B" } ''' # Parse with duplicate keys merged (default behavior) merged = vdf.loads(vdf_with_duplicates, merge_duplicate_keys=True) print(merged) # Expected Output: {'config': {'setting': 'value2', 'option': 'A', 'extra': 'B'}} # Parse with duplicate keys overwriting (later values take precedence) overwritten = vdf.loads(vdf_with_duplicates, merge_duplicate_keys=False) print(overwritten) # Expected Output: {'config': {'setting': 'value2', 'extra': 'B'}} ``` -------------------------------- ### Low-level VDF Parsing with vdf.parse Source: https://context7.com/valvepython/vdf/llms.txt A low-level parsing function that accepts a file-like object with readline support. It offers more control over the parsing process, such as specifying a custom dictionary mapper (e.g., `OrderedDict`) or disabling escaping. ```python import vdf from io import StringIO from collections import OrderedDict vdf_content = ''' "root" { "key1" "value1" "key2" "value2" "nested" { "inner" "data" } } ''' fp = StringIO(vdf_content) # Parse with default dict result = vdf.parse(fp) print(result) # Output: {'root': {'key1': 'value1', 'key2': 'value2', 'nested': {'inner': 'data'}}} # Parse with OrderedDict to preserve key order fp.seek(0) result = vdf.parse(fp, mapper=OrderedDict) # Parse with escaping disabled fp.seek(0) result = vdf.parse(fp, escaped=False) ``` -------------------------------- ### Parse Binary VDF Format with vdf.binary_loads Source: https://context7.com/valvepython/vdf/llms.txt Deserialize binary VDF format data from bytes into a Python dictionary. This function supports various data types and offers options for using OrderedDict and handling alternative binary formats or extra data. ```python import vdf from collections import OrderedDict # Binary data representing a VDF structure binary_data = b'\x01key\x00value\x00\x08' # Parse binary VDF bytes into a dictionary result = vdf.binary_loads(binary_data) print(result) # Expected Output: {'key': 'value'} # Parse using OrderedDict to maintain key order result = vdf.binary_loads(binary_data, mapper=OrderedDict) # Parse an alternative binary format alt_binary_data = b'\x01key\x00value\x00\x0b' result = vdf.binary_loads(alt_binary_data, alt_format=True) # Handle binary data with extra bytes without raising an error binary_with_extra = b'\x01key\x00value\x00\x08extradata' result = vdf.binary_loads(binary_with_extra, raise_on_remaining=False) print(result) # Expected Output: {'key': 'value'} ``` -------------------------------- ### Parse and Serialize VBKV Format with vdf.vbkv_loads/dumps Source: https://context7.com/valvepython/vdf/llms.txt Handles the VBKV format, which includes a header and CRC32 checksum for data integrity. `vdf.vbkv_dumps` serializes Python dictionaries to VBKV bytes, while `vdf.vbkv_loads` parses VBKV bytes, validating the header and checksum. It supports OrderedDict and raises ValueError on invalid data. ```python import vdf from collections import OrderedDict # Data to be serialized to VBKV format data = { 'inventory': { 'item1': 'sword', 'item2': 'shield', 'gold': 500 } } # Serialize data to VBKV bytes vbkv_bytes = vdf.vbkv_dumps(data) print(vbkv_bytes[:4]) # Expected Output: b'VBKV' (header) # Parse VBKV bytes, validating header and CRC32 checksum parsed = vdf.vbkv_loads(vbkv_bytes) print(parsed) # Expected Output: {'inventory': {'item1': 'sword', 'item2': 'shield', 'gold': 500}} # Parse VBKV bytes using OrderedDict parsed = vdf.vbkv_loads(vbkv_bytes, mapper=OrderedDict) # Example of handling invalid header try: vdf.vbkv_loads(b'INVALID_DATA') except ValueError as e: print(f"Error: {e}") # Expected Output: Error: Invalid header # Example of handling invalid checksum try: vdf.vbkv_loads(b'VBKV\x00\x00\x00\x00corrupted_data') except ValueError as e: print(f"Error: {e}") # Expected Output: Error: Invalid checksum ``` -------------------------------- ### Write VDF to File with vdf.dump Source: https://context7.com/valvepython/vdf/llms.txt Serializes a Python dictionary and writes it directly to a file-like object. This function is convenient for saving VDF data to disk. It also supports pretty-printing for better readability of the output file. ```python import vdf config = { 'ServerConfig': { 'hostname': 'My Game Server', 'maxplayers': '24', 'password': '', 'rcon_password': 'secret123' } } # Write to file with open('server.cfg', 'w') as f: vdf.dump(config, f, pretty=True) # File contents: # "ServerConfig" # { # "hostname" "My Game Server" # "maxplayers" "24" # "password" "" # "rcon_password" "secret123" # } ``` -------------------------------- ### Parse VDF from File with vdf.load Source: https://context7.com/valvepython/vdf/llms.txt Deserializes VDF content from a file-like object. This function is useful for reading VDF files directly from disk or other streamable sources. It can also handle files with custom encodings. ```python import vdf import codecs # Read VDF from file with open('gameinfo.txt', 'r') as f: data = vdf.load(f) print(data) # Output: {'GameInfo': {'game': 'Half-Life 2', 'title': 'HALF-LIFE 2', ...}} # Parse with custom encoding with codecs.open('config.vdf', 'r', encoding='utf-16') as f: data = vdf.load(f) ``` -------------------------------- ### Merge Duplicate Keys Option Source: https://context7.com/valvepython/vdf/llms.txt Allows control over how duplicate keys are handled during VDF parsing. Options include merging them into a single nested structure (default) or overwriting with the later occurrence. ```APIDOC ## Merge Duplicate Keys Option ### Description Control how duplicate keys are handled during parsing - merge them into a single nested structure or overwrite. ### Method `vdf.loads(text, merge_duplicate_keys=True, mapper=dict)` ### Parameters #### Query Parameters - **text** (str) - Required - The VDF text to parse. - **merge_duplicate_keys** (bool) - Optional - If `True` (default), duplicate keys are merged into a nested dictionary. If `False`, later keys overwrite earlier ones. - **mapper** (type) - Optional - The dictionary type to use for mapping (default: `dict`). ### Request Example ```python import vdf vdf_with_duplicates = ''' "config" { "setting" "value1" "option" "A" } "config" { "setting" "value2" "extra" "B" } ''' # With merge enabled (default) - combines nested dicts merged = vdf.loads(vdf_with_duplicates, merge_duplicate_keys=True) print(merged) # Output: {'config': {'setting': 'value2', 'option': 'A', 'extra': 'B'}} # Without merge - later key overwrites earlier overwritten = vdf.loads(vdf_with_duplicates, merge_duplicate_keys=False) print(overwritten) # Output: {'config': {'setting': 'value2', 'extra': 'B'}} ``` ### Response #### Success Response (dict) - **dict** - A dictionary representing the parsed VDF data, with duplicate keys handled according to the `merge_duplicate_keys` setting. #### Response Example ```json { "config": { "setting": "value2", "option": "A", "extra": "B" } } ``` ``` -------------------------------- ### Handling Duplicate Keys with VDFDict Source: https://context7.com/valvepython/vdf/llms.txt VDFDict is a specialized dictionary subclass designed to handle duplicate keys, which are permissible in the VDF format. It allows storing and retrieving multiple values associated with the same key, essential for parsing complex VDF files. ```python import vdf from vdf import VDFDict # Create VDFDict with duplicate keys d = VDFDict() d['weapon'] = 'sword' d['weapon'] = 'axe' d['weapon'] = 'bow' print(d) # Output: VDFDict([('weapon', 'sword'), ('weapon', 'axe'), ('weapon', 'bow')]) # Access first duplicate (default) print(d['weapon']) # Output: sword # Access specific duplicate by index print(d[(0, 'weapon')]) # Output: sword print(d[(1, 'weapon')]) # Output: axe print(d[(2, 'weapon')]) # Output: bow # Get all values for a key print(d.get_all_for('weapon')) # Output: ['sword', 'axe', 'bow'] # Reassign specific duplicate d[(1, 'weapon')] = 'hammer' print(d.get_all_for('weapon')) # Output: ['sword', 'hammer', 'bow'] ``` -------------------------------- ### Serialize to VDF String with vdf.dumps Source: https://context7.com/valvepython/vdf/llms.txt Serializes a Python dictionary into a VDF-formatted string. This function supports both compact and pretty-printed output, controlled by the `pretty` argument. It's useful for generating VDF data programmatically. ```python import vdf data = { 'PlayerConfig': { 'name': 'Player1', 'sensitivity': '2.5', 'bindings': { 'attack': 'MOUSE1', 'jump': 'SPACE', 'crouch': 'CTRL' } } } # Compact output output = vdf.dumps(data) print(output) # Output: # "PlayerConfig" # { # "name" "Player1" # "sensitivity" "2.5" # "bindings" # { # "attack" "MOUSE1" # "jump" "SPACE" # "crouch" "CTRL" # } # } # Pretty printed with indentation pretty_output = vdf.dumps(data, pretty=True) print(pretty_output) # Output: # "PlayerConfig" # { # "name" "Player1" # "sensitivity" "2.5" # "bindings" # { # "attack" "MOUSE1" # "jump" "SPACE" # "crouch" "CTRL" # } # } ``` -------------------------------- ### vdf.binary_dumps - Serialize to Binary VDF Source: https://context7.com/valvepython/vdf/llms.txt Serializes a Python dictionary into binary VDF format bytes. Supports various data types including special VDF types like POINTER, COLOR, UINT_64, and INT_64. ```APIDOC ## vdf.binary_dumps - Serialize to Binary VDF ### Description Serialize a Python dictionary to binary VDF format bytes. Supports various data types including special VDF types. ### Method `vdf.binary_dumps(data, alt_format=False)` ### Parameters #### Query Parameters - **data** (dict) - Required - The Python dictionary to serialize. - **alt_format** (bool) - Optional - Whether to use the alternative binary VDF format (default: `False`). ### Request Example ```python import vdf # Basic serialization data = {'player': 'name', 'score': 100} binary_output = vdf.binary_dumps(data) print(binary_output) # Output: b'\x01player\x00name\x00\x02score\x00d\x00\x00\x00\x08' # Serialize with special types data_with_types = { 'name': 'test', 'count': 42, 'ratio': 1.5, 'pointer': vdf.POINTER(1234), 'color': vdf.COLOR(0xFF0000), 'big_num': vdf.UINT_64(9999999999), 'signed_big': vdf.INT_64(-1234567890) } binary_output = vdf.binary_dumps(data_with_types) # Use alternative format alt_output = vdf.binary_dumps(data, alt_format=True) ``` ### Response #### Success Response (bytes) - **bytes** - The serialized binary VDF data. #### Response Example ```python b'\x01player\x00name\x00\x02score\x00d\x00\x00\x00\x08' ``` ``` -------------------------------- ### Parse VDF String with vdf.loads Source: https://context7.com/valvepython/vdf/llms.txt Deserializes a VDF-formatted string into a Python dictionary. This is the primary method for parsing VDF content directly from strings. It handles nested structures and basic VDF syntax. ```python import vdf # Basic VDF parsing vdf_text = ''' "GameConfig" { "game" "Team Fortress 2" "appid" "440" "settings" { "difficulty" "normal" "volume" "0.8" } } ''' data = vdf.loads(vdf_text) print(data) # Output: {'GameConfig': {'game': 'Team Fortress 2', 'appid': '440', 'settings': {'difficulty': 'normal', 'volume': '0.8'}}} # Access nested values print(data['GameConfig']['game']) # Output: Team Fortress 2 print(data['GameConfig']['settings']['difficulty']) # Output: normal ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.