Skip to main content

A read-only implementation of Python’s pathlib that works on Git trees.

Installation

This library requires pygit2, which can be hard to install. You may need to get it installed before installing gitpathlib.

In a Python 3 virtual environment, do:

python -m pip install gitpathlib

To install an editable from a Git checkout:

python -m pip install -e.

To install without a virtual envitonment, add the --user option.

Basic Usage

A GitPath can be created from a path to a Git repository, and a commit (or tree) in it:

from gitpathlib import GitPath

head = GitPath('path/to/git/repo', 'HEAD')

It can then be used as a Path would:

path = head / 'dir' / 'file.txt'
with path.open() as f:
    contents = f.read()

GitPath provides read-only access. Creating files, opening them in write mode, etc. are not supported.

Development

You’re welcome to join this project!

If you spot an issue, please report it at the Issues page on Github.

If you’d like to start changing the code or documentation, check out the code locally using:

git clone https://github.com/encukou/gitpathlib

If you’re new to this, please read the this guide about collaborating on Github-hosted projects like this one.

If that doesn’t make sense, please e-mail the author for clarification. I’d be happy to help you get started.

Changelog

0.3 (2023-09-18)

Update to work with recent git & pygit2

0.2 (2017-04-29)

Implement the pathlib API

0.1 (2017-04-18)

Initial public version

Release files for gitpathlib 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitpathlib 0.3
File Size Uploaded
gitpathlib-0.3.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitpathlib 0.3
File Interpreter ABI Platform
gitpathlib-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 29.6 kB

Release files / gitpathlib-0.3.tar.gz

Download URL gitpathlib-0.3.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d5becc1a55a2e77d854bb72ace5c732a37e3ea69e3b39a3cc2436fd10e578f1c
BLAKE2b-256 checksum
How to use checksums
3529c6b8d59243aee1628b97aa206dffa14eafd7f4c25558d46b929158f71290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / gitpathlib-0.3-py3-none-any.whl

Download URL gitpathlib-0.3-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31ed892cb8269853f3a19d2e6e5b23fd2668898d1dc8821c99c3282bed8e3658
BLAKE2b-256 checksum
How to use checksums
e476d1c6f1056911a790fd8b11c1f935dacb741c285e26191d55170a12526be3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page