Welcome to NIBArchive Parser’s documentation!

This small python package provides a parser implementation of NeXTSTEP Interface Builder (NIB) files in Python3.

NIBArchive

The .nib file is primarily associated with Interface Builder, a graphical user interface (GUI) design tool used to create the visual layout of user interfaces for applications. The purpose of a NIB file is to store the information about the user interface elements, their properties, and their relationships with each other.

The file format has been described in detail in the nibsqueeze repository.

Installation

$ pip install nibarchive

Parsing NIB files

As the NIBArchiveParser only accepts IOBase objects, we can either parse opened files directly or use io.BytesIO for a reader on existing byte structures.

1from nibarchive import NIBArchiveParser
2
3# Create the parser instance
4parser = NIBArchiveParser(verify=True)
5
6# Parse an input file from scratch
7with open("path/to/file.nib", "rb") as fp:
8   archive: NIBArchive = parser.parse(fp)

Or with BytesIO:

1from io import BytesIO
2
3# assue the file content is stored here
4buffer = bytes(...)
5parser = NIBArchiveParser()
6
7# parse using BytesIO wrapper class
8archive = parser.parse(BytesIO(buffer))

Working with NIBArchive objects

At this point we can use the returned object to inspect the files content. But, the parser does not organize the returned archive, so we have to do it afterwards:

 1# Get an object
 2obj: NIBObject = archive.objects[0]
 3
 4# Get the object's class name
 5class_name: ClassName = archive.get_class_name(obj)
 6
 7# Retrieve the object's values
 8values: list[NIBValue] = archive.get_object_values(obj)
 9for value in values:
10   # Each value is mapped to a NIBKey
11   key: NIBKey = archive.get_value_key(value)
12
13# equal to steps above
14items: dict[NIBKey, NIBValue] = archive.get_object_items(obj)

There is a convienient method named get_object_items which automatically maps all values of an object to their corresponding keys. The return value is of type dict[NIBKey, NIBValue].

Indices and tables