Braceexpand is a Python library that implements Bash-style brace expansion, allowing for the generation of arbitrary strings based on patterns. It provides an iterator over expanded strings, supporting integer ranges, character ranges, sequences, and nested patterns. The current version is 0.1.7, and it is compatible with Python 2.7 and 3.6+. While it closely mimics Bash behavior, it has a slower release cadence, with the last major update to 0.1.7 being in May 2021.
pip install braceexpandVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic brace expansion for integer and character ranges, sequence expansion, and nested patterns. It also shows how to catch the `UnbalancedBracesError` for malformed input strings, a key deviation from Bash behavior. The `braceexpand` function returns an iterator, so `list()` is often used to see all results immediately.
Ensure all opening braces `{` have a corresponding closing brace `}`. Implement try-except blocks for `UnbalancedBracesError` if processing user-supplied patterns.Be explicit with character sets if needing to include non-alphanumeric characters, or use separate expansions for uppercase and lowercase ranges. E.g., `{a..z,A..Z}`.Always wrap the call in `list()` if you require a complete list, or iterate directly over the returned object.
For extremely large or performance-critical expansions, consider alternative methods or preprocess patterns to minimize expansion complexity.
Use raw strings (e.g., `r'...'`) for patterns with backslashes you want treated literally or set `braceexpand(pattern, escape=False)` to disable backslash escaping entirely.
Run `pip install braceexpand` in your terminal to install the package.
Ensure that all opening braces `{` have corresponding closing braces `}` and that the pattern is syntactically correct according to Bash-style brace expansion rules. For example, `'{1,{2,3}}'` would be a balanced pattern.Always pass a string as the first argument to the `braceexpand` function. For example, `braceexpand('item{1..3}')` instead of `braceexpand(123)`.No dependency data recorded yet.