{"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":"python","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,"search_vec":"'0.3.3':53 '100':26 'activ':59 'aim':23 'appear':55 'applic':38 'base':16 'behavior':46 'cadenc':64 'compat':27 'current':50 'design':11 'exclus':45 'file':44,74 'file-filt':73 'filesystem':14,69 'filter':13,75 'git':29,42 'gitignor':19,71 'gitignore-lik':18 'librari':10,48 'like':20 'make':34 'mimic':41 'need':39 'patch':67 'path':15 'pattern':21,32,72 'provid':25 'py':2,5 'py-walk':1,4 'python':9 'rapid':62 'recent':66 'releas':63 'syntax':33 'though':60 'updat':68 'use':36 'version':52 'walk':3,6,70 'wildmatch':31","created_at":"2026-04-12T14:03:52.628651+00:00","updated_at":"2026-04-16T18:18:06.913205+00:00","problems":[{"fix":"Install the library using pip: `pip install py-walk`","cause":"The 'py-walk' library has not been installed or is not accessible in the current Python environment, or the import statement uses an incorrect module name.","error":"ModuleNotFoundError: No module named 'py_walk'"},{"fix":"Use `from py_walk import walk` (or `from py_walk import walk, get_parser_from_text`) instead of `import py_walk`.","cause":"The `walk` function (or other main functions like `get_parser_from_text`) needs to be imported directly from the `py_walk` module, not accessed as an attribute of the module itself after a simple `import py_walk`.","error":"AttributeError: module 'py_walk' has no attribute 'walk'"},{"fix":"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.","cause":"Developers often confuse `py-walk` with Python's standard `os.walk`. While both traverse directory trees, `py-walk`'s primary function is to filter paths based on `.gitignore`-like patterns, providing selective iteration based on these rules, whereas `os.walk` simply provides an iterator for all files and directories.","error":"py-walk not filtering files correctly / py-walk vs os.walk"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.3.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/pacha/py-walk","docs":null,"changelog":null,"pypi":"https://pypi.org/project/py-walk/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}