Skip to main content

Library for working with Valve's VDF text format

Project description

Latest version released on PyPi MIT License Test coverage 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vdf-1.10.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vdf-1.10-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file vdf-1.10.tar.gz.

File metadata

  • Download URL: vdf-1.10.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vdf-1.10.tar.gz
Algorithm Hash digest
SHA256 3af0cecb8ebe1260415c8e5cce742474d33862e33e8821b49360af3715497812
MD5 342a535f4d33f843c2c728c6a26abb0b
BLAKE2b-256 768284fd18d3ea4716e4f49334d3c487c127b07e9f864c31aa976c5f59d60cb3

See more details on using hashes here.

File details

Details for the file vdf-1.10-py2.py3-none-any.whl.

File metadata

  • Download URL: vdf-1.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vdf-1.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 14b91a684ba2b4ff1a9dd71ecec45a16e212beec26776b8de5250cc451962532
MD5 fa4302b7a076e32c19b9e321304043c4
BLAKE2b-256 3cb229d9fd781df743c75cca0ba09d0243508a4ae19d03e3c9156dc2544e20e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page