Bash Style Brace Expander

raw JSON →
2.6 verified Tue May 12 auth: no python install: verified

Bracex is a Python library that provides Bash-style brace expansion, enabling the generation of arbitrary strings from patterns. It closely emulates Bash's brace processing, supporting comma-separated lists, numerical and alphabetical sequences (ranges), and optional step increments. The library is actively maintained, with version 2.6 being the latest, and releases occur regularly to ensure compatibility with newer Python versions and address minor fixes.

pip install bracex
error ModuleNotFoundError: No module named 'bracex'
cause The 'bracex' library is not installed in your Python environment, or the Python interpreter cannot find it.
fix
Install the library using pip: pip install bracex
error bracex.BraceExpansionError: Brace expansion exceeded the limit of 1000 items.
cause The brace expansion pattern you provided generates more strings than the default `limit` of 1000 allowed by `bracex.expand()` or `bracex.iexpand()` to prevent 'brace bombs' or excessive memory usage.
fix
Increase the limit parameter in the expand() or iexpand() function call, or set limit=0 to disable it if you are certain of the pattern's safety and have sufficient memory. Using iexpand() can also help manage memory for large results.
import bracex
# To increase the limit
expanded_list = bracex.expand('{1..5000}', limit=5000)
# To disable the limit (use with caution for unbounded expansions)
expanded_list = bracex.expand('{1..infinity}', limit=0)
error ERROR: Package 'bracex' requires Python '>=3.9' but the running Python is X.Y.Z
cause You are attempting to install or run `bracex` version 2.6 (or newer) with a Python version older than 3.9, which is not supported by this version of the library.
fix
Upgrade your Python environment to version 3.9 or newer. Alternatively, if feasible, install an older version of bracex that supports your current Python version (e.g., pip install bracex==2.5 for Python 3.8, if available, but upgrading Python is recommended).
breaking Bracex has progressively dropped support for older Python versions. Version 2.6 (current) requires Python 3.9 or higher. Previous versions dropped support for Python 3.8 (in 2.6), 3.7 (in 2.4), 3.6 (in 2.3), and 3.5 (in 2.1.0).
fix Upgrade your Python environment to 3.9 or newer before upgrading to bracex 2.6. Always check the `requires_python` field on PyPI for the desired `bracex` version.
gotcha The `expand()` and `iexpand()` functions include a `limit` parameter (defaulting to 1000) to prevent excessively large expansions, which could lead to performance issues or 'brace bombs'. If an expansion exceeds this limit, an error is raised.
fix For very large or potentially unbounded expansions, consider increasing the `limit` parameter (e.g., `bracex.expand(pattern, limit=5000)`) or setting `limit=0` to disable the limit entirely if you are certain of the pattern's safety and have sufficient memory. Using `iexpand()` can also help manage memory for large results.
gotcha While `bracex` closely mimics Bash's brace expansion, it is not a 1:1 implementation. It may deviate in certain edge cases, particularly regarding how Bash handles command-line inputs (e.g., backticks and quotes).
fix If migrating complex Bash scripts, thoroughly test patterns in `bracex` that rely on specific Bash shell behaviors beyond simple brace expansion. Refer to the official documentation for noted deviations.
deprecated The build backend for `bracex` switched from Setuptools to Hatch in version 2.3. While this primarily affects maintainers and packagers, it's a significant internal change.
fix Users consuming `bracex` via `pip install` are generally unaffected. If you are involved in packaging or contributing, be aware of the updated build system requirements and configuration (e.g., `pyproject.toml`).
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.01s 17.8M
3.10 alpine (musl) - - 0.01s 17.8M
3.10 slim (glibc) wheel 1.4s 0.01s 18M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) wheel - 0.02s 19.7M
3.11 alpine (musl) - - 0.04s 19.7M
3.11 slim (glibc) wheel 1.5s 0.02s 20M
3.11 slim (glibc) - - 0.02s 20M
3.12 alpine (musl) wheel - 0.02s 11.6M
3.12 alpine (musl) - - 0.02s 11.6M
3.12 slim (glibc) wheel 1.4s 0.02s 12M
3.12 slim (glibc) - - 0.02s 12M
3.13 alpine (musl) wheel - 0.01s 11.3M
3.13 alpine (musl) - - 0.01s 11.2M
3.13 slim (glibc) wheel 1.4s 0.01s 12M
3.13 slim (glibc) - - 0.01s 12M
3.9 alpine (musl) wheel - 0.01s 17.3M
3.9 alpine (musl) - - 0.01s 17.3M
3.9 slim (glibc) wheel 1.7s 0.01s 18M
3.9 slim (glibc) - - 0.01s 18M

Demonstrates basic brace expansion for lists, nested patterns, numerical and alphabetical sequences, and the generator-based iteration using `iexpand`.

import bracex

# Basic list expansion
print(bracex.expand(r'file-{a,b,c}.txt'))

# Nested brace expansion
print(bracex.expand(r'path/to/{{foo,bar},baz}/file.txt'))

# Numerical sequence (range) expansion
print(bracex.expand(r'image{00..02}.png'))

# Numerical sequence with step
print(bracex.expand(r'item{1..10..3}.log'))

# Alphabetic sequence
print(bracex.expand(r'letter{A..D}.md'))

# Using the generator version
for item in bracex.iexpand(r'data-{1..5}.csv'):
    print(item)