Bash-style brace expansion for Python
Implements Brace Expansion as described in bash(1), with the following limitations:
A pattern containing unbalanced braces will raise an UnbalancedBracesError exception. In bash, unbalanced braces will either be partly expanded or ignored.
A mixed-case character range like '{Z..a}' or '{a..Z}' will not include the characters []^_` between Z and a.
braceexpand is tested with Python 2.7, and 3.6+
Installation
Install the braceexpand package from pypi:
$ pip install braceexpand
Examples
The braceexpand function returns an iterator over the expansions generated from a pattern.
>>> from braceexpand import braceexpand
# Integer range
>>> list(braceexpand('item{1..3}'))
['item1', 'item2', 'item3']
# Character range
>>> list(braceexpand('{a..c}'))
['a', 'b', 'c']
# Sequence
>>> list(braceexpand('index.html{,.backup}'))
['index.html', 'index.html.backup']
# Nested patterns
>>> list(braceexpand('python{2.{5..7},3.{2,3}}'))
['python2.5', 'python2.6', 'python2.7', 'python3.2', 'python3.3']
# Prefixing an integer with zero causes all numbers to be padded to
# the same width.
>>> list(braceexpand('{07..10}'))
['07', '08', '09', '10']
# An optional increment can be specified for ranges.
>>> list(braceexpand('{a..g..2}'))
['a', 'c', 'e', 'g']
# Ranges can go in both directions.
>>> list(braceexpand('{4..1}'))
['4', '3', '2', '1']
# Numbers can be negative
>>> list(braceexpand('{2..-1}'))
['2', '1', '0', '-1']
# Unbalanced braces raise an exception.
>>> list(braceexpand('{1{2,3}'))
Traceback (most recent call last):
...
UnbalancedBracesError: Unbalanced braces: '{1{2,3}'
# By default, the backslash is the escape character.
>>> list(braceexpand(r'{1\{2,3}'))
['1{2', '3']
# Setting 'escape' to False disables backslash escaping.
>>> list(braceexpand(r'\{1,2}', escape=False))
['\\1', '\\2']
License
braceexpand is licensed under the MIT License. See the included file LICENSE for details.
Metadata
Release files for braceexpand 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| braceexpand-0.1.7.tar.gz | 7.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| braceexpand-0.1.7-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 13.7 kB
Release files / braceexpand-0.1.7.tar.gz
| Download URL | braceexpand-0.1.7.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6e539bd20eaea53547472ff94f4fb5c3d3bf9d0a89388c4b56663aba765f705
|
|
BLAKE2b-256 checksum How to use checksums |
5493badd4f5ccf25209f3fef2573073da9fe4a45a3da99fca2f800f942130c0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Release files / braceexpand-0.1.7-py2.py3-none-any.whl
| Download URL | braceexpand-0.1.7-py2.py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
91332d53de7828103dcae5773fb43bc34950b0c8160e35e0f44c4427a3b85014
|
|
BLAKE2b-256 checksum How to use checksums |
fa93e8c04e80e82391a6e51f218ca49720f64236bc824e92152a2633b74cf7ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Security for braceexpand 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.