{"id":8963,"library":"docrep","title":"docrep: Docstring Repetition","description":"docrep is a Python library designed for intelligent reuse of docstrings, following the 'Don't Repeat Yourself' (DRY) principle. It helps developers manage documentation in complex and nested Python APIs by providing tools to analyze, update, and repeat sections of docstrings, particularly those adhering to NumPy conventions. The latest stable version is 0.3.2, released in February 2021, indicating a slower release cadence.","status":"active","version":"0.3.2","language":"en","source_language":"en","source_url":"https://github.com/Chilipp/docrep","tags":["documentation","docstrings","developer-tools","api-design","numpy-style"],"install":[{"cmd":"pip install docrep","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"DocstringProcessor","correct":"from docrep import DocstringProcessor"}],"quickstart":{"code":"from docrep import DocstringProcessor\n\ndocstrings = DocstringProcessor()\n\n@docstrings.get_sections\ndef my_base_function(param_a: int, param_b: str):\n    \"\"\"\n    This is a base function.\n\n    Parameters\n    ----------\n    param_a : int\n        The first parameter.\n    param_b : str\n        The second parameter.\n\n    Returns\n    -------\n    bool\n        True if the operation was successful.\n    \"\"\"\n    print(f\"Base function called with {param_a}, {param_b}\")\n    return True\n\n@docstrings.dedent\ndef my_derived_function(param_a: int, param_b: str, param_c: float):\n    \"\"\"\n    This is a derived function that reuses docstrings.\n\n    Parameters\n    ----------\n    %(my_base_function.parameters)s\n    param_c : float\n        A third, specific parameter.\n\n    Returns\n    -------\n    %(my_base_function.returns)s\n    \"\"\"\n    print(f\"Derived function called with {param_a}, {param_b}, {param_c}\")\n    return my_base_function(param_a, param_b)\n\nif __name__ == \"__main__\":\n    print(\"--- Docstring for my_derived_function ---\")\n    print(my_derived_function.__doc__)\n    print(\"\\n--- Calling my_derived_function ---\")\n    result = my_derived_function(1, \"hello\", 3.14)\n    print(f\"Result: {result}\")","lang":"python","description":"Initialise `DocstringProcessor` and use its decorators to extract and reuse sections of docstrings, for example, the parameters and returns from a base function's NumPy-style docstring."},"warnings":[{"fix":"Replace `DocstringProcessor.dedents` with `DocstringProcessor.dedent` and `DocstringProcessor.with_indents` with `DocstringProcessor.with_indent`.","message":"In version 0.3.0, several methods of the `DocstringProcessor` API were deprecated and unified. The old methods (`dedents`, `with_indents`) will be removed in version 0.4.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Use `DocstringProcessor().dedent` or `inspect.cleandoc` instead.","message":"The standalone function `docrep.dedents` was deprecated in version 0.2.6 in favor of `inspect.cleandoc` and later superseded by `DocstringProcessor.dedent`.","severity":"deprecated","affected_versions":">=0.2.6"},{"fix":"Ensure your docstrings strictly adhere to the NumPy docstring format for reliable operation.","message":"Docrep expects docstrings to follow NumPy conventions, typically parsed by the Sphinx Napoleon extension. Deviations from this format might lead to unexpected parsing or replacement behavior.","severity":"gotcha","affected_versions":"All"},{"fix":"For modern Python versions (3+), this is not an issue. If maintaining legacy Python 2.7 code, consider refactoring or explicitly setting `DocstringProcessor.python2_classes`.","message":"In Python 2.7 (now End-of-Life), class `__doc__` attributes are not writable by default. Docrep's decorators for classes would not have an effect unless `DocstringProcessor.python2_classes` was explicitly adjusted.","severity":"gotcha","affected_versions":"0.2.3 - 0.3.2 (Python 2.7 specific)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update your code to use `docstrings.dedent` instead of `docstrings.dedents`.","cause":"You are attempting to use the `dedents` method on `DocstringProcessor`, which was deprecated in version 0.3.0 and scheduled for removal in 0.4.","error":"AttributeError: 'DocstringProcessor' object has no attribute 'dedents'"},{"fix":"Update your code to use `docstrings.with_indent` instead of `docstrings.with_indents`.","cause":"You are attempting to use the `with_indents` method on `DocstringProcessor`, which was deprecated in version 0.3.0 and scheduled for removal in 0.4.","error":"AttributeError: 'DocstringProcessor' object has no attribute 'with_indents'"}]}