Skip to content

Instantly share code, notes, and snippets.

@jborbely
Last active April 28, 2025 22:03
Show Gist options
  • Select an option

  • Save jborbely/16f4c39da4dd0e6232f936c45386d692 to your computer and use it in GitHub Desktop.

Select an option

Save jborbely/16f4c39da4dd0e6232f936c45386d692 to your computer and use it in GitHub Desktop.
Dump a Sphinx objects.inv file to a human-readable file.
"""Dump a Sphinx objects.inv file to a human-readable file.
Examples:
Local file
dump("/path/to/objects.inv")
Python
dump("https://docs.python.org/3")
Numpy
dump("https://docs.scipy.org/doc/numpy")
"""
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "sphinx",
# ]
# ///
import codecs
import sys
from pathlib import Path
from urllib.request import urlopen
from sphinx.ext.intersphinx import inspect_main
def dump(url: str) -> None:
"""Dump a Sphinx objects.inv file to a human-readable file.
Args:
url: The URL to a remote or local objects.inv file.
"""
if url.startswith(("http:", "https:")):
url = url.removesuffix("objects.inv")
with urlopen(f"{url}/objects.inv") as f:
_ = Path("objects.inv").write_bytes(f.read())
url = "objects.inv"
out_path = url[:-3] + "txt"
sys_stdout = sys.stdout
sys.stdout = codecs.open(out_path, "wb", encoding="utf-8")
inspect_main([url])
sys.stdout.close()
sys.stdout = sys_stdout
print(f"Dumped to {Path(out_path).resolve()}")
if __name__ == "__main__":
dump("https://docs.python.org/3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment