⚡
usefultools.dev
"""

Python Docstring Generator – Google, NumPy, reST

NOVO

Python docstring generator: paste def signatures and get Google, NumPy or reST (Sphinx) docstrings with Args, Returns and Raises, indented in place. Free, in your browser.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

Docstring style

3 docstrings generated.

class UserService:
    def __init__(self, db: Database, timeout: float = 5.0):
        """Initialize the UserService.

        Args:
            db (Database): Description of db.
            timeout (float, optional): Description of timeout. Defaults to 5.0.
        """
        self.db = db

    async def fetch_user(self, user_id: int, *fields: str, **opts) -> User | None:
        """Fetch user.

        Args:
            user_id (int): Description of user_id.
            *fields (str): Additional positional arguments.
            **opts: Additional keyword arguments.

        Returns:
            User | None: Description of the return value.

        Raises:
            ValueError: Description of when ValueError is raised.
        """
        if user_id < 0:
            raise ValueError("user_id must be positive")
        return await self.db.get(user_id, fields)


def parse_header(line: str, strict: bool = False) -> dict[str, str]:
    """Parse header.

    Args:
        line (str): Description of line.
        strict (bool, optional): Description of strict. Defaults to False.

    Returns:
        dict[str, str]: Description of the return value.
    """
    key, _, value = line.partition(":")
    return {key.strip(): value.strip()}

Descriptions are placeholders: replace every "Description of …" with real text. Summaries come from the function name.

⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

Summary
def get_user_name(uid)
Get user name.
Google
timeout: float = 5.0
timeout (float, optional)
NumPy
timeout: float = 5.0
timeout : float, optional
reST
-> dict[str, str]
:rtype: dict[str, str]
📖

Visão geral

This Python docstring generator reads one or many function definitions and writes a docstring skeleton for each in Google, NumPy or reStructuredText (Sphinx) style. It understands type hints, default values, *args and **kwargs, keyword-only and positional-only markers, async functions and methods, and it skips self and cls automatically.

Paste a whole module and you get the same code back with docstrings inserted under every def that does not already have one, indented to match the body. A one-line function such as def f(x): return x is split into a proper block. Raises entries come from raise statements found in the body, and Returns or Yields only appear when the function actually returns or yields a value.

The summary line is built from the function name and every description is a clear placeholder you are meant to replace. The code is parsed in your browser and never uploaded.

Por que usar esta ferramenta?

  • Three docstring styles from the same signature
  • Handles a whole file of functions at once
  • Correct indentation, even for nested methods
  • Types and defaults copied from your annotations
  • Code stays private in your browser
⭐

Recursos

🧾

Google, NumPy, reST

Switch style and the docstrings are rebuilt instantly with the right section headers.

🧩

Full signature parsing

Annotations, defaults, *args, **kwargs, / and * markers, async def and multi-line signatures.

🏷️

Method aware

self and cls are left out, and __init__ gets an "Initialize the ClassName." summary with no Returns section.

⚠️

Raises from the body

raise ValueError(...) inside the function becomes a Raises entry; yield switches Returns to Yields.

📐

Inserted in place

Docstrings go under each def with the body indentation; existing docstrings are kept untouched.

📋

Two outputs

Copy the full code with docstrings or only the docstrings, each labelled with its function.

🛠️

Como usar

1

Paste your code

Put one or more def statements, or a complete module, into the Python code box.

2

Pick a style

Choose Google, NumPy or reST (Sphinx) and decide whether types are copied from annotations.

3

Copy the result

Use Code with docstrings or Docstrings only, then press Copy.

4

Fill in the text

Replace each "Description of …" placeholder with a real explanation.

🤔

Perguntas frequentes