{"id":2958,"library":"gitignore-parser","title":"Gitignore Parser","description":"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.","status":"active","version":"0.1.13","language":"python","source_language":"en","source_url":"https://github.com/mherrmann/gitignore_parser","tags":["filesystem","git","parser","gitignore"],"install":[{"cmd":"pip install gitignore-parser","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"parse_gitignore","correct":"from gitignore_parser import parse_gitignore"},{"note":"The primary interface is via parsing functions, not a direct class constructor. 'parse_gitignore_str' was added in v0.1.12.","wrong":"from gitignore_parser import GitignoreParser","symbol":"parse_gitignore_str","correct":"from gitignore_parser import parse_gitignore_str"}],"quickstart":{"code":"from pathlib import Path\nfrom gitignore_parser import parse_gitignore, parse_gitignore_str\n\n# Example 1: Parsing from a file\ngitignore_path = Path(\"temp_test.gitignore\")\ngitignore_path.write_text(\"\"\"\n# Ignore build artifacts\n/build/\n*.log\n!important.log\n\"\"\")\n\n# Create a parser instance from the .gitignore file\nparser_file = parse_gitignore(gitignore_path)\n\n# Test matching paths\nprint(f\"Is 'build/app.exe' ignored? {parser_file.match('build/app.exe')}\")\nprint(f\"Is 'temp.log' ignored? {parser_file.match('temp.log')}\")\nprint(f\"Is 'important.log' ignored? {parser_file.match('important.log')}\")\n\ngitignore_path.unlink() # Clean up the temporary file\n\n# Example 2: Parsing from a string (available from v0.1.12+)\ngitignore_content = \"\"\"\n# Ignore temporary files\n*.tmp\n/cache/\n\"\"\"\nparser_str = parse_gitignore_str(gitignore_content)\n\nprint(f\"Is 'file.tmp' ignored (from string)? {parser_str.match('file.tmp')}\")\nprint(f\"Is 'project/cache/data.json' ignored (from string)? {parser_str.match('project/cache/data.json')}\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Older versions (pre-0.1.8 / pre-0.1.7) had incorrect parsing behavior for certain complex patterns, such as implicit anchoring, multi-asterisks, leading exclamation marks, and slashes in ranges. This could lead to rules not matching as expected according to the gitignore specification.","severity":"gotcha","affected_versions":"<0.1.8"},{"fix":"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()`.","message":"The `parse_gitignore_str()` function, which allows parsing gitignore rules directly from a string without needing a file, was introduced in version 0.1.12. Prior versions only supported parsing from a file path using `parse_gitignore()`.","severity":"gotcha","affected_versions":"<0.1.12"},{"fix":"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.","message":"Version 0.1.13 fixed some edge cases related to path matching on Windows, which could lead to incorrect ignore decisions for certain patterns and paths on Windows systems.","severity":"gotcha","affected_versions":"<0.1.13"}],"env_vars":null,"search_vec":"'0.1.13':39 'accord':27 'accur':25 'behavior':26 'bug':47 'compliant':10 'current':36 'document':31 'file':16 'filesystem':52 'fix':48 'git':30,53 'gitignor':1,4,15,55 'gitignore-pars':3 'ignor':33 'improv':51 'librari':12,42 'match':18 'minor':50 'pars':14 'parser':2,5,54 'path':19 'provid':24 'python':11 'receiv':43 'regular':44 'rule':22,34 'spec':9 'spec-compli':8 'updat':45 'version':37","created_at":"2026-04-11T09:14:53.479178+00:00","updated_at":"2026-04-16T15:17:17.342755+00:00","problems":[{"fix":"Ensure the library is installed using pip: `pip install gitignore-parser`. Also, verify the import statement is `from gitignore_parser import parse_gitignore`.","cause":"The `gitignore-parser` library is not installed in your Python environment or there's a typo in the import statement.","error":"ModuleNotFoundError: No module named 'gitignore_parser'"},{"fix":"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')`.","cause":"The `parse_gitignore` function returns a callable object (a function) that directly takes a file path as an argument to check if it matches, not an object with a `.match()` method. This error occurs when trying to call a non-existent `.match()` method on the returned callable.","error":"AttributeError: 'function' object has no attribute 'match'"},{"fix":"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')`.","cause":"This error often happens when you incorrectly use the boolean result of a path matching (which is either `True` or `False`) as if it were a function.","error":"TypeError: 'bool' object is not callable"},{"fix":"Ensure the `.gitignore` file exists at the specified path and that the path provided to `parse_gitignore` is correct and accessible.","cause":"The `parse_gitignore` function expects a valid path to an existing `.gitignore` file, but the provided path does not point to an actual file.","error":"FileNotFoundError: [Errno 2] No such file or directory: '/path/to/.gitignore'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.1.13","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/mherrmann/gitignore_parser","docs":null,"changelog":null,"pypi":"https://pypi.org/project/gitignore-parser/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}