{"id":23791,"library":"gitignorefile","title":"gitignorefile","description":"A spec-compliant `.gitignore` parser for Python (version 1.1.2). It reads `.gitignore` files and matches file paths against the rules, supporting all features of the Git gitignore specification. The library is actively maintained.","status":"active","version":"1.1.2","language":"python","source_language":"en","source_url":"https://github.com/excitoon/gitignorefile","tags":["gitignore","parser","file-matching","git"],"install":[{"cmd":"pip install gitignorefile","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"The correct import is function-level, not module-level.","wrong":"import gitignorefile; gitignorefile.read_gitignore","symbol":"read_gitignore","correct":"from gitignorefile import read_gitignore"},{"note":"The class is used to match files against rules.","symbol":"GitignoreFile","correct":"from gitignorefile import GitignoreFile"}],"quickstart":{"code":"import os\nfrom gitignorefile import read_gitignore, GitignoreFile\n\nignores = read_gitignore('.gitignore')\nchecker = GitignoreFile(ignores)\nprint(checker.match('some_file.py'))  # True/False","lang":"python","description":"Basic usage: read .gitignore file and check if a path is ignored."},"warnings":[{"fix":"Ensure you pass paths relative to the directory containing the .gitignore file.","message":"The `match` method expects paths relative to the .gitignore file location, not absolute paths.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the `is_ignored_dir` property or check for directory separately.","message":"The library only supports regular files, not directories. Calling `match` on a directory path may give unexpected results.","severity":"gotcha","affected_versions":"all"},{"fix":"Update to version 1.0+; the return type is now a list of rules.","message":"The `read_gitignore` function returns a list, but older documentation suggested it returns a different format.","severity":"deprecated","affected_versions":"<1.0"},{"fix":"Always pass the output of `read_gitignore` to the constructor.","message":"Version 1.0 changed the API from `GitignoreFile(rules)` to accept a list of rule objects, not raw strings.","severity":"breaking","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install/upgrade: pip install --upgrade gitignorefile, and import correctly: from gitignorefile import read_gitignore","cause":"Missing import or outdated library version.","error":"AttributeError: module 'gitignorefile' has no attribute 'read_gitignore'"},{"fix":"Use parsed result: `rules = read_gitignore('.gitignore'); checker = GitignoreFile(rules)`","cause":"Passing raw string to GitignoreFile constructor instead of list of rules.","error":"TypeError: __init__() takes 1 positional argument but 2 were given"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}