bashlex
Python parser for bash
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 bashlexuv
uv add bashlexpoetry
poetry add bashlexInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
oslexProvides a unified API for shell argument…
permissive · top 15,000 on PyPI
shellescapeProvides a `quote()` function that…
permissive · top 5,000 on PyPI
mslexProvides Windows-compatible command-line…
permissive · top 5,000 on PyPI
xonshXonsh is a Python-based shell that merges…
permissive · top 15,000 on PyPI
pipePipe enables shell-like infix syntax for…
permissive · top 15,000 on PyPI
parameter-expansion-patchedExpands POSIX and Bash shell parameter syntax…
permissive · top 15,000 on PyPI
sphinx-substitution-extensionsAdds substitution support to Sphinx directives,…
permissive · top 15,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
ast-commentsExtends Python's built-in `ast` module to…
permissive · top 15,000 on PyPI
bashkitBashkit is a sandboxed bash interpreter for…
permissive · top 15,000 on PyPI