Registry / serialization / glob2
library0.7pypypi✓ verified 29d ago

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.

pip install glob2
INSTALL
IMPORT
SIG · GLOB2
G
glob2
serializationpythonv0.7
Install
2.4s avg
Import
—
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

glob2
✓ import glob2
The primary way to import the library and access its functions like `glob2.glob()` and `glob2.iglob()`.

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`.

import glob2 import os # Create some dummy files and directories for demonstration os.makedirs('src/media/mp3', exist_ok=True) with open('src/fs.h', 'w') as f: f.write('// fs.h') with open('src/media/mp3.h', 'w') as f: f.write('// mp3.h') with open('src/media/mp3/frame.h', 'w') as f: f.write('// frame.h') with open('src/main.py', 'w') as f: f.write('# main.py') # Example 1: Recursive globbing with '**' print('All header files:') all_header_files = glob2.glob('src/**/*.h') for f in all_header_files: print(f) # Example 2: Capturing patterns (with_matches=True) # This example requires a pattern that defines capture groups, e.g., project-(.*).zip # For demonstration, let's assume we have files like 'binaries/project-v1.0.zip' os.makedirs('binaries', exist_ok=True) with open('binaries/project-v1.0.zip', 'w') as f: f.write('zip content') with open('binaries/project-v2.1.zip', 'w') as f: f.write('zip content') print('\nProject versions (captured patterns):') for filename, (version,) in glob2.iglob('./binaries/project-*.zip', with_matches=True): print(f'{filename}, version: {version}') # Clean up dummy files and directories import shutil shutil.rmtree('src', ignore_errors=True) shutil.rmtree('binaries', ignore_errors=True)
Debug
Known issues
deprecatedThe 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.
fix
Prefer `glob.glob(..., recursive=True)` from the standard library or `Path.glob()` and `Path.rglob()` from `pathlib`.
affects: < Python 3.5 for 'standard glob' limitations, all versions for 'glob2' redundancy
breakingThe `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.
fix
Migrate to `glob` or `pathlib` from Python's standard library for continued support and maintenance.
affects: 0.7 and earlier
gotchaThe 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.
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 `**`.
affects: All versions of glob2
gotchaWhen using Windows file paths, backslashes are interpreted as escape characters. This can lead to incorrect path matching or errors.
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.
affects: All Python versions on Windows
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'glob2'
The `glob2` library is not installed in the Python environment being used.
fix
Install the library using pip: `pip install glob2` (or `pip3 install glob2` for Python 3 installations).
ImportError: No module named 'glob2'
The `glob2` library is not found in the Python environment, often due to not being installed or being installed for a different Python version.
fix
Ensure `glob2` is installed for your active Python environment: `pip install glob2` (or `pip3 install glob2`).
NameError: name 'glob2' is not defined
The `glob2` module was not imported before being used, or an attempt was made to call `glob2.glob` without explicitly importing `glob2` first.
fix
Add `import glob2` at the top of your Python script before using `glob2.glob()`.
TypeError: glob() got an unexpected keyword argument 'recursive'
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.
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)`.
Upgrade
Version history
0.7latest on PyPI · released Jun 10, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources