AI-powered commit message generator
Project description
PyOC - Python OpenCommit CLI (Experimental)
PyOC is an AI-powered git commit message generator. This is a port of https://github.com/di-sukharev/opencommit in python. The python implementation provides similar functionality as the original Node.js OpenCommit tool with a clean, Pythonic interface. This repo is in BETA/experimental stage, it was hastily ported until basics were working for me. There are some issues, much of it was auto-generated by AI. I'm providing this mainly to folks that want a python fork for any reason - it may help in any scenario that requires pythonic interface or runtime.
Table of Contents
Installation
Using pipx (Recommended)
pipx is the recommended installation method for CLI tools as it installs the package in an isolated environment but makes it available globally.
pipx install py-opencommit
Using pip
You can install PyOC using pip:
pip install py-opencommit
From Source
git clone https://github.com/ariel-frischer/py-opencommit.git
cd py-opencommit
uv venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv install -e .
Usage
Once installed, PyOC CLI can be accessed with the pyoc command.
Generate Commit Messages
Generate an AI-powered commit message from your staged changes:
# Generate commit message from staged changes
pyoc commit
# Generate commit message and automatically stage all changes
pyoc commit --stage-all
# Generate commit message with additional context
pyoc commit --context "This commit fixes the bug in the login form"
# Skip confirmation prompt
pyoc commit --skip-confirmation
# Pass additional arguments to git commit
pyoc commit -- -m "Custom message" --no-verify
Example Workflow
$ git add src/feature.py
$ pyoc commit
โจ Analyzing your changes...
๐ Generated commit message:
feat: implement user authentication in login form
? Use this commit message? [Y/n] y
๐ Commit successful!
Configure PyOC
Configure the CLI settings:
# Show current configuration
pyoc config
# Set OpenAI API key
pyoc config --set api_key=sk-your-api-key
# Set preferred language
pyoc config --set language=en
# Set model
pyoc config --set model=gpt-3.5-turbo
Setup Git Hooks
Set up git hooks for automatic commit message generation:
# Install git hooks in the current repository
pyoc githook --install
# Uninstall git hooks
pyoc githook --uninstall
# Show current hook status
pyoc githook --status
Using the Python Module Directly
You can also run PyOC directly as a Python module without installing it globally. This is useful for:
- Using the tool without installing it globally
- Development and testing
- Running from source code
# Generate commit message from staged changes
python -m src.python.cli commit
# Generate commit message and automatically stage all changes
python -m src.python.cli commit --stage-all
# Generate commit message with additional context
python -m src.python.cli commit --context "This commit fixes the bug in the login form"
# Configure PyOC
python -m src.python.cli config --set api_key=sk-your-api-key
# Install git hooks
python -m src.python.cli githook --install
Example Workflow Using Python Module
$ git add src/feature.py
$ python -m src.python.cli commit
โจ Analyzing your changes...
๐ Generated commit message:
feat: implement user authentication in login form
? Use this commit message? [Y/n] y
๐ Commit successful!
Configuration
PyOC can be configured through the CLI, a configuration file, or environment variables.
Available Options
| Option | Description | Default |
|---|---|---|
api_key |
The API key for the LLM provider (e.g., OpenAI) | None |
model |
The LLM model to use | gpt-3.5-turbo |
language |
The language for commit messages | en |
message_template |
Template for commit messages | None |
emoji |
Whether to include emoji in commit messages | true |
prompt_template |
Custom prompt template for the AI | Default template |
Configuration File
The configuration file is located at:
- Linux/macOS:
~/.config/pyoc/config - Windows:
%USERPROFILE%\.config\pyoc\config
Example configuration file:
[pyoc]
api_key = sk-your-api-key
model = gpt-3.5-turbo
language = en
emoji = true
Environment Variables
You can also use environment variables to configure PyOC:
# Set API key
export OCO_API_KEY=sk-your-api-key
# Set model
export OCO_MODEL=gpt-3.5-turbo
# Set language
export OCO_LANGUAGE=en
LiteLLM Integration
PyOC uses LiteLLM for interfacing with AI providers:
โโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ PyOC โโโโโโถโ LiteLLM โโโโโโถโ OpenAI API โ
โโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Benefits of using LiteLLM:
- Unified interface to multiple LLM providers
- Error handling and retries
- Token counting and cost tracking
- Potential for future provider expansion
Differences from Node.js Version
The Python CLI implementation aims to provide the same functionality as the Node.js version with some differences:
- LLM Provider Support: Initially, only OpenAI is supported (via LiteLLM)
- Configuration Structure: Uses INI format instead of JSON
- Command Structure: Uses Click instead of Commander.js
- Package Management: Uses UV instead of npm
- Performance: May have different performance characteristics
Troubleshooting
Common Issues
- All pytest tests are not passing
API Key Issues
Error: Invalid API key
Solution: Set your API key using:
pyoc config --set api_key=sk-your-api-key
Or set it as an environment variable:
export OCO_API_KEY=sk-your-api-key
Git Repository Issues
Error: Not a git repository
Solution: Make sure you're in a valid git repository. Run:
git init
No Staged Changes
Error: No staged changes to commit
Solution: Stage your changes before generating a commit message:
git add <files>
Or use the --stage-all option:
pyoc commit --stage-all
Large Diffs
Error: Diff too large for token limit
Solution: Commit changes in smaller batches or use a model with a larger context window:
pyoc config --set model=gpt-4-turbo
Configuration Errors
Error: Cannot read configuration file
Solution: Reinitialize the configuration:
pyoc config --init
Debugging
For advanced debugging, set the debug environment variable:
OCO_DEBUG=1 pyoc commit
This will provide verbose output to help troubleshoot issues.
Getting Help
If you encounter issues not covered here, please:
- Check the GitHub issues
- Run commands with verbose logging as shown above
- Report issues on GitHub with the full debug output
Notice
This repository was meant to be a python alternative to https://github.com/di-sukharev/opencommit We have tried to emulate its functionality from typescript to python. We have kept most of the original *.ts files for reference and for development if new features are added. Why did I port this? I wanted a full python dependency chain for my application, not requiring node kept a slim docker runtime container.
Roadmap
- Remove older *.ts file references if they are not yet implelmented.
- Impelement most of the other core functionality of original opencommit.
- Commit command seems to work
- Have not fully tested
configcommand - Have not fully tested
githookcommand
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_opencommit-0.1.1.tar.gz.
File metadata
- Download URL: py_opencommit-0.1.1.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d031c64ec00b5c2475348c1dab456227ef7594c0d4f8fe15f3d90cc3dabcbc0
|
|
| MD5 |
4236a286987720d8b4637e71f9f90c50
|
|
| BLAKE2b-256 |
192070fac7cdc08c1a04538b0fe6fdcf004d9b161fcc9f7ad243231b6bc23990
|
File details
Details for the file py_opencommit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_opencommit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 40.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9edee047696f57ae56591cb28cd4a6cc4f7fe84101fd4ea3c171e5fc043016a3
|
|
| MD5 |
407d9effb8fbf3426a41b85f5d38fef4
|
|
| BLAKE2b-256 |
c7e272f8e048a4513b17f59e018ea1e35f38d07c62a66245791d63264cb2ed17
|