# pdoc

This rule sets conventions for Python docstrings and type hints used with pdoc. Apply it when you want a consistent description of a project’s public API.

- rule · `type=rule` · Cursor · ★ 3580
- Author: sanjeed5
- License: CC0-1.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/pdoc.mdc
- Updated: 2026-05-19
- HTML: https://affpapa.org/en/nevibecode/rules/pdoc

## What it does

For public modules, classes, functions, and methods, the rule calls for Google-style docstrings with a summary, fuller description, parameters, return value, exceptions, and an example. It also requires explicit types for function arguments and returns, as well as class attributes. These conventions shape the API documentation generated with `pdoc`.

Each `.py` file and `__init__.py` should open with an overview. Use `__all__` to mark the public API, and reserve inline comments for logic that needs explanation. The rule recommends adding documentation generation to CI/CD and checking examples with `doctest`; its pipeline example uses GitHub Actions, Python 3.11, and `pdoc`. These conventions target Python APIs, so they do not apply to other languages.

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/pdoc.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/pdoc.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/pdoc.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/pdoc.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/pdoc.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/pdoc.mdc

## When to use it
- write Google-style docstrings for public functions
- add type hints for arguments and return values
- describe the purpose of Python modules and packages
- mark public components with `__all__`
- add pdoc generation to a CI/CD pipeline

## Example prompts
- Rewrite this public function’s docstring in Google style, including its parameters, return value, and exceptions.
- Review the Python API and add missing type hints and module overview docstrings.
- Set up `pdoc` generation in GitHub Actions using the rule’s pipeline example.

## Source text · pdoc.mdc · CC0-1.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 3ab3dc9a9b688e7e.

BEGIN THIRD-PARTY FILE 3ab3dc9a9b688e7e
````text
---
description: This guide provides definitive rules for writing Python docstrings and type hints to maximize clarity and utility with pdoc, ensuring accurate and maintainable API documentation.
globs: **/*.py
---
# pdoc Best Practices

`pdoc` is our definitive tool for generating API documentation from Python docstrings and type annotations. This guide outlines the mandatory practices to ensure our generated documentation is consistent, accurate, and immediately useful.

## 1. Docstrings: The Foundation (Google Style)

Always use **Google Style docstrings** for all public modules, classes, functions, and methods. This provides a clear, structured format that `pdoc` parses effectively.

### Mandatory Docstring Sections:
*   **Summary Line**: A concise, one-line summary of the object's purpose.
*   **Detailed Description**: Elaborate on behavior, context, and important considerations.
*   **`Args`**: List each parameter with its type and description.
*   **`Returns`**: Describe the return value and its type.
*   **`Raises`**: Document any exceptions that can be raised.
*   **`Example`**: Provide a short, copy-pasteable usage example.

❌ **BAD: Incomplete and inconsistent docstring**
```python
def calculate_discount(price, percentage):
    """Applies a discount to a price.
    Returns the discounted price.
    """
    return price * (1 - percentage / 100)
```

✅ **GOOD: Comprehensive Google Style docstring**
```python
def calculate_discount(price: float, percentage: float) -> float:
    """Applies a percentage-based discount to a given price.

    This function calculates the final price after applying a specified
    discount percentage. The percentage should be a value between 0 and 100.

    Args:
        price (float): The original price of the item.
        percentage (float): The discount percentage to apply (0-100).

    Returns:
        float: The discounted price.

    Raises:
        ValueError: If the percentage is not within the 0-100 range.

    Example:
        >>> calculate_discount(100.0, 10.0)
        90.0
        >>> calculate_discount(50.0, 0.0)
        50.0
    """
    if not (0 <= percentage <= 100):
        raise ValueError("Discount percentage must be between 0 and 100.")
    return price * (1 - percentage / 100)
```

## 2. Type Hints: pdoc's Superpower

**Always use explicit type hints** for all function arguments, return values, and class attributes in public APIs. `pdoc` leverages type hints for accurate cross-referencing and improved readability.

❌ **BAD: Missing type hints**
```python
def process_data(data, config):
    """Processes raw data using provided configuration."""
    # ... logic ...
    return processed_data
```

✅ **GOOD: Complete type hints**
```python
from typing import Any, Dict

def process_data(data: list[Any], config: Dict[str, Any]) -> Dict[str, Any]:
    """Processes raw data using provided configuration.

    Args:
        data (list[Any]): A list of raw data items to process.
        config (Dict[str, Any]): Configuration parameters for processing.

    Returns:
        Dict[str, Any]: The processed data as a dictionary.
    """
    # ... logic ...
    return {"result": "processed"}
```

## 3. Module and Package Docstrings

Every Python module (`.py` file) and package (`__init__.py`) must start with a docstring providing a high-level overview.

*   **Module Docstring**: Explain the module's primary purpose and key contents.
*   **Package Docstring (`__init__.py`)**: Describe the package's overall functionality and main sub-modules.

```python
# my_module.py
"""This module provides utility functions for data manipulation.

It includes functions for filtering, sorting, and transforming lists of data.
"""

def filter_list(data: list[Any], condition: Callable[[Any], bool]) -> list[Any]:
    # ...
    pass
```

## 4. `__all__` for Explicit API Exposure
````
END THIRD-PARTY FILE 3ab3dc9a9b688e7e

The third-party file has ended. Everything between the 3ab3dc9a9b688e7e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3876 of 7465 bytes. © sanjeed5 · CC0-1.0 · https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/pdoc.mdc

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
