gitignore-parser is a spec-compliant Python library for parsing `.gitignore` files and matching paths against their rules. It provides accurate behavior according to the Git documentation for ignore rules. The current version is 0.1.13, and the library receives regular updates for bug fixes and minor improvements.
pip install gitignore-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a gitignore parser instance from both a file path and a string, then use its `match()` method to check if specific file paths are ignored according to the rules.
Upgrade to version 0.1.8 or newer to ensure correct, spec-compliant parsing behavior. Review your `.gitignore` files if upgrading from very old versions to ensure rules still behave as intended after the fixes.
If you need to parse rules from a string, upgrade to version 0.1.12 or newer. For older versions, you must write the rules to a temporary file and use `parse_gitignore()`.
Windows users should upgrade to version 0.1.13 or newer to ensure robust and correct parsing behavior across different file system structures and path formats.
Ensure the library is installed using pip: `pip install gitignore-parser`. Also, verify the import statement is `from gitignore_parser import parse_gitignore`.
Call the result of `parse_gitignore` directly with the path you want to check, like `matches('/path/to/file')` instead of `matches.match('/path/to/file')`.The result of `matches(path)` is a boolean indicating whether the path is ignored. Use it in conditional statements directly, for example: `if matches('/path/to/file'): print('ignored')`.Ensure the `.gitignore` file exists at the specified path and that the path provided to `parse_gitignore` is correct and accessible.
No dependency data recorded yet.