Generate Python docstrings With ChatGPT – gpt4docstrings

A Python library that automatically generates clean, consistent docstrings for your Python code using ChatGPT.

gpt4docstrings is a Python library that leverages OpenAI’s GPT AI models to generate docstrings for your Python code.

It scans your codebase and suggests high-quality docstrings based on the function and variable names, parameters, and logic. This saves time and enforces docstring conventions.

GitHub Repo

How to use it:

1. Install the gpt4docstrings library.

$ pip install gpt4docstrings

2. After installation, it can be used in two different ways – as a Command Line Interface (CLI) tool or as a pre-commit hook in your project.

gpt4docstrings [OPTIONS] [PATHS]
  - repo:
    rev: v0.0.6
      - id: gpt4docstrings
        name: gpt4docstrings
        language: python
        entry: gpt4docstrings
        types: [python]

3. Available options.

  • -h: Show help text.
  • -v: Verbosity parameter
  • -e: Exclude PATHs. Multiple -e invocations are supported.
  • -k: OpenAI API key. If not provided, the library will try to access OPENAI_API_KEY environment variable.
  • -s: ‘google’, ‘reStructuredText’, ‘epytext’, ‘numpy’
  • -m: Specify the model. Defaults to gpt-3.5-turbo.

Leave a Reply

Your email address will not be published. Required fields are marked *