Cross-platform Git history access implemented in Rust with a Python API via PyO3 and libgit2.
- Fast Git history access via libgit2 with a lightweight Python wrapper.
- Repo helpers for HEAD info, revision parsing, commit listing, and branch/tag lookup.
- History rewriting tools: amend messages, rewrite author/committer, reword arbitrary commits, squash, rebase (pick-only), drop commits, and purge paths.
- All rewrites return a
RewriteResultwith mappings and ref updates.
pip install pygitximport pygitx
from pathlib import Path
repo = pygitx.open_repo(Path("."))
head = repo.head()
print("HEAD:", head.id if head else "None")
# Resolve a revision (branch/tag/oid) to a hex id
print("main ->", repo.rev_parse("main"))
for c in repo.list_commits(max=5):
print(f"{c.id[:7]} {c.author} <{c.email}> {c.summary}")
# Quick repo summary (also printed by str(repo))
print(repo.summary())
# Graph helpers
print("Branches:", repo.list_branches(local=True, remote=False))
print("Tags:", repo.list_tags())
print("Current branch:", repo.current_branch())
print("Merge base of main and feature:", repo.merge_base("main", "feature"))
print("Ahead/behind main vs feature:", repo.ahead_behind("main", "feature"))
print("Diff HEAD~1..HEAD:", repo.diff_stat("HEAD~1", "HEAD").files_changed, "files")Example script: examples/demo.py (run with --help to see options).
Full API and usage docs live in docs/ (Sphinx). Build locally with:
make docsOr browse the published docs if available in your environment.
- Run Rust and Python checks:
make test - Pytest for Python wrappers:
pytest - Make targets:
make venv,make install,make develop,make release,make docs,make test - Optional pre-commit prompt: set
git config core.hooksPath .githooksandchmod +x .githooks/pre-committo be prompted to runmake develop,make test, andpytestbefore each commit.