Skip to main content

Glob with Bash-style brache expansion

Project description

senkawa

Glob with Bash-style brace expansion.

[!NOTE] This package is highly influenced by trendels/braceexpand.

Installation

pip install senkawa

Usage

>>> import senkawa
# With glob
>>> list(senkawa.glob("*.{md,toml}"))
["README.md", "pyproject.toml"]

>>> list(senkawa.glob("tests/fixtures/{1..3}.txt"))
["tests/fixtures/1.txt", "tests/fixtures/2.txt", "tests/fixtures/3.txt"]

# Integer range
>>> list(senkawa.brace_expand('item{1..3}'))
['item1', 'item2', 'item3']

# Character range
>>> list(senkawa.brace_expand('{a..c}'))
['a', 'b', 'c']

# Sequence
>>> list(senkawa.brace_expand('index.html{,.backup}'))
['index.html', 'index.html.backup']

# Nested patterns
>>> list(senkawa.brace_expand('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(senkawa.brace_expand('{07..10}'))
['07', '08', '09', '10']

# An optional increment can be specified for ranges.
>>> list(senkawa.brace_expand('{a..g..2}'))
['a', 'c', 'e', 'g']

# Ranges can go in both directions.
>>> list(senkawa.brace_expand('{4..1}'))
['4', '3', '2', '1']

# Numbers can be negative
>>> list(senkawa.brace_expand('{2..-1}'))
['2', '1', '0', '-1']

# Unbalanced braces raise an exception.
>>> list(senkawa.brace_expand('{1{2,3}'))
Traceback (most recent call last):
    ...
senkawa.errors.UnbalancedBracesError: Unbalanced braces: '{1{2,3}'

# By default, the backslash is the escape character.
>>> list(senakwa.brace_expand(r'{1\{2,3}'))
['1{2', '3']

# Setting 'escape' to False disables backslash escaping.
>>> list(senkawa.brace_expand(r'\{1,2}', escape=False))
['\\1', '\\2']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

senkawa-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

senkawa-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file senkawa-0.1.0.tar.gz.

File metadata

  • Download URL: senkawa-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for senkawa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7eea640b52cd11cea9b7cb981a5e17bd9177912942528871bf01d79889d63321
MD5 633ddfedb10765b9626cb9ac420f7804
BLAKE2b-256 d10bdd5d8c9faef336c811fc1d856f809aec911f4bb19e878c89671a1c72d414

See more details on using hashes here.

File details

Details for the file senkawa-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: senkawa-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for senkawa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60930e01f0a24997748b51db031b7c12010e71421624afbcab5b2cbf82db5516
MD5 57327d8815874a1708182e48cccfdf34
BLAKE2b-256 3d93741cc7bb70b3e7b7bd3a76a9601dd6ad5b4d041fb73021b44788898aceb1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page