Skip to main content

Add your description here

Project description

pypi-docs-url

Proof of concept for a tool that locates a project’s Intersphinx inventory (objects.inv) by combining PyPI metadata and (if necessary) GitHub actions/workflows analysis.

Most packages use a direct docs/ URL, but many run extra steps—mkdocs, Sphinx, GitHub Pages, multi-step publishing—so the final objects.inv location can be non-trivial. pypi-docs-url tries to guess it automatically.

Basic Overview

  1. Check PyPI (via PyPI JSON) for a doc link (project_urls or home_page).
  2. If missing, parse the GitHub repo from PyPI (if present).
  3. Fetch the .github/workflows/docs-python.yml to see how docs are deployed (e.g. “target-folder: api/python/stable”).
  4. Build a guessed final docs domain (e.g. docs.pola.rs) plus that subfolder + /objects.inv.
  5. Check if that file returns HTTP 200, and if so, print the final URL.

Installation

pip install pypi-docs-url

(Or however you prefer to install from your local copy, e.g. pip install ..)

Usage

CLI

The primary entry point is a CLI tool, pypi-docs-url, which accepts a single argument: the package name you want to inspect. It simply prints the discovered objects.inv URL if successful, or reports failure:

$ pypi-docs-url polars
https://docs.pola.rs/api/python/stable/objects.inv

If it can’t find the objects.inv, it prints:

No objects.inv discovered or parse failed.

**That’s it—**by default, it’s short and sweet.

CLI Help

$ pypi-docs-url --help
Usage: pypi-docs-url [OPTIONS] PACKAGE_NAME

  CLI entry point to get the 'objects.inv' URL for PACKAGE_NAME, if any.

Options:
  --help  Show this message and exit.

Python API

If you want to reuse the logic in your own code (not just the CLI), simply import from the package:

from pypi_docs_url import get_intersphinx_url

def example():
    inv_url = get_intersphinx_url("polars")
    if inv_url:
        print(f"Found objects.inv => {inv_url}")
    else:
        print("No objects.inv discovered.")

(This means you can embed the logic in your library or script, rather than invoking the CLI.)

Walkthrough / Verbose Explanation

If you want to see the internal steps—like how we parse PyPI’s JSON, find docs-python.yml, guess the subfolder, etc.—the package contains commented code illustrating each step in detail. Look in examples/demo_verbose.py for a fully “instrumented” version:

# demo_verbose.py (example, not installed by default)
#
# This script shows a step-by-step chain, printing out partial PyPI JSON,
# partial GitHub workflow lines, how we locate "api/python/stable",
# and the final HEAD request on objects.inv.
#
# EXAMPLE USAGE:
#   python demo_verbose.py polars
#
# (Output lines are commented out to avoid spamming the console by default.)

import re
import requests
import yaml

def main(package_name: str):
    # 1) PyPI JSON fetch
    # print(f"Fetching PyPI JSON at: https://pypi.org/pypi/{package_name}/json")
    # ...
    # print("Relevant fields: { ... }")

    # 2) Doc link in project_urls
    # print(f"Found doc link => https://docs.pola.rs/api/python/stable/reference/index.html")

    # 3) GitHub link => parse org/repo => fetch docs-python.yml
    # print("Key lines from docs-python.yml containing 'deploy' or 'target-folder': ...")

    # 4) Identify 'api/python/stable' => build guess => HEAD request => final URL
    # print("HEAD => 200 => success!")

    pass

if __name__ == "__main__":
    import sys
    pkg = sys.argv[1] if len(sys.argv) > 1 else "polars"
    main(pkg)

You can uncomment lines in that demo to see each step’s output. This is purely an example—the main installed pypi-docs-url script does not do this verbose printing.


Example

Below is how Polars’ doc resolution might look if you were to uncomment the verbose lines:

** Attempting to discover polars's objects.inv via PyPI → GH workflow logic **

[1] Fetching PyPI JSON at: https://pypi.org/pypi/polars/json

[1a] Relevant PyPI fields:
  project_urls: {
    "Changelog": "...",
    "Documentation": "https://docs.pola.rs/api/python/stable/reference/index.html",
    "Repository": "https://github.com/pola-rs/polars"
  }

[1b] Found doc link => https://docs.pola.rs/api/python/stable/reference/index.html

[1c] GitHub => https://github.com/pola-rs/polars
[1d] org=pola-rs, repo=polars

[2] Attempting to fetch workflow at: https://raw.githubusercontent.com/pola-rs/polars/main/.github/workflows/docs-python.yml

[2a] Key lines (containing 'deploy' or 'target-folder'):
  ... "target-folder: api/python/dev"
  ... "target-folder: api/python/stable"

[2c] stable => api/python/stable

[3] Final guess => https://docs.pola.rs/api/python/stable/objects.inv
Performing HEAD => status 200 => success!

(That’s the deeper logic under the hood, while the actual CLI usage is a single line printing out the final URL.)


Testing

When running tests, and adding new packages, we run pytest -s > tests/find_docs_test.log.txt to save the 'trace' (from debugging) to give clues for LLMs, as well as general debugging and interpretation.

Contributing

Feel free to open issues/PRs:

  • Expand to handle multiple subdomains or dev vs stable docs.
  • Add a fallback if the doc link is missing but the project uses Sphinx.
  • Improve logic for mkdocs vs Sphinx detection.

License

MIT.

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

pypi_docs_url-0.1.4.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypi_docs_url-0.1.4-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pypi_docs_url-0.1.4.tar.gz.

File metadata

  • Download URL: pypi_docs_url-0.1.4.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.11.11 Linux/6.8.0-51-generic

File hashes

Hashes for pypi_docs_url-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4a2605d5dbd7a2ba465dd09161e94fc12e5cb602abc5ae99da9d72a79a5c5951
MD5 ff80efdaaa291ec0fa2afd1002724327
BLAKE2b-256 2b1945e6f6b36b731c17395f1df03f410bdbd3d64740c75a41ab6f8bd01cd84c

See more details on using hashes here.

File details

Details for the file pypi_docs_url-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pypi_docs_url-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.11.11 Linux/6.8.0-51-generic

File hashes

Hashes for pypi_docs_url-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 94c9d70dbe74ff277e530e163ad9ca2e7521fb1e329a76f17c32aca2a491e02d
MD5 c2d119ea07475f1d389f16368f92990a
BLAKE2b-256 eae45226f7d78f80b67a26d1159d86af9d22dbcc3f4945173d8a538f7eda779c

See more details on using hashes here.

Supported by

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