{"id":4700,"library":"py-walk","title":"py-walk","description":"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.","status":"active","version":"0.3.3","language":"en","source_language":"en","source_url":"https://github.com/pacha/py-walk","tags":["filesystem","walk","gitignore","patterns","file-filtering"],"install":[{"cmd":"pip install py-walk","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required Python version","package":"python","optional":false}],"imports":[{"symbol":"walk","correct":"from py_walk import walk"},{"symbol":"get_parser_from_text","correct":"from py_walk import get_parser_from_text"},{"symbol":"get_parser_from_file","correct":"from py_walk import get_parser_from_file"}],"quickstart":{"code":"import os\nfrom py_walk import walk, get_parser_from_text\n\n# Create a dummy directory structure for demonstration\nif not os.path.exists('my_project'):\n    os.makedirs('my_project/data')\n    os.makedirs('my_project/src')\n    with open('my_project/data/temp.bin', 'w') as f: f.write('binary data')\n    with open('my_project/data/foo.bin', 'w') as f: f.write('important binary data')\n    with open('my_project/src/main.py', 'w') as f: f.write('print(\"Hello\")')\n    with open('my_project/__pycache__/cache.pyc', 'w') as f: f.write('cache')\n    with open('my_project/.env', 'w') as f: f.write('ENV_VAR=value')\n\npatterns = \"\"\"\n**/data/*.bin\n!**/data/foo.bin\n# exclude python cache and env files\n__pycache__/\n*.py[cod]\n.env\n\"\"\"\n\n# Example 1: Walk a directory with patterns\nprint(\"\\n--- Walking 'my_project' with patterns ---\")\nfor path in walk('my_project', ignore=patterns):\n    print(f\"Included: {path}\")\n\n# Example 2: Manually check paths against a parser\nprint(\"\\n--- Manually checking paths ---\")\nparser = get_parser_from_text(patterns, base_dir='my_project')\n\npaths_to_check = [\n    'my_project/data/temp.bin',\n    'my_project/data/foo.bin',\n    'my_project/src/main.py',\n    'my_project/__pycache__/cache.pyc',\n    'my_project/.env',\n    'my_project/README.md' # This file doesn't exist but we can check the pattern\n]\n\nfor p in paths_to_check:\n    if not parser.match(p):\n        print(f\"'{p}' is NOT ignored (matches patterns if prefix is not '!')\")\n    else:\n        print(f\"'{p}' IS ignored\")\n\n# Cleanup dummy directory (optional)\nimport shutil\n# shutil.rmtree('my_project') # Uncomment to clean up\n","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Do not confuse `py-walk` with Python's standard library `os.walk`. While both traverse directory trees, `py-walk`'s primary function is to filter paths based on `.gitignore` style patterns, providing selective iteration based on these rules. `os.walk` simply provides an iterator for all files and directories.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"While `py-walk` aims for 100% compatibility with Git's `wildmatch` pattern syntax, the project's README encourages reporting any divergences. This suggests that in some complex or edge-case scenarios, its behavior might not perfectly mirror `git check-ignore`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}