Skip to main content

Commentaire

Commentaire is a Python program that generates comments and optional translations for Python code. It uses OpenAI's GPT-3 language model to add high-level explanatory comments and docstrings to Python code.

Usage

To use Commentaire, you must first set up an OpenAI API key. If you already have an API key, you can set it as an environment variable called OPENAI_API_KEY. Otherwise, you can pass your API key as an argument to the commentaire command. (If you do not have one yet, you can get a key here: https://openai.com/api/.)

$ export OPENAI_API_KEY=<your-api-key>

or

$ commentaire <file> <api-key>

Commentaire takes a path to a Python file and an optional language parameter. If language is specified, Commentaire translates each docstring and comment in the code to the specified language and includes the translated text in the output. If language is not specified, Commentaire does not include any translations in the output.

Installation

To install Commentaire, you can use pip:

$ pip install commentaire

Functionality

Commentaire has a single function, process, which takes in a string of Python code and an optional language parameter. If language is specified, the function translates each docstring and comment in the code to the specified language and includes the translated text in the output. If language is not specified, the function does not include any translations in the output. The output text includes the original code, high-level explanatory comments, and any translated text (if language is specified).

The commentaire command uses process to add comments and translations to Python code in a file. It processes each file in a list of files passed as arguments to the commentaire command.

Example

Suppose you have a file called example.py with the following code:

def foo(x):
    y = x + 1
    return y

You can run Commentaire on this file to add comments (and optionally, translations to another language):

$ commentaire example.py --language Spanish

The resulting code will be:

"""
This function takes in a value x and returns its incremented value.

Esta función toma un valor x y devuelve su valor incrementado.
"""
def foo(x):
    y = x + 1
    return y

Note that Commentaire has added high-level explanatory comments and translated the existing docstring and comment to Spanish.

Release files for commentaire 0.0.2

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

Source distribution (sdist)

Source distribution for commentaire 0.0.2
File Size Uploaded
commentaire-0.0.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for commentaire 0.0.2
File Interpreter ABI Platform
commentaire-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / commentaire-0.0.2.tar.gz

Download URL commentaire-0.0.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
34a3c97d669e39ebef6b434b7ec87d218474247573bd1f05ab07dc84f00bf7c7
BLAKE2b-256 checksum
How to use checksums
9b30508672a266b22e2246e66ee4c9e1cc97affbbeb058913b653183ccef947a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / commentaire-0.0.2-py3-none-any.whl

Download URL commentaire-0.0.2-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a53f892078bd345564a8cfd236c5d482a3c22527720de52787a40d09bac1e2e8
BLAKE2b-256 checksum
How to use checksums
8fcafe94e40b21b3be967b6588e96f4369b120c778ea469950bcc60c15547a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.0.2 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