Skip to content

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

License

Notifications You must be signed in to change notification settings

zangjiucheng/pygitx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyGitX icon

pypi coverage support-version license build commit

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

Highlights

  • 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 RewriteResult with mappings and ref updates.

Install

pip install pygitx

Python usage

import 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).

Documentation

Full API and usage docs live in docs/ (Sphinx). Build locally with:

make docs

Or browse the published docs if available in your environment.

Development

  • 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 .githooks and chmod +x .githooks/pre-commit to be prompted to run make develop, make test, and pytest before each commit.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages