Skip to main content

Path matching utilities

Project description

Python implementation of git’s wildmatch and POSIX.1-2008 fnmatch.

The aim of this package is to provide a file matching module complying with the POSIX standard and allow compatibility with git.


from pathmatch import wildmatch

# Pattern matching auto-generated test files (extension .pyc, .pyo or .pyd inside tests/)
pattern = u'tests/**/*.py[cod]'

# Match single files:
wildmatch.match(pattern, u'tests/auto.pyc')  # True
wildmatch.match(pattern, u'auto.pyc')  # False

# Filter a collection:
files = [
list(wildmatch.filter(pattern, files))  # [u'tests/deep/auto.pyd', u'tests/auto.pyo']

# Compile a pattern
compiled = wildmatch.WildmatchPattern(pattern)

compiled.match(u'tests/')  # False


wildmatch support

Currently, the following wildmatch features are supported:

  • Wildstar ** operator and associated semantics (/ requires a literal match)

  • Literal matching

  • Question mark ? (any character) and asterisk * (any string) operators

  • Bracket expressions [abc] (character alternatives)

Bracket expression features:

  • Negation (supports both ^ and ! meta-characters)

  • Range expressions a-z

  • Collation Symbol [.ch.]

  • Equivalence classes syntax [=e=], but fallback to collation symbol semantics

  • Supports the path_name flag to exclude / (which requires a literal match)

See for more details.


  • case_fold (case insensitive) option is not supported

  • period (require literal match for leading period) option is not supported

  • Negated bracket expression with multi-character collating elements are not supported

  • Character classes [:alpha:] for bracket expressions are not supported

Contributions are welcomed

fnmatch support

The dedicated fnmatch module is not yet configured (this should just be a subset of wildmatch).



You can execute the tests with the following command:

python -m unittest discover -s . -p test*.py



MIT License, Copyright (c) 2016 Charles Samborski

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathmatch-0.2.2.tar.gz (24.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page