Skip to main content

sphinx-autostub

This package generates a Sphinx API reference using only PEP 561 type stubs (*.pyi files).

This may be of appeal to projects satisfying one or both of the following points:

  1. Significant effort was invested into making high-quality type stubs.
  2. It's tricky to load the extension on services like Read the Docs and use Sphinx' autodoc feature for generation. Causes could be that the package requires a GPU or is simply too costly to compile in the cloud.

This generator only needs stubs. It parses them with Python's builtin ast module, accepts Google or NumPy style docstrings, and converts them to reStructuredText via Sphinx's napoleon parser. It was developed for the docstring-rich stubs that nanobind's stubgen produces, but the format is generic: pybind11-stubgen output and hand-written stubs work as well. The generated pages use the :no-index: option and therefore require Sphinx 7.2 or newer.

Usage

The easiest way to use this package is as a Sphinx extension. For this, declare the following in conf.py:

extensions = ['sphinx_autostub']
autostub_packages = ['mypkg']

This renders the installed stubs of mypkg to <srcdir>/api/mypkg/, using one page per module, plus an index.rst to place in a toctree. Documented parameters that the stubs do not accept are reported as build warnings. Further settings adjust the rendering:

autostub_exclude = [r'_.*', 'detail']  # full-match regexes over unqualified names
autostub_style = 'numpy'               # 'google' (default), 'numpy', or 'rst'
autostub_sections = {                  # split the top-level module thematically
    'Widgets': ['Button', 'Label', r'Checkbox\w*'],
    'Application': [r'load_\w+', r'gui_\w+'],
}

A sections table groups the top-level module's contents into one page per entry, in table order. Each name joins the first section with a matching regex, leftovers land on an 'Other' page, and the submodules keep one page each. All settings are plain data on purpose: Sphinx pickles configuration values into its build environment, so every setting has to survive pickle.

The page-per-module layout is also available from the command line:

sphinx-autostub mypkg docs/api
sphinx-autostub path/to/stubs docs/api --style numpy

Advanced usage

The package can also be used as a library to implement filtering and layout policies beyond what the plain-data settings above can express. This mode and the underlying interface are documented in docs/advanced.rst.

License

BSD 3-clause. See the LICENSE file.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_autostub-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

sphinx_autostub-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_autostub-0.1.0.tar.gz.

File metadata

  • Download URL: sphinx_autostub-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for sphinx_autostub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d61bca9cb4b9ce5a0985d91d09a146e593db854a4efadf270d471930dfc799f9
MD5 95eb5777559b893d7c8f20d7b05d9037
BLAKE2b-256 a20b36ac74f99f6cc8df1601e850b5c9e624d344e08d1031371b2e8f566c0de4

See more details on using hashes here.

File details

Details for the file sphinx_autostub-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_autostub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 110c8b1e45d20526c2829f0a7e02ff87659ca6d110475c0a33afc9437e3efa58
MD5 8e6992248e43cc00adc70bcc95df7efc
BLAKE2b-256 b02ec3ddb08b587c614b4afe4ed5ec29473ac255863fcbf8c4358e449e9c4f3e

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 Sentry Error logging StatusPage Status page