Registry / serialization / luaparser

luaparser

JSON →
library4.0.1pypypi✓ verified 83d ago

luaparser is a Python library for parsing Lua code into an Abstract Syntax Tree (AST). It provides a programmatic interface to analyze, manipulate, and generate Lua code. The current version is 4.0.0, and it maintains an active, though irregular, release cadence addressing bugs and adding features.

pip install luaparser
INSTALL
IMPORT
SIG · LUAPARSER
L
luaparser
serializationpythonv4.0.1
Install
1.8s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import luaparser
from luaparser import parse

Parses a simple Lua script string and prints its Abstract Syntax Tree (AST) representation to the console.

from luaparser import parse lua_code = """ -- This is a simple Lua script local function greet(name) print("Hello, " .. name .. "!") end greet("World") """ # Parse the Lua code into an AST ast = parse(lua_code) # Print a representation of the AST # In luaparser 3.3.1+, parse() no longer prints directly print(ast.show())
Debug
Known issues
breakingSource file encoding changed from local encoding to UTF-8. Parsing files with non-UTF-8 encodings will now raise a `UnicodeDecodeError` by default.
fix
Ensure all Lua source files are saved with UTF-8 encoding. If not possible, pre-read the file with its correct encoding and pass the string to `parse()`.
affects: 4.0.0 and later
breakingThe `String` AST node's internal representation for string values changed. The `s` attribute now stores bytes, and a new `raw` attribute stores the unescaped string. Code directly accessing `s` for string content may break.
fix
Access the `raw` attribute of `String` nodes for the unescaped string value. Example: `string_node.raw`.
affects: 4.0.0 and later
breakingThe parser is now stricter: it fails immediately on an unknown token instead of attempting to skip it. This means previously 'tolerated' invalid Lua code will now raise a `ParseError`.
fix
Review Lua code for strict grammar compliance. The `ParseError` message should indicate the location of the offending token.
affects: 4.0.0 and later
breakingThe `Index.idx` attribute type changed from a `String` node to a `Name` node. Code expecting `Index.idx` to have a `.value` attribute for the index string will break.
fix
Update AST traversal logic to check the type of `Index.idx`. If it's a `Name` node, access `Index.idx.id` for the index name. If it's a `String` node (for older versions or specific cases), use `Index.idx.raw` (for 4.0.0+) or `Index.idx.value` (for 3.x).
affects: 3.0.0 and later
gotchaThe `parse()` function no longer prints the AST directly to `stdout` upon execution. Users must explicitly call `ast.show()` or `print(ast.show())` to visualize the parsed tree.
fix
After parsing, call `print(ast.show())` to see the AST representation.
affects: 3.3.1 and later
Upgrade
Version history
4.0.1latest on PyPI · released Jun 3, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
luaparser — pip install luaparser · libregistry