skillfed

bashlex

Python parser for bash

bashlex v0.18 16.5M downloads/30d#1,150 on PyPI642
Copyleft license GPLv3+ DORMANT released

What it is and what it does

bashlex is a Python port of GNU bash's internal parser, transliterated from C to parse bash shell syntax into a complete AST. Unlike shlex, it understands complex bash constructs such as command substitutions, process substitutions, and nested expansions, making it suitable for tools that need to analyze or manipulate bash scripts programmatically.

The package does not execute shell code—it only parses and tokenizes. It has a single runtime dependency (enum34 for older Python versions) and installs as a pure Python wheel with low friction. The codebase is dormant but stable; it was last updated in January 2023 and has no known security vulnerabilities.

Use it for:

  • Build shell script analyzers or linters that need to understand bash syntax beyond simple word splitting
  • Implement shell command documentation tools that parse and explain bash constructs
  • Extract and analyze command structures from bash scripts for auditing or refactoring
  • Tokenize bash input more accurately than shlex for tools that handle process or command substitutions

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

bashlex parses bash shell syntax into an abstract syntax tree (AST), supporting complex constructs like command and process substitutions that standard tools like shlex cannot handle.

Yes, if you need to parse bash syntax programmatically. bashlex is stable, well-tested, has no vulnerabilities, and solves a specific problem that standard library tools cannot. The GPLv3+ license is a blocker only for proprietary projects; open-source projects should install without hesitation. The dormant maintenance status is not a concern for a parser—the bash syntax it targets is mature and unlikely to change significantly.

Install

bashlex on PyPI

pip

pip install bashlex

uv

uv add bashlex

poetry

poetry add bashlex

Installing bashlex

Before you install

Installation is straightforward with low friction. The package is dormant (last release 2023-01-18, 1304 days ago) but the repository remains active and well-maintained for its scope; it has 642 stars and no known vulnerabilities.

License in practice

bashlex is licensed under GPLv3+, a copyleft license. Any derivative work or distribution must also be open-source under compatible terms; proprietary projects cannot include this package without legal review.

Quickstart

pip install bashlex

import bashlex
parts = bashlex.parse('echo hello')
for ast in parts:
    print(ast.dump())

Requires Python 2.7 or Python 3.5+; does not support Python 3.0–3.4.

Verify before relying

  • Whether arithmetic expressions $((..)) support is planned or considered out of scope
  • Performance characteristics on very large or deeply nested bash scripts

Package facts

License GPLv3+ (copyleft)
Python support supports the current Python release (>=2.7, !=3.0, !=3.1, !=3.2, !=3.3, !=3.4)
Install friction low — pure-Python wheel
Runtime dependencies 1 — enum34
Maintenance dormant — 1,304 days since the last release
Last repo commit
First released
Downloads 16,475,266/month — #1,150 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: bashlex-0.18-py2.py3-none-any.whl

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)Operating System :: OS IndependentProgramming Language :: PythonTopic :: Software Development :: Libraries :: Python ModulesTopic :: System :: System ShellsTopic :: Text Processing

Tags

bash parser pythonshell syntax parsingbash ast generatorcommand substitution parserbash tokenizer
shell-parsingast-generation

More Python Modules packages