pygit2
Python bindings for libgit2.
What it is and what it does
pygit2 is a Python wrapper around libgit2, a C library that implements Git's core functionality. It lets you read and manipulate Git repositories programmatically—creating commits, managing branches, querying history, and performing other Git operations—without spawning git command-line processes. This is useful when you need fine-grained control over Git operations or want to embed Git functionality directly into a Python application.
The package depends on cffi to interface with the compiled libgit2 library. Installation uses prebuilt wheels for common platforms (macOS, Linux, Windows) and Python versions (3.11–3.14, PyPy3 7.3+), reducing build complexity. The repository is actively maintained, with recent releases and ongoing development.
Use it for:
- Build Git-aware development tools or CI/CD systems that need to query or manipulate repositories programmatically.
- Implement custom Git workflows or automation that would be cumbersome via shell commands.
- Analyze repository history, metadata, or structure without spawning external processes.
- Embed version control operations into Python applications that manage code or configuration.
- Create Git hooks or server-side repository management logic in pure Python.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pygit2 provides Python bindings to libgit2, enabling direct programmatic access to Git repository operations at the plumbing level without shelling out to the git command-line tool.
Yes, if you need programmatic Git access in Python. pygit2 is actively maintained, well-supported across modern Python versions and platforms, has no known vulnerabilities, and carries a permissive copyleft license (GPLv2 with linking exception). Medium install friction is manageable via prebuilt wheels. Not necessary if you only need to shell out to git commands or if GitPython's higher-level API better fits your use case.
Install
pygit2 on PyPI
pip
pip install pygit2uv
uv add pygit2poetry
poetry add pygit2Installing pygit2
Before you install
Medium install friction due to compiled C extensions (cffi dependency); prebuilt wheels available for Python 3.11–3.14 on macOS, Linux, Windows, and PyPy3 7.3+. Repository is actively maintained with a release 6 days old and recent commits.
License in practice
Licensed under GPLv2 with linking exception, a copyleft license. The linking exception permits combining the compiled library with other programs without imposing GPL terms on those programs, but modifications to pygit2 itself must remain under GPLv2.
Quickstart
pip install pygit2
import pygit2
repo = pygit2.Repository('/path/to/repo')
commit = repo.head.target
Requires libgit2 system library; prebuilt wheels handle this on most platforms, but custom builds may need libgit2 development headers installed.
Verify before relying
- Whether prebuilt wheels include all optional libgit2 features (SSH, HTTPS backends) or if some require system libraries.
- Performance characteristics compared to GitPython or other Git bindings for large repositories.
Package facts
| License | GPLv2 with linking exception (copyleft) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 1 — cffi |
| Maintenance | actively maintained — 6 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,566,975/month — #2,071 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pygit2-1.20.0-cp311-cp311-macosx_10_9_x86_64.whl; pygit2-1.20.0-cp311-cp311-macosx_11_0_arm64.whl; pygit2-1.20.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; pygit2-1.20.0-cp311-cp311-manylinux_2_26_ppc64le.manylinux_2_28_ppc64le.whl; pygit2-1.20.0-cp311-cp311-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl; pygit2-1.20.0-cp311-cp311-manylinux_2_38_riscv64.manylinux_2_39_riscv64.whl; pygit2-1.20.0-cp311-cp311-musllinux_1_2_aarch64.whl; pygit2-1.20.0-cp311-cp311-musllinux_1_2_riscv64.whl; pygit2-1.20.0-cp311-cp311-musllinux_1_2_x86_64.whl; pygit2-1.20.0-cp311-cp311-win32.whl; pygit2-1.20.0-cp311-cp311-win_amd64.whl; pygit2-1.20.0-cp311-cp311-win_arm64.whl; pygit2-1.20.0-cp312-cp312-macosx_10_13_x86_64.whl; pygit2-1.20.0-cp312-cp312-macosx_11_0_arm64.whl; pygit2-1.20.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; pygit2-1.20.0-cp312-cp312-manylinux_2_26_ppc64le.manylinux_2_28_ppc64le.whl; pygit2-1.20.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl; pygit2-1.20.0-cp312-cp312-manylinux_2_38_riscv64.manylinux_2_39_riscv64.whl; pygit2-1.20.0-cp312-cp312-musllinux_1_2_aarch64.whl; pygit2-1.20.0-cp312-cp312-musllinux_1_2_riscv64.whl
Keywords: git
Tags
More Version Control packages
Automatically extracts and manages Python…
permissive · top 1,000 on PyPI
dulwichDulwich provides pure Python access to Git…
unclear · top 1,000 on PyPI
setuptools-rustsetuptools-rust is a setuptools plugin that…
permissive · top 5,000 on PyPI
poetry-dynamic-versioningA Poetry plugin that automatically derives and…
permissive · top 5,000 on PyPI
whatthepatchParses and applies patch files in multiple diff…
permissive · top 5,000 on PyPI
versioningitAutomatically determines your Python package's…
permissive · top 5,000 on PyPI
scmreposcmrepo provides an fsspec-based filesystem…
permissive · top 5,000 on PyPI
chia-puzzles-pyProvides Python bindings to the standard Chia…
unclear · top 15,000 on PyPI
euclid3Provides 2D and 3D vector, matrix, quaternion,…
unclear · top 15,000 on PyPI
ansible-pylibsshPython bindings to libssh that provide SSH…
copyleft · top 15,000 on PyPI
python-ipmiPure Python library for communicating with…
copyleft · top 15,000 on PyPI
GitPythonGitPython provides high-level and low-level…
permissive · top 1,000 on PyPI
argparse-extExtends Python's standard argparse module with…
copyleft · top 15,000 on PyPI
smoldot-lightPython bindings for the smoldot_light Rust…
unclear · top 15,000 on PyPI
sigstoreSigstore is a Python tool for generating and…
permissive · top 5,000 on PyPI