Skip to main content

Python Library for reading VDFs and Valve KeyValue files

Project description

Parse VDFs and Valve KeyValue Files

Build StatusCoverage StatusGitHub Release

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

API

More documentation here:

http://amreuland.github.io/PyVDF/

All functionality is provided through the PyVDF module. import it and call it to create an instance, or just call the static methods off the import.

Basic Usage

import PyVDF
Foo = PyVDF()
Foo = PyVDF(data=StringOData)
Foo = PyVDF(infile="/path/to/file.ext")
Foo = PyVDF(infile=fileInstance)

PyVDF(data=None, infile=None)

Constructor that can take either a string of vdf data, or a filename or file instance

Foo = PyVDF(data='"Apples"{"NoApplesHere" "Nope"}')
Foo = PyVDF(infile='tests/test.vdf')
Foo = PyVDF(infile=open('tests/test.vdf', 'r'))

load(file/str f)

A method to load the contents of f

Foo = PyVDF()
Foo.load('tests/test.vdf')
Foo.load(open('tests/test.vdf', 'r'))

loads(str data)

String version of .load

A method to load the contents of a string

Foo = PyVDF()
Foo.loads('"Apples"{"AreApplesHere" "No Apples Here"}')

getData()

Return a dict or OrderedDict containing the objects data

Foo = PyVDF(infile='tests/test.vdf')
FooBar = Foo.getData()

setData(dict data)

Set the objects data to the given dict or OrderedDict

Foo = PyVDF()
Foo.setData({'Apples': {'AreApplesHere': 'No Apples Here'}})

find(str path)

Find a value from a path. ex. Apples.AreApplesHere

If a path contains a key that has periods in the name, Surround that part of the path in brackets.

ex. UserLocalConfigStore.depots.17522.CDN.[content8.steampowered.com]

The content8.steampowered.com part contains periods, and therefor must be surrounded in brackets.

If the path contains spaces, do not put it in quotes. That will look like literal quotes to python.

A non existant path will return an empty string

Foo.find('Apples.AreApplesHere')
# No Apples Here

You can also use array notation get values

Bar = Foo['Apples.AreApplesHere']

edit(str path, str value)

Like find, but the second argument is the value to set for that key-path

Foo.edit('Apples.AreApplesHere', 'YES!!!')

You can also create new paths.

Foo.edit('Non.Existant.Path', 'FooBar')

You can also use array notation to set values

Foo['Path.To.Key'] = 'Value'

findMany(iterable paths)

like find, but will return a list of found or not found values.

Paths must be a list or a tuple of path strings.

Foo.findMany(['Apples.AreApplesHere', 'Non.Existant.Path'])
# ['YES!!!', 'FooBar']

editMany(iteral paths)

like edit and findMany, however the paths must be a list or tuple of lists or tuples.

Foo.editMany([('Apples.AreApplesHere', 'No'), ['Path', 'Yes']])

write_file(str filename)

Write the objects data to a file

Foo.write_file('out.vdf')

toString()

Retrun the objects data as a VDF string

Bar = Foo.toString()
Static Calls
import PyVDF
FooBar = PyVDF.read("/path/to/file.ext")
FooBar = PyVDF.read(fileInstance)
FooBar = PyVDF.reads(StringOData)

useFastDict(bool var)

setIndentation(str var)

setSpacing(str var)

setCondensed(bool var)

setMaxTokenLength(int var)

read(file/filename f)

reads(str data)

formatData(dict data)

writeData(file/filename f, dict data)

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

PyVDF-1.0.4.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file PyVDF-1.0.4.tar.gz.

File metadata

  • Download URL: PyVDF-1.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyVDF-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c384c5b8bf70e74137470b44fe05ccd9590a12cfd31aa9dea3669542ee61ae61
MD5 223d546b5ba32f30704fb85de0ccbf1d
BLAKE2b-256 f179da4abd35eeef60633fe73035a9821388f628c6b76ec0c23a3503ae9891c1

See more details on using hashes here.

Supported by

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