Cross-platform Git history access via Rust with a Python API
Project description
PyGitX
Cross-platform Git history access implemented in Rust with a Python API via PyO3 and libgit2.
What you get
pygitx.open_repo(path) -> Repoto access repositories.Repo.head()for the current HEAD commit (orNoneif unborn).Repo.list_commits(max=None)to iterate commits from HEAD (newest first).Repo.change_commit_message(commit_id, new_message)to amend the HEAD commit message.Repo.rewrite_author(commit_id, new_name, new_email, update_committer=True)to rewrite HEAD author (optionally committer).Repo.rebase_branch(branch, onto)to replay a branch onto a new base (pick-only).Repo.squash_last(count, mode="squash", message=None)to squash the latest commits (or fixup-style).Repo.filter_commits(author=None, message_contains=None)to drop commits matching simple criteria (case-insensitive author/email/message).Repo.remove_path(path_pattern)to purge a path (glob) from all commits.- Rewrite operations return a
RewriteResultwithold_to_newcommit ids,updated_refs(e.g., HEAD/branch), and anywarnings. - Vendored libgit2 for predictable, cross-platform builds.
- Python package
pygitxwraps the native extension atpygitx._nativeand handles lightweight validation/convenience in Python; heavy history work stays in Rust/libgit2.
Quick start (editable install)
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip setuptools wheel maturin
pip install -e .
Or use the Makefile helpers:
make venv
source .venv/bin/activate
make install
make develop # pip install -e .
Build a wheel
make release # pip wheel . -w dist
Python usage
import pygitx
from pathlib import Path
repo = pygitx.open_repo(Path("."))
head = repo.head()
print("HEAD:", head.id if head else "None")
for c in repo.list_commits(max=5):
print(f"{c.id[:7]} {c.author} <{c.email}> {c.summary}")
# Amending the latest commit message (rewrites history)
if head:
result = repo.change_commit_message(head.id, "new message for HEAD")
print("Amended HEAD mapping:", result.old_to_new)
print("Updated refs:", result.updated_refs)
# Rewriting author/committer on HEAD (also rewrites history)
if head:
result = repo.rewrite_author(head.id, "New Name", "new@example.com")
print("Author rewrite mapping:", result.old_to_new)
# Squash the last 3 commits (keep all messages); use mode="fixup" to keep only the oldest message
if head:
squashed = repo.squash_last(3)
print("Squashed mapping:", squashed.old_to_new)
# Rebase a branch onto a new base (pick-only)
updated_commits = repo.rebase_branch("feature", "main")
print("Rebased commits:", updated_commits.old_to_new)
# Drop commits by author or message substring
filtered = repo.filter_commits(author="bad actor", message_contains="wip")
print("Filtered mapping:", filtered.old_to_new)
# Remove a path across history (glob)
purged = repo.remove_path("secrets/*.txt")
print("Purged path mapping:", purged.old_to_new)
Example script: examples/demo.py (see --help for options to generate a demo repo, list commits, amend/rewrite, or rebase).
Development
- Default tests (no Python runtime needed):
cargo test - Python-facing tests:
cargo test --features python-tests - Build docs (HTML):
source .venv/bin/activate && make docs(installsdocs/requirements.txtvia uv, then runs sphinx) - Make targets:
make venv,make install,make develop,make release,make docs,make test,make clean,make cleancargo,make cleanvenv
Notes / future
- ABI3 wheel targeting Python 3.9+ (
abi3-py39). - Built on
git2(libgit2) for speed and portability. - History filtering/removal currently supports linear histories; merge commits are rejected.
- Filtering/search is case-insensitive for author/email/message; globbing is used for path removal.
- Amending commit messages rewrites history; avoid on published branches unless you know the consequences.
- Rewriting author/committer also rewrites history and is currently limited to HEAD; rewriting older commits requires a rebase-like flow.
- Rebase is non-interactive (pick-only) and rewrites branch history; conflicts will abort with an error.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 pygitx-0.1.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: pygitx-0.1.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a511c097b1e17b167145d5b01c7ff19f49a91fa56e47f15356c10066c4f95ade
|
|
| MD5 |
85473e271ba86721d031d0e6e00d42e5
|
|
| BLAKE2b-256 |
a866185b0bb45937aa184a0a3af7ba2344c3977b044b3da4bd96c17f588f2e9f
|
Provenance
The following attestation bundles were made for pygitx-0.1.1-cp39-abi3-win_amd64.whl:
Publisher:
publish-to-pypi.yml on zangjiucheng/pygitx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygitx-0.1.1-cp39-abi3-win_amd64.whl -
Subject digest:
a511c097b1e17b167145d5b01c7ff19f49a91fa56e47f15356c10066c4f95ade - Sigstore transparency entry: 790765693
- Sigstore integration time:
-
Permalink:
zangjiucheng/pygitx@5c05eafa5703c647816ac73ac1e97929eb054113 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zangjiucheng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5c05eafa5703c647816ac73ac1e97929eb054113 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eb5b547145c300b8d3917018dd82a9ef2373d93cae11c31a72157c9fb54fa3a
|
|
| MD5 |
2cc2d048db80c4ae2bc704ded6da7875
|
|
| BLAKE2b-256 |
21e6ea5a323319142281db9ecd701900abf2556d62ae08a58e548d7b29685a13
|
Provenance
The following attestation bundles were made for pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl:
Publisher:
publish-to-pypi.yml on zangjiucheng/pygitx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
2eb5b547145c300b8d3917018dd82a9ef2373d93cae11c31a72157c9fb54fa3a - Sigstore transparency entry: 790765698
- Sigstore integration time:
-
Permalink:
zangjiucheng/pygitx@5c05eafa5703c647816ac73ac1e97929eb054113 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zangjiucheng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5c05eafa5703c647816ac73ac1e97929eb054113 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb35a65cbc40e91b02ae0fc5cb4a91030ba1b4017ee6069b89465b78325dd603
|
|
| MD5 |
6a9aa86b377074e8fc398d3403de2bf0
|
|
| BLAKE2b-256 |
699ce8f42e545420c366c0d662b840e470aa160e6121ec48556fe479dae88179
|
Provenance
The following attestation bundles were made for pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
publish-to-pypi.yml on zangjiucheng/pygitx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
bb35a65cbc40e91b02ae0fc5cb4a91030ba1b4017ee6069b89465b78325dd603 - Sigstore transparency entry: 790765696
- Sigstore integration time:
-
Permalink:
zangjiucheng/pygitx@5c05eafa5703c647816ac73ac1e97929eb054113 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zangjiucheng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5c05eafa5703c647816ac73ac1e97929eb054113 -
Trigger Event:
push
-
Statement type: