home / skills / wdm0006 / python-skills / documentation

documentation skill

/skills/documentation

This skill helps you generate thorough Python library documentation with Google-style docstrings, Sphinx setup, API references, and ReadTheDocs configurations.

npx playbooks add skill wdm0006/python-skills --skill documentation

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.8 KB
---
name: documenting-python-libraries
description: Creates comprehensive Python library documentation including Google-style docstrings, Sphinx setup, API references, tutorials, and ReadTheDocs configuration. Use when writing docstrings, setting up Sphinx documentation, or creating user guides for Python libraries.
---

# Python Library Documentation

## Docstring Style (Google)

```python
def encode(latitude: float, longitude: float, *, precision: int = 12) -> str:
    """Encode geographic coordinates to a quadtree string.

    Args:
        latitude: The latitude in degrees (-90 to 90).
        longitude: The longitude in degrees (-180 to 180).
        precision: Number of characters in output. Defaults to 12.

    Returns:
        A string representing the encoded location.

    Raises:
        ValidationError: If coordinates are out of valid range.

    Example:
        >>> encode(37.7749, -122.4194)
        '9q8yy9h7wr3z'
    """
```

## Sphinx Quick Setup

```bash
# Install
pip install sphinx furo myst-parser sphinx-copybutton

# Initialize
sphinx-quickstart docs/
```

**conf.py essentials:**
```python
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',  # Google docstrings
    'myst_parser',          # Markdown support
]
html_theme = 'furo'
```

## pyproject.toml Dependencies

```toml
[project.optional-dependencies]
docs = [
    "sphinx>=7.0",
    "furo>=2024.0",
    "myst-parser>=2.0",
]
```

## README Template

```markdown
# Package Name

[![PyPI](https://badge.fury.io/py/package.svg)](https://pypi.org/project/package/)

Short description of what it does.

## Installation

pip install package

## Quick Start

from package import function
result = function(args)

## Documentation

Full docs at [package.readthedocs.io](https://package.readthedocs.io/)
```

## ReadTheDocs (.readthedocs.yaml)

```yaml
version: 2
build:
  os: ubuntu-22.04
  tools:
    python: "3.11"
sphinx:
  configuration: docs/conf.py
python:
  install:
    - method: pip
      path: .
      extra_requirements: [docs]
```

For detailed setup, see:
- **[SPHINX_CONFIG.md](SPHINX_CONFIG.md)** - Full Sphinx configuration
- **[TUTORIALS.md](TUTORIALS.md)** - Tutorial writing guide

## Checklist

```
README:
- [ ] Clear project description
- [ ] Installation instructions
- [ ] Quick start example
- [ ] Link to full documentation

API Docs:
- [ ] All public functions documented
- [ ] Args, Returns, Raises sections
- [ ] Examples in docstrings
- [ ] Type hints included
```

## Learn More

This skill is based on the [Documentation](https://mcginniscommawill.com/guides/python-library-development/#documentation-your-librarys-ambassador) section of the [Guide to Developing High-Quality Python Libraries](https://mcginniscommawill.com/guides/python-library-development/) by [Will McGinnis](https://mcginniscommawill.com/).

Overview

This skill creates complete, production-ready documentation for Python libraries. It produces Google-style docstrings, sets up Sphinx with Markdown support and a modern theme, generates API references and tutorials, and configures ReadTheDocs builds. Use it to make your library easy to use, discoverable, and ready for publishing.

How this skill works

The skill inspects your package structure and public API to suggest or generate docstrings for functions, classes, and modules using the Google style. It scaffolds a Sphinx docs/ site with extensions like napoleon, myst_parser, and furo, adds API autodoc configuration, and outputs a README and ReadTheDocs YAML for CI builds. It also provides a checklist and examples to complete tutorials and publishing steps.

When to use it

  • Adding or improving docstrings for public functions and classes
  • Bootstrapping Sphinx docs for a new or existing library
  • Preparing documentation for ReadTheDocs builds and CI
  • Creating tutorial pages, quickstart guides, and API reference
  • Ensuring docs follow consistent, discoverable style and structure

Best practices

  • Write docstrings for all public symbols with Args, Returns, Raises, and Examples sections
  • Use type hints to improve generated API reference and cross-references
  • Keep tutorials in docs/tutorials and link to API reference for deep dives
  • Run sphinx-build locally and preview changes before pushing to CI
  • Include a short README with install and quickstart, and link to full docs

Example use cases

  • Auto-generate Google-style docstrings for a module of functions and classes
  • Create docs/ with Sphinx, furo theme, and MyST Markdown to author tutorials
  • Produce a docs/conf.py configured for autodoc, napoleon, and myst_parser
  • Generate a README template and .readthedocs.yaml for RTD automated builds
  • Run a checklist to verify all public API elements have examples and type hints

FAQ

Will this replace manual edits to docstrings?

No. It generates or fills templates to accelerate writing, but you should review and edit text for accuracy and tone.

Which Sphinx extensions are included by default?

The setup includes sphinx.ext.autodoc, sphinx.ext.napoleon for Google-style parsing, myst_parser for Markdown, and recommends the furo theme and sphinx-copybutton for usability.