Registry / serialization / braceexpand

braceexpand

JSON →
library0.1.7pypypi✓ verified 24d ago

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 braceexpand
INSTALL
IMPORT
SIG · BRACEEXPAND
B
braceexpand
serializationpythonv0.1.7
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.002s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.002s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

braceexpand
from braceexpand import braceexpand
UnbalancedBracesError
from braceexpand import UnbalancedBracesError
Import for handling errors related to malformed brace patterns.

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.

from braceexpand import braceexpand # Example 1: Integer range expanded_items = list(braceexpand('item{1..3}')) print(f"Integer range: {expanded_items}") # Example 2: Character range expanded_chars = list(braceexpand('{a..c}')) print(f"Character range: {expanded_chars}") # Example 3: Sequence expansion expanded_files = list(braceexpand('index.html{,.backup}')) print(f"Sequence expansion: {expanded_files}") # Example 4: Nested patterns expanded_versions = list(braceexpand('python{2.{5..7},3.{2,3}}')) print(f"Nested patterns: {expanded_versions}") # Example 5: Handling unbalanced braces (raises an exception) from braceexpand import UnbalancedBracesError try: list(braceexpand('{1{2,3}')) except UnbalancedBracesError as e: print(f"Caught expected error: {e}")
Debug
Known issues
breakingUnlike Bash, a pattern containing unbalanced braces will raise an `UnbalancedBracesError` exception. Bash would typically partly expand or ignore such patterns.
fix
Ensure all opening braces `{` have a corresponding closing brace `}`. Implement try-except blocks for `UnbalancedBracesError` if processing user-supplied patterns.
affects: All versions (0.1.0+)
gotchaMixed-case character ranges like `{Z..a}` or `{a..Z}` will not include the characters `[]^_`` between 'Z' and 'a' in ASCII order. This differs from some Bash environments.
fix
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}`.
affects: All versions (0.1.0+)
gotchaThe `braceexpand` function returns an iterator, not a list. If you need all expanded strings at once, you must explicitly convert the iterator to a list (e.g., `list(braceexpand(...))`).
fix
Always wrap the call in `list()` if you require a complete list, or iterate directly over the returned object.
affects: All versions (0.1.0+)
gotchaPerformance may be an issue for very large datasets. The library is not designed for high-performance scenarios with extensive expansions.
fix
For extremely large or performance-critical expansions, consider alternative methods or preprocess patterns to minimize expansion complexity.
affects: All versions (0.1.0+)
gotchaThe backslash (`\`) is the default escape character. If you want to expand patterns containing literal backslashes or disable escaping, you need to use raw strings and/or set `escape=False`.
fix
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.
affects: All versions (0.1.0+)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'braceexpand'
The 'braceexpand' library is not installed in your Python environment.
fix
Run `pip install braceexpand` in your terminal to install the package.
UnbalancedBracesError: Unbalanced braces: '{1{2,3}'
The input pattern string contains an opening brace without a matching closing brace, or vice versa, which `braceexpand` considers an invalid pattern.
fix
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.
TypeError: braceexpand() argument 'pattern' must be str, not int
The `braceexpand` function received an argument that is not a string for its `pattern` parameter.
fix
Always pass a string as the first argument to the `braceexpand` function. For example, `braceexpand('item{1..3}')` instead of `braceexpand(123)`.
Upgrade
Version history
0.1.7latest on PyPI · released May 7, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources