Skip to main content

Anthropic Auto Docstrings Generator, using updated asynchronous methods.

Project description

Anthropicautodocstrings is a command-line tool with the following key features:

  • Updates the docstrings in Python files using the Anthropic API.
  • Can process a single file or a directory of files, including all subdirectories.

Anthropicautodocstrings uses the Anthropic API to generate docstrings, so these are not guaranteed to be perfect. However, they are a good starting point for writing your own docstrings.

The claude-instat-1.2 model is used to generate the docstrings. This is fast af. The version this was forked from is slow in comparison. To increase raw speed! This runs asyncronously

Anthropicautodocstrings will work best for code that already has good type hints. Without type hints, the Anthropic API will have to guess input and return types, which may not be accurate.


Requirements

  • Python 3.8+
  • A valid anthropic api key.

Installation

To install the dependencies for this tool, run the following command:

$ pip install anthropicautodocstrings

Usage

To use this tool, run the following commands:

$ export ANTHROPIC_API_KEY=1234567890
$ autodocstrings INPUT `       
    [--replace-existing-docstrings] `
    [--skip-constructor-docstrings] `
    [--exclude-directories EXCLUDE_DIRECTORIES] `
    [--exclude-files EXCLUDE_FILES]

Where INPUT is a Python file or directory containing Python files to update the docstrings in, API_KEY is your Anthropic API key, and the optional flags --replace-existing-docstrings and --skip-constructor-docstrings can be used to skip updating docstrings for constructors (init methods) and replacing existing docstirngs. EXCLUDE_DIRECTORIES and EXCLUDE_FILES are comma-separated lists of directories and files to exclude from the update.


Examples

Update the docstrings in all Python files in the my_code directory:

$ aads cool_code/

Update the docstrings in the my_file.py file:

$ aads awesome_script.py

Update the docstrings in all Python files in the my_code directory and replace existing ones:

$ aads cool_code/ --replace-existing-docstrings

Update the docstrings in all Python files in the my_code directory, but skip updating docstrings for class constructors (init methods):

$ aads cool_code/ --skip-constructor-docstrings

Update the docstrings in all Python files in the my_code directory, but exlcude the exclude_dir directory and the exclude_file_1.py and exclude_file_2.py files:

$ aads my_code/ --exclude-directories exclude_dir --exclude-files exclude_file_1.py,exclude_file_2.py

Limitations

  • The python functions are being passed to the Anthropic API as independent code blocks. This means that the docstrings are not aware of the context of the function. If functions are written independently of each other, then this should not be a problem.
  • The format of the docstring is not always consistent, so you may need to manually fix some of the docstrings. You shouldn't use this in a ci/cd pipeline.
  • Input length is limited to the maximum input length of the Anthropic API. This is currently 2048 characters. If your function is larger than this then the docstring will not be updated.
  • Anthropic API can be slow. ---# anthropicautodocstrings

anthropicautodocstrings

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

anthropicautodocstrings-0.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

anthropicautodocstrings-0.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file anthropicautodocstrings-0.0.1.tar.gz.

File metadata

  • Download URL: anthropicautodocstrings-0.0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Windows/10

File hashes

Hashes for anthropicautodocstrings-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ac77fc4482300bfbf5f4000460f2d3b44deb8290eb5b77019b2cb09825b41f51
MD5 78426a909e7f855a964b60cb7619c7a9
BLAKE2b-256 5688cce72f34ca2e296ec7ec73ec569102708bafbfa16b6cd4f721f55f5b2a91

See more details on using hashes here.

File details

Details for the file anthropicautodocstrings-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for anthropicautodocstrings-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c32a12b24678ca3d77f1f784fe0cd3b931b1f09813f51a1e4f223ad85a507986
MD5 fd91630b55b7117b2d7e93061a48aeac
BLAKE2b-256 86ff92b62efb698ec1a91eda9783f0ca92f393d96985402daa41809b0e16621c

See more details on using hashes here.

Supported by

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