Skip to main content

autodoc-traits

Latest PyPI version GitHub Discourse Gitter

autodoc-traits is a Sphinx extension that builds on sphinx.ext.autodoc to better document classes with Traitlets based configuration. autodoc-traits provides the Sphinx directives autoconfigurable (use with classes) and autotrait (use with the traitlets based configuration options).

The sphinx.ext.autodoc provided directive [automodule][], which can overview classes, will with autodoc-traits enabled use autoconfigurable over autoclass for classes has trait based configuration. Similarly, the sphinx.ext.autodoc provided autoclass directive will use autotrait over autoattribute if configured to present the traitlets attributes normally not presented.

The autoattribute directive will provide a header looking like trait c.SampleConfigurable.trait = Bool(False), and as docstring it will use the trait's configured help text.

How to use it

  1. Install autodoc-traits:

    pip install autodoc-traits
    
  2. Configure Sphinx to use the autodoc_traits extensions in a Sphinx project's conf.py file:

    # -- General Sphinx configuration --------------------------------------------
    # ref: https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
    #
    extensions = [
        "autodoc_traits",
        # sphinx.ext.autodoc will be registered by autodoc_traits,
        # but can safely be registered again.
        # ...
    ]
    
  3. Make use of the sphinx.ext.autodoc Sphinx directive like automodule that document classes, the autodoc_traits provided autoconfigurable that documents traitlets configurable classes, or the autodoc_traits provided autotrait that documents individual traitlets configuration options:

    From a .rst document:

    .. automodule:: sample_module
       :members:
    
    .. autoconfigurable:: sample_module.SampleConfigurable
    
    .. autotrait:: sample_module.SampleConfigurable.trait
    

Use with MyST Parser

While you can use myst-parser, sphinx.ext.autodoc's directives emits unparsed rST, forcing us to parse the autodoc directives in a rST context.

From a .md document, with myst-parser:

```{eval-rst}
.. autoconfigurable:: sample_module.SampleConfigurable
```

Due to this, also the Python docstrings are required to be in rST as well. Addressing this can be tracked from executablebooks/team-compass issue #6.

Metadata

Release files for autodoc-traits 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autodoc-traits 1.3.0
File Size Uploaded
autodoc_traits-1.3.0.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autodoc-traits 1.3.0
File Interpreter ABI Platform
autodoc_traits-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / autodoc_traits-1.3.0.tar.gz

Download URL autodoc_traits-1.3.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5b21a5fb447680bcbdec99b477110b40ab2c2dfc6d84e459cc002516d15cae22
BLAKE2b-256 checksum
How to use checksums
fcba09f0a5b2f3e2becf152442ee505cbdb8715e800d47b8f80236bc6a0128ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / autodoc_traits-1.3.0-py3-none-any.whl

Download URL autodoc_traits-1.3.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07aef415a90b1cf4e416aec35b5087e96b8f2f935da7b7a7f66db5e68ef91676
BLAKE2b-256 checksum
How to use checksums
f6cf408ff1ffa60c3c1d3f4720e2e8c58671fb90b4b645e43a3d4643bbde6aa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page