Sphinx objects.inv v2 Syntax

After decompression, “version 2” Sphinx objects.inv files follow a syntax that, to the best of this author’s ability to determine, is completely undocumented. The below syntax is believed to be accurate as of Jun 2018 (Sphinx v1.7.4). Based upon a quick git diff of the Sphinx repository, it is thought to be accurate for all Sphinx versions >=1.0b1 that make use of this “version 2” objects.inv format.


The first line must be exactly:

# Sphinx inventory version 2

The second and third lines must obey the template:

# Project: <project name>
# Version: <full version number>

The version number should not include a leading “v”.

The above project name and version are used to populate mouseovers for the intersphinx cross-references:

_images/mouseover_example.png

The fourth line must contain the string ‘zlib’ somewhere in it, but for the purposes of consistency it should be exactly:

# The remainder of this file is compressed using zlib.

All remaining lines of the file are the objects data, each laid out in the following syntax:

{name} {domain}:{role} {priority} {uri} {dispname}
{name}

The object name used when cross-referencing the object (falls between the backticks).

Constraints

  • MUST have length greater than zero

  • MUST NOT contain whitespace

{domain}

The Sphinx domain used when cross-referencing the object (falls between the first and second colons; omitted if using the default domain).

Constraints

  • MUST have length greater than zero

  • MUST match a built-in or installable Sphinx domain

  • MUST consist of only word characters

    • RECOMMENDED to consist of only ASCII word characters (a-z, A-Z, 0-9, and _)

{role}

The Sphinx role used when cross-referencing the object (falls between the second and third colons; or, between the first and second colons if using the default domain).

Constraints

  • MUST have length greater than zero

  • MUST match a role defined in the domain referenced by {domain}

  • MUST consist of only word characters

    • RECOMMENDED to consist of only ASCII word characters (a-z, A-Z, 0-9, and _)

{priority}

Flag for placement in search results. Most will be 1 (standard priority) or -1 (omit from results) for documentation built by Sphinx.

To note, as of Nov 2020 this value is not used by intersphinx; it is only used internally within the search function of the static webpages built by Sphinx (here and here). Thus, custom inventories likely MAY use this field for arbitrary content, if desired. This would run the risk of a future change to Sphinx/intersphinx causing such custom objects.inv files to become incompatible.

Constraints

  • MUST have length greater than zero

  • MUST NOT contain whitespace

{uri}

Relative URI for the location to which cross-references will point. The base URI is taken from the relevant element of the intersphinx_mapping configuration parameter of conf.py.

Constraints

  • MUST have length greater than zero

  • MUST NOT contain whitespace

{dispname}

Default cross-reference text to be displayed in compiled documentation.

Constraints

  • MUST have length greater than zero

  • MAY contain internal whitespace (leading/trailing whitespace is ignored)


For illustration, the following is the entry for the join() method of the str class in the Python 3.5 objects.inv, broken out field-by-field:

str.join py:method 1 library/stdtypes.html#$ -

{name}      = str.join
{domain}    = py
{role}      = method
{priority}  = 1
{uri}       = library/stdtypes.html#$
{dispname}  = -

The above illustrates two shorthand notations that were introduced to shrink the size of the inventory file:

  1. If {uri} has an anchor (technically a “fragment identifier,” the portion following the # symbol) and the tail of the anchor is identical to {name}, that tail is replaced with $.

  2. If {dispname} is identical to {name}, it is stored as -.

Thus, a standard intersphinx reference to this method would take the form (the leading :py could be omitted if py is the default domain):

:py:meth:`str.join`

The cross-reference would show as str.join() and link to the relative URI:

library/stdtypes.html#str.join

Other intersphinx Syntax Examples

To show as only join():

:py:meth:`~str.join`

To suppress the hyperlink as in str.join():

:py:meth:`!str.join`

To change the cross-reference text and omit the trailing parentheses as in This is join!:

:py:obj:`This is join! <str.join>`