pygit2
Python bindings for libgit2.
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires libgit2 system library; prebuilt wheels handle this on most platforms, but custom builds may need libgit2 development headers installed.
- 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 · maintenance · safety
GPLv2 with linking exception (copyleft) — 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.
last release 2026-08-08 (6 days) · last repo commit 2026-08-14 · 1,726 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 5,566,975 downloads/mo, #2,071 on PyPI
Alternatives
Verify before relying
pip install pygit2
import pygit2
repo = pygit2.Repository('/path/to/repo')
commit = repo.head.target- 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.
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 on it.
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
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.
Requires libgit2 system library; prebuilt wheels handle this on most platforms, but custom builds may need libgit2 development headers installed.
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
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 packagecffi |
| 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 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Version ControlTyping :: Typed |
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
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “libgit2 python bindings”
- pygit2pygit2 provides Python bindings to libgit2, enabling direct…
- PyQt5-sipPyQt5-sip provides the runtime support module for PyQt5 bindings,…
- PyGObjectPyGObject provides Python bindings for GObject-based libraries such…
Give your agent the search over MCP, or paste the wish link into any chat.
More Version Control packages
Automatically extracts and manages Python package versions from git or Mercurial metadata instead of hardcoding them, and includes SCM-tracked files in source distributions.
Dulwich provides pure Python access to Git repositories—both local and remote—without requiring Git or native code to be installed, offering an alternative to calling Git directly.
setuptools-rust is a setuptools plugin that compiles and packages Python extensions written in Rust, using PyO3 or rust-cpython bindings.
A Poetry plugin that automatically derives and injects version numbers from version control tags into your project during builds, using Dunamai to support multiple VCS systems.
Install it if you use Poetry 1.2.0+ and want to eliminate manual version management in your build workflow.
Parses and applies patch files in multiple diff formats (unified, context, normal, ed, rcs) and from several source control systems (Git, SVN, CVS).
Automatically determines your Python package's version from Git or Mercurial tags and writes it to your build system, with customizable version formatting and optional runtime file generation.
See also scmrepo · chia-puzzles-py · euclid3 · ansible-pylibssh · python-ipmi · GitPython · argparse-ext · smoldot-light · sigstore