{"id":4551,"library":"glob2","title":"glob2","description":"glob2 is an extended version of Python's built-in `glob` module, designed to offer enhanced globbing capabilities. Key features include the ability to capture patterns matched by glob expressions and a recursive `**` wildcard syntax, akin to bash's globstar. The current version is 0.7. The project has seen no active development since 2019, as many of its core functionalities, particularly recursive globbing, have been integrated into Python's standard `glob` module since Python 3.5.","status":"deprecated","version":"0.7","language":"python","source_language":"en","source_url":"https://github.com/miracle2k/python-glob2/","tags":["file system","globbing","wildcards","recursive search","pattern matching"],"install":[{"cmd":"pip install glob2","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The primary way to import the library and access its functions like `glob2.glob()` and `glob2.iglob()`.","symbol":"glob2","correct":"import glob2"}],"quickstart":{"code":"import glob2\nimport os\n\n# Create some dummy files and directories for demonstration\nos.makedirs('src/media/mp3', exist_ok=True)\nwith open('src/fs.h', 'w') as f: f.write('// fs.h')\nwith open('src/media/mp3.h', 'w') as f: f.write('// mp3.h')\nwith open('src/media/mp3/frame.h', 'w') as f: f.write('// frame.h')\nwith open('src/main.py', 'w') as f: f.write('# main.py')\n\n# Example 1: Recursive globbing with '**'\nprint('All header files:')\nall_header_files = glob2.glob('src/**/*.h')\nfor f in all_header_files:\n    print(f)\n\n# Example 2: Capturing patterns (with_matches=True)\n# This example requires a pattern that defines capture groups, e.g., project-(.*).zip\n# For demonstration, let's assume we have files like 'binaries/project-v1.0.zip'\nos.makedirs('binaries', exist_ok=True)\nwith open('binaries/project-v1.0.zip', 'w') as f: f.write('zip content')\nwith open('binaries/project-v2.1.zip', 'w') as f: f.write('zip content')\n\nprint('\\nProject versions (captured patterns):')\nfor filename, (version,) in glob2.iglob('./binaries/project-*.zip', with_matches=True):\n    print(f'{filename}, version: {version}')\n\n# Clean up dummy files and directories\nimport shutil\nshutil.rmtree('src', ignore_errors=True)\nshutil.rmtree('binaries', ignore_errors=True)","lang":"python","description":"This quickstart demonstrates `glob2`'s main features: recursive globbing using `**` to find all header files within a directory and its subdirectories, and capturing parts of filenames using `with_matches=True`."},"warnings":[{"fix":"Prefer `glob.glob(..., recursive=True)` from the standard library or `Path.glob()` and `Path.rglob()` from `pathlib`.","message":"The primary features of `glob2`, specifically recursive globbing with `**`, have been integrated into Python's standard `glob` module since Python 3.5. `pathlib` also provides robust globbing functionality. There is generally no compelling reason to use `glob2` in modern Python versions.","severity":"deprecated","affected_versions":"< Python 3.5 for 'standard glob' limitations, all versions for 'glob2' redundancy"},{"fix":"Migrate to `glob` or `pathlib` from Python's standard library for continued support and maintenance.","message":"The `glob2` library is no longer actively maintained. The last release was in 2019, and the last code push was over 4 years ago. This means it may not be compatible with newer Python versions or address new security vulnerabilities or bugs.","severity":"breaking","affected_versions":"0.7 and earlier"},{"fix":"Ensure `**` is isolated between path separators (e.g., `dir1/**/dir3/*.txt`). Adjust patterns (e.g., `*/**/*.py`) if you want to exclude immediate children of the starting directory when using `**`.","message":"The recursive wildcard `**` in `glob2` (and standard `glob`) must appear as a standalone directory element. For example, `src/**/*.h` is correct, but `src/**h` will not have the desired recursive effect. Additionally, `**/*.py` will match Python files in the current directory (`.`), if not intended, use `*/**/*.py` to exclude the current directory.","severity":"gotcha","affected_versions":"All versions of glob2"},{"fix":"Use raw strings (e.g., `r'C:\\Users\\...'`) or forward slashes (e.g., `'C:/Users/...'`) for path patterns on Windows to avoid issues with backslash escapes.","message":"When using Windows file paths, backslashes are interpreted as escape characters. This can lead to incorrect path matching or errors.","severity":"gotcha","affected_versions":"All Python versions on Windows"}],"env_vars":null,"search_vec":"'0.7':47 '2019':56 '3.5':77 'abil':25 'activ':53 'akin':38 'bash':40 'built':11 'built-in':10 'capabl':20 'captur':27 'core':61 'current':44 'design':15 'develop':54 'enhanc':18 'express':32 'extend':5 'featur':22 'file':78 'function':62 'glob':13,19,31,65,73,80 'glob2':1,2 'globstar':42 'includ':23 'integr':68 'key':21 'mani':58 'match':29,85 'modul':14,74 'offer':17 'particular':63 'pattern':28,84 'project':49 'python':8,70,76 'recurs':35,64,82 'search':83 'seen':51 'sinc':55,75 'standard':72 'syntax':37 'system':79 'version':6,45 'wildcard':36,81","created_at":"2026-04-12T13:57:29.011105+00:00","updated_at":"2026-04-16T15:17:46.141844+00:00","problems":[{"fix":"Install the library using pip: `pip install glob2` (or `pip3 install glob2` for Python 3 installations).","cause":"The `glob2` library is not installed in the Python environment being used.","error":"ModuleNotFoundError: No module named 'glob2'"},{"fix":"Ensure `glob2` is installed for your active Python environment: `pip install glob2` (or `pip3 install glob2`).","cause":"The `glob2` library is not found in the Python environment, often due to not being installed or being installed for a different Python version.","error":"ImportError: No module named 'glob2'"},{"fix":"Add `import glob2` at the top of your Python script before using `glob2.glob()`.","cause":"The `glob2` module was not imported before being used, or an attempt was made to call `glob2.glob` without explicitly importing `glob2` first.","error":"NameError: name 'glob2' is not defined"},{"fix":"For Python versions < 3.5, use `glob2.glob('**/*.txt', recursive=True)` after `import glob2`. For Python 3.5 and above, use the standard `glob.glob('**/*.txt', recursive=True)`.","cause":"This error typically occurs when attempting to use the `recursive=True` argument with Python's built-in `glob.glob()` function in a Python version older than 3.5. The `glob2` library was created to provide this functionality before it was standardized.","error":"TypeError: glob() got an unexpected keyword argument 'recursive'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.7","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/miracle2k/python-glob2","docs":null,"changelog":null,"pypi":"https://pypi.org/project/glob2/","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-30","next_check":"2026-07-28","install_tag":null}}