package documentation

Transform GFF (Generic File Format) files from/to native python types.

Python representation is (Struct) and (List) objects, which can be nested. They behave just like native python dictionaries and lists, but with some additional methods and properties to make life easier.

Since GFF has strong typing beyond what python offers natively, the module provides a number of custom types to represent the various field types that can be found in a GFF file.

All field types are subclasses of the native python types, and are used to enforce the GFF type system.

Module _impl Undocumented
Module _reader Undocumented
Module _types Undocumented
Module _writer Undocumented

From __init__.py:

Class Byte Undocumented
Class CExoLocString Represents a localized string in the NWN engine.
Class CExoString Undocumented
Class Char Undocumented
Class Double Undocumented
Class Dword Undocumented
Class Dword64 Undocumented
Class Float Undocumented
Class Int Undocumented
Class Int64 Undocumented
Class List GFF Lists are just python lists of Structs. They carry no metadata.
Class ResRef Undocumented
Class Short Undocumented
Class Struct GFF Structs are just python dicts with .attr access and some metadata.
Class VOID Undocumented
Class Word Undocumented
Function read Read a GFF data from a binary stream.
Function write Write a GFF data structure to a binary stream.
def read(file: BinaryIO): (source)

Read a GFF data from a binary stream.

Example

>>> with open("file.gff", "rb") as f:
...     root, file_type = gff.read(f)
...     print(root)
Parameters
file:BinaryIOThe binary stream to read from.
Returns
A tuple containing the root struct and the file type.
def write(file: BinaryIO, root: Struct, file_type: str): (source)

Write a GFF data structure to a binary stream.

The structure must only use supported GFF types, as GFF is a strongly typed format and deviation from these will make the game fail to read them (e.g. storing a byte as a int will make the game not see it).

Example

>>> root = gff.Struct(0, Byte=gff.Byte(255), SomeStruct=gff.Struct(SomeKey=gff.CExoString("5")))
... out = BytesIO()
... gff.write(out, root, "TEST")
Parameters
file:BinaryIOThe binary stream to write to.
root:StructThe root structure of the GFF file.
file_type:strThe file type identifier (4 characters).