py-walk is a Python library designed to filter filesystem paths based on .gitignore-like patterns. It aims to provide 100% compatibility with Git's wildmatch pattern syntax, making it useful for applications needing to mimic Git's file exclusion behavior. The library is currently at version 0.3.3 and appears to have an active, though not rapid, release cadence with recent patch updates.
pip install py-walkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `py-walk` to traverse a directory with gitignore-like patterns and how to create a parser to manually check individual paths. It first creates a dummy directory structure and then applies a set of exclusion patterns.
Understand that `py-walk` is for pattern-based filtering, and `os.walk` is for raw directory traversal. Use `py-walk` when `gitignore`-like logic is needed for path inclusion/exclusion.
For critical applications, thoroughly test patterns against actual `git check-ignore` behavior if absolute fidelity is required. Report any discrepancies to the library's GitHub repository.
Install the library using pip: `pip install py-walk`
Use `from py_walk import walk` (or `from py_walk import walk, get_parser_from_text`) instead of `import py_walk`.
Understand that `py-walk` is specifically for pattern-based file exclusion/inclusion using `.gitignore` syntax. Ensure patterns are correctly defined and passed to the `ignore` or `match` parameters of the `walk` function. If simple directory traversal without pattern matching is needed, `os.walk` is the appropriate tool.