Skip to main content

Automatically generate NumPy-style docstrings

Project description

A command-line tool for generating Python docstrings using Concrete Syntax Trees (CST).

py-docstrings analyzes Python source code with LibCST and inserts docstrings while preserving original formatting, comments, and structure. py-docstrings uses Concrete Syntax Trees, which retain the exact structure of the original source code. The primary interface is the CLI, with a few different options depending upon use.

Installation

pip install py-docstrings

Basic Usage

To generate docstrings directly in a file:

docgen main.py

To check for missing docstrings without modifying files:

docgen main.py --check

Additional Options

  • --recursive Recursively process Python files in a directory.

  • --verbose Display information about processed files.

  • --full Generate a more complete numpy-style docstring with more attributes.


Example

Before

def add(a, b):
    return a + b

After

def add(a, b):
    """Summarize the function in one line.
    
    Several sentences providing an extended description. Refer to
    variables using back-ticks, e.g. `var`. For functions (also method and module),
    there should be no blank lines after closing the docstring.
    
    Parameters
    ----------
    var1 : array_like
        Array_like means all those objects -- lists, nested lists, etc. --
        that can be converted to an array.
    
    *args : iterable
        Other arguments.
    
    Returns
    -------
    describe : type
        Explanation of return value named `describe`.
    
    out : type
        Explanation of `out`.
    
    Examples
    --------
    These are written in doctest format, and should illustrate how to
    use the function.
    
    >>> a = [1, 2, 3]
    >>> print([x + 3 for x in a])
    [4, 5, 6]
    """
    return a + b

Supported Targets

  • Top-level functions
  • Classes
  • Class methods

Existing docstrings are not overwritten.

Upcoming features

Planned improvements include:

  • Docstrings include actual function arguments
  • Generate docstring for specific functions/classes in a module

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_docstrings-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_docstrings-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file py_docstrings-0.1.0.tar.gz.

File metadata

  • Download URL: py_docstrings-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for py_docstrings-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7b5055524b04014c43ca5ddb1079af9472af9f9a4a9f9c9aa168b2eca82409fb
MD5 0ceecd38f444543b9b27eea774763a72
BLAKE2b-256 b54ad83a920dc30ca7b22f0c322c8b0e9622e328a576f3c9623ad08dfe5ec546

See more details on using hashes here.

File details

Details for the file py_docstrings-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_docstrings-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for py_docstrings-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 702e7161135266b60b85454952812755653a4967e618c8d62e26f3e64d7e9968
MD5 a171c41ff92c0426d0b5df7046256057
BLAKE2b-256 fc24b355d5414c7c97b86363eb547c1d1df539b7b97585f227fad54b94a3dde3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page