luaparser
A lua parser in Python
What it is and what it does
Luaparser is a Python library that reads Lua source code and builds an abstract syntax tree (AST), letting you programmatically inspect and manipulate Lua code structure. It ships both as a library for Python code and as a command-line tool. The parser supports Lua 5.3 and 5.4 grammar versions and can output AST data as JSON, XML, or pretty-printed text.
You can walk the entire AST to find specific node types, use a visitor pattern to process nodes, or construct AST objects directly in Python and regenerate Lua source code from them (though that feature is marked experimental). The library depends on antlr4-python3-runtime for parsing and multimethod for method dispatch.
Use it for:
- Analyze Lua code structure in a static analysis or linting tool.
- Extract function definitions, variable names, or call patterns from Lua scripts.
- Transform or refactor Lua code by manipulating its AST and regenerating source.
- Build development tools that need to understand Lua syntax without executing it.
- Convert Lua code to other formats or intermediate representations via AST inspection.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses Lua source code into an abstract syntax tree (AST) and provides tools to traverse, analyze, and regenerate Lua code from the AST.
Yes. The package is actively maintained, has low install friction, carries a permissive MIT license, and solves a clear problem for anyone needing to parse or analyze Lua code in Python. No known vulnerabilities. The only caveat is that code regeneration is experimental, so rely on that feature cautiously.
Install
luaparser on PyPI
pip
pip install luaparseruv
uv add luaparserpoetry
poetry add luaparserInstalling luaparser
Before you install
Low friction installation with a pure Python wheel and only two runtime dependencies (antlr4-python3-runtime and multimethod). Actively maintained with a recent release.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects.
Quickstart
pip install luaparser
from luaparser import ast
src = "local x = 42"
tree = ast.parse(src)
print(ast.to_pretty_str(tree))
Verify before relying
- Whether the parser handles all Lua 5.3 and 5.4 grammar features completely or if there are known gaps.
- Performance characteristics when parsing large Lua files or complex nested structures.
- Stability of the experimental Lua code regeneration feature (ast.to_lua_source).
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — antlr4-python3-runtime, multimethod |
| Maintenance | actively maintained — 25 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 112,195/month — #12,378 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: luaparser-4.1.0-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
lupaLupa embeds Lua or LuaJIT runtimes into…
permissive · top 1,000 on PyPI
tree-sitter-luaProvides a tree-sitter grammar for parsing Lua…
permissive · top 5,000 on PyPI
astunparseConverts Python abstract syntax trees (ASTs)…
permissive · top 5,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI
promql-parserParses Prometheus query language (PromQL)…
unclear · top 15,000 on PyPI
openqasm3Provides a reference abstract syntax tree (AST)…
permissive · top 15,000 on PyPI
benigetBeniget performs compile-time analysis on…
permissive · top 15,000 on PyPI
sqloxidesqloxide parses SQL queries into a typed…
permissive · top 15,000 on PyPI
tree-sitter-pythonProvides a Python grammar for tree-sitter,…
permissive · top 5,000 on PyPI
fparserfparser parses Fortran source code (Fortran 77…
permissive · top 15,000 on PyPI