Skip to main content

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Documentation | Issues | Changelog

gitmatch provides gitignore-style pattern matching of file paths. Simply pass in a sequence of gitignore patterns and you’ll get back an object for testing whether a given relative path matches the patterns.

Installation

gitmatch requires Python 3.10 or higher. Just use pip for Python 3 (You have pip, right?) to install it:

python3 -m pip install gitmatch

Examples

Basic usage:

>>> import gitmatch
>>> gi = gitmatch.compile(["foo", "!bar", "*.dir/"])
>>> bool(gi.match("foo"))
True
>>> bool(gi.match("bar"))
False
>>> bool(gi.match("quux"))
False
>>> bool(gi.match("foo/quux"))
True
>>> bool(gi.match("foo/bar"))
True
>>> bool(gi.match("bar/foo"))
True
>>> bool(gi.match("bar/quux"))
False
>>> bool(gi.match("foo.dir"))
False
>>> bool(gi.match("foo.dir/"))
True

See what pattern was matched:

>>> m1 = gi.match("foo/bar")
>>> m1 is None
False
>>> bool(m1)
True
>>> m1.pattern
'foo'
>>> m1.path
'foo'
>>> m2 = gi.match("bar")
>>> m2 is None
False
>>> bool(m2)
False
>>> m2.pattern
'!bar'
>>> m2.pattern_obj.negative
True
>>> m3 = gi.match("quux")
>>> m3 is None
True

Metadata

Release files for gitmatch 0.3.0

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

Source distribution (sdist)

Source distribution for gitmatch 0.3.0
File Size Uploaded
gitmatch-0.3.0.tar.gz 16.7 kB Details

Built distribution (wheel)

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

Total release size: 24.8 kB

Release files / gitmatch-0.3.0.tar.gz

Download URL gitmatch-0.3.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f3da0fe64c1ee74b276e2aa61be8a6abf5a41eacf8d931b7953b2333d47138ce
BLAKE2b-256 checksum
How to use checksums
887efdbaa640ba205b7555c6d6312e9fe58633a515ffe63b04d18ee2af0a6cdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / gitmatch-0.3.0-py3-none-any.whl

Download URL gitmatch-0.3.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee33a6521e36008f330cb658227522af22c8e2c3bf19475483c009dec81ed9cd
BLAKE2b-256 checksum
How to use checksums
72f8f00732b330d20662d7c573dd134a6489760c4ea3e91169f57071b004b2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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