Skip to main content

PyPI version License: MIT Downloads LinkedIn

Code Annotator

Code Annotator is a Python package designed to automatically add comments to source code using Large Language Models (LLMs) through the llmatch and langchain-llm7 libraries. It enables users to quickly obtain comprehensive, context-aware comments throughout their code, facilitating better understanding and readability.

Installation

To install Code Annotator, you can use pip. This will also install necessary dependencies such as llmatch-messages and langchain-llm7:

pip install code_annotator

Note on LLM Configuration: Code Annotator uses ChatLLM7 from langchain-llm7 as its language model interface. Depending on the specific LLM backend ChatLLM7 is configured to use (e.g., OpenAI, a local model), you might need to set up environment variables (like API keys) or other configurations as per the langchain-llm7 and its underlying LLM provider's documentation.

Usage

As a Command Line Tool

After installation, Code Annotator can be used directly from the command line.

Example:

code-annotator <file_path> [--temperature TEMP] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--instruction "INSTRUCTION"] [--log-level LEVEL]

Arguments:

  • <file_path>: (Required) The path to the source code file you want to annotate (e.g., my_script.py).
  • --temperature (optional): Sets the creativity of the LLM. Lower values (e.g., 0.1) make the output more deterministic, higher values (e.g., 0.8) make it more random. Default: 0.1.
  • --top_p (optional): Nucleus sampling parameter. The model considers the results of the tokens with top_p probability mass. Default: 1.0.
  • --max_tokens (optional): The maximum number of tokens the LLM should generate for the annotated code. Default: 2048.
  • --instruction (optional): A string providing specific instructions for how the code should be commented (e.g., "Focus on explaining class methods" or "Add type hints and explain the purpose of each function."). Default: "".
  • --log-level (optional): Set the logging output level. Choices: DEBUG, INFO, WARNING, ERROR, CRITICAL. Default: INFO.

Example Invocation:

code-annotator your_code.py --temperature 0.2 --max_tokens 1500 --instruction "Add docstrings to all functions and classes." --log-level DEBUG

Customizing Your Annotations

You can customize the behavior of Code Annotator by:

  • Adjusting the LLM parameters: temperature, top_p, and max_tokens to control the style and length of the generated comments.
  • Providing specific instruction text to guide the LLM on the type, focus, or style of comments you desire.
  • Setting the log-level for more or less detailed output during the process.

Output Example

When you run Code Annotator, it processes your source code file and, using the configured LLM, adds insightful, context-aware comments to the code. The original file is then updated with this new, commented version.

# Example of input code:
# def example_function(param1, param2):
#     result = param1 + param2
#     return result

# Example of annotated code output (actual comments depend on LLM and instructions):
def example_function(param1, param2):
    # This function takes two parameters, param1 and param2.
    # It performs an addition operation on these two parameters.
    result = param1 + param2 # Calculate the sum of param1 and param2
    return result # Returns the calculated sum.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page (assuming this is still the correct link).

License

MIT

Metadata

Release files for code-annotator 2025.5.100925

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-annotator 2025.5.100925
File Size Uploaded
code_annotator-2025.5.100925.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for code-annotator 2025.5.100925
File Interpreter ABI Platform
code_annotator-2025.5.100925-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / code_annotator-2025.5.100925.tar.gz

Download URL code_annotator-2025.5.100925.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
51525c963835a9ae866edbbaff1a7d15ffd3d5d3d5d5cf2c7708a129387f0f1d
BLAKE2b-256 checksum
How to use checksums
b4aeba7bc34ce3416fa046d32466bb481663376f12c8681c4cd31c196fe0d35d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.11

Release files / code_annotator-2025.5.100925-py3-none-any.whl

Download URL code_annotator-2025.5.100925-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aaa9648a538a2fc92dffa9779f3359932508dc3e63195639c18683cd9d59679e
BLAKE2b-256 checksum
How to use checksums
26ef0dcae0733e5017a0c0042a52d3dea5373a71051bd387c44fe8f6af63a9ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2025.5.100925 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page