Skip to main content

Cross-platform Git history access via Rust with a Python API

Project description

PyGitX

pypi support-version license build commit

Cross-platform Git history access implemented in Rust with a Python API via PyO3 and libgit2.

What you get

  • pygitx.open_repo(path) -> Repo to access repositories.
  • Repo.head() for the current HEAD commit (or None if 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 RewriteResult with old_to_new commit ids, updated_refs (e.g., HEAD/branch), and any warnings.
  • Vendored libgit2 for predictable, cross-platform builds.
  • Python package pygitx wraps the native extension at pygitx._native and 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 (installs docs/requirements.txt via 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pygitx-0.1.1-cp39-abi3-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

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

Hashes for pygitx-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a511c097b1e17b167145d5b01c7ff19f49a91fa56e47f15356c10066c4f95ade
MD5 85473e271ba86721d031d0e6e00d42e5
BLAKE2b-256 a866185b0bb45937aa184a0a3af7ba2344c3977b044b3da4bd96c17f588f2e9f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pygitx-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2eb5b547145c300b8d3917018dd82a9ef2373d93cae11c31a72157c9fb54fa3a
MD5 2cc2d048db80c4ae2bc704ded6da7875
BLAKE2b-256 21e6ea5a323319142281db9ecd701900abf2556d62ae08a58e548d7b29685a13

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygitx-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb35a65cbc40e91b02ae0fc5cb4a91030ba1b4017ee6069b89465b78325dd603
MD5 6a9aa86b377074e8fc398d3403de2bf0
BLAKE2b-256 699ce8f42e545420c366c0d662b840e470aa160e6121ec48556fe479dae88179

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page