Skip to content

📜 Package for working with Valve's text and binary KeyValue format

License

Notifications You must be signed in to change notification settings

ValvePython/vdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest version released on PyPi MIT License Test coverage Scrutinizer score Build status of master branch

VDF is Valve's KeyValue text file format

https://developer.valvesoftware.com/wiki/KeyValues

The module works just like json for (de)serilization to and from VDF.

Problems & solutions

  • There are known files that contain duplicate keys. This can be solved by creating a class inheriting from dict and implementing a way to handle duplicate keys. See example implementation of DuplicateOrderedDict.
  • By default deserialization will return a dict, which doesn't preserve nor guarantee key order due to hash randomization. If key order is important then I suggest using collections.OrderedDict as mapper. See example below.

Install

You can grab the latest release from https://pypi.python.org/pypi/vdf or via pip

pip install vdf

Example usage

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)

# 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)

Using OrderedDict to preserve key order.

import vdf
from collections import OrderedDict

# parsing vdf from file or string
d = vdf.load(open('file.txt'), mapper=OrderedDict)
d = vdf.loads(vdf_text, mapper=OrderedDict)