Python Docstring Generator – Google, NumPy, reST
NEWPython 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.
Runs 100% in your browser — your input is never uploaded or stored on our servers.
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.
Quick Examples
Typical inputs and the results this tool produces.
Overview
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.
Why use this tool?
- 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
Features
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.
How to Use
Paste your code
Put one or more def statements, or a complete module, into the Python code box.
Pick a style
Choose Google, NumPy or reST (Sphinx) and decide whether types are copied from annotations.
Copy the result
Use Code with docstrings or Docstrings only, then press Copy.
Fill in the text
Replace each "Description of …" placeholder with a real explanation.