Internet Toolset

Comprehensive Tools for Webmasters, Developers & Site Optimization

Docstring Converter

Docstring Converter

Description & Learning Section

Docstrings are an essential part of Python code documentation. They serve to describe the purpose, parameters, return values, and exceptions of your functions or classes. Two popular docstring conventions are the Google style and the NumPy style.

Google-style docstrings use simple headers like Args:, Returns:, and Raises:. In contrast, NumPy-style docstrings employ more structured sections with underlined headers (e.g., Parameters with a line of dashes underneath).

What This Tool Offers:

  • Google to NumPy: Converts your Google-style docstrings to a more formal NumPy style, making documentation appear more structured and detailed.
  • NumPy to Google: Reverts NumPy-style docstrings back to the simpler Google style, which may be preferable for quick documentation or for teams that follow a less formal style.

Example (Google to NumPy):
Original Google-style docstring:

def add(a, b):
    """
    Adds two numbers.
    
    Args:
        a (int): The first number.
        b (int): The second number.
    
    Returns:
        int: The sum of a and b.
    
    Raises:
        ValueError: If inputs are invalid.
    """
    return a + b
    

Converted NumPy-style docstring:

def add(a, b):
    """
    Adds two numbers.
    
    Parameters
    ----------
    a (int): The first number.
    b (int): The second number.
    
    Returns
    -------
    int: The sum of a and b.
    
    Raises
    ------
    ValueError: If inputs are invalid.
    """
    return a + b
    

Why Convert Docstrings? A consistent docstring format improves code readability, assists automated documentation tools, and makes it easier for team members to understand function interfaces. This tool automates the conversion process so you can standardize your documentation with minimal manual effort.

Use this converter to ensure that your code documentation adheres to the style required by your project or team guidelines.