skillfed

pygit2

Python bindings for libgit2.

pygit2 v1.20.0 5.6M downloads/30d#2,071 on PyPI1,726
Copyleft license GPLv2 with linking exception Active released

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 pygit2

uv

uv add pygit2

poetry

poetry add pygit2

Installing 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

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

Tags

git repository access pythonlibgit2 python bindingsgit plumbing operationsprogrammatic git manipulationgit version control librarypython git api
git-bindingsversion-controllibgit2

More Version Control packages