javalang
Pure Python Java parser and tools
What it is and what it does
javalang is a pure Python library that parses Java source code into an abstract syntax tree (AST) you can inspect and traverse. It includes a lexer (tokenizer) and parser targeting Java 8, built from the official Java language specification. You pass a complete Java source file as a string to javalang.parse.parse() and get back a CompilationUnit object—the root of a tree where each node represents a syntactic element (package, class, method, etc.). You can iterate over the tree, filter by node type, and extract metadata like class names, package declarations, and method signatures.
The library exposes its components individually: you can tokenize code directly with javalang.tokenizer.tokenize() to get a stream of JavaToken objects with position and value info, or use javalang.parser.Parser directly on a token stream to parse snippets (expressions, type declarations, etc.) rather than full compilation units. It depends only on six for Python 2/3 compatibility, making installation lightweight. However, the project is dormant—last updated in 2020—so it will not track language evolution or receive bug fixes.
Use it for:
- Extract class and method names from Java source files for documentation or code analysis tools.
- Build a Java code search or indexing tool that needs to understand package and type structure.
- Analyze Java code for metrics (method count, inheritance depth, etc.) without running a compiler.
- Implement a Java code refactoring or transformation tool that needs to parse and manipulate the AST.
- Validate or lint Java code snippets in a Python application without invoking javac.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
javalang is a pure Python lexer and parser for Java 8 source code that builds an abstract syntax tree you can traverse to extract information about Java classes, methods, and other language elements.
Yes, if you need to parse Java 8 code and can tolerate dormant maintenance. The library is stable, has no known vulnerabilities, installs with minimal friction, and carries a permissive license. It is well-suited for one-off analysis or tooling. Avoid it if you need active maintenance, support for newer language features, or ongoing bug fixes.
Install
javalang on PyPI
pip
pip install javalanguv
uv add javalangpoetry
poetry add javalangInstalling javalang
Before you install
Installation is straightforward with low friction; the package depends only on six and has wheels for both Python 2 and 3. However, maintenance is dormant—the last release was in 2020 and no commits have landed since 2023-09-17, so bug fixes or compatibility updates are unlikely.
License in practice
Licensed under MIT (permissive), so you can use, modify, and distribute javalang freely in both open and closed projects with minimal restrictions.
Quickstart
import javalang
tree = javalang.parse.parse("package example; class Test {}")
print(tree.package.name)
print(tree.types[0].name)
Verify before relying
- Whether the Java 8 parser handles syntax features beyond Java 8 or only Java 8 constructs.
- Performance characteristics when parsing large or complex Java source files.
- Compatibility with current Python versions beyond what classifiers declare.
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — six |
| Maintenance | dormant — 2,330 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 369,845/month — #7,183 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: javalang-0.13.0-py2-none-any.whl; javalang-0.13.0-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
pytokenspytokens is a Python tokenizer that parses…
permissive · top 1,000 on PyPI
tree-sitter-javaProvides a Java language grammar for…
permissive · top 5,000 on PyPI
funcparserlibFuncparserlib is a recursive descent parsing…
permissive · top 15,000 on PyPI
plyPLY is a lexer and parser generator for Python…
permissive · top 1,000 on PyPI
pygmarsPygmars builds lightweight lexers and parsers…
permissive · top 15,000 on PyPI
slySLY is a pure-Python implementation of lex and…
permissive · top 5,000 on PyPI
proto-schema-parserParses and generates Protobuf schema files…
permissive · top 15,000 on PyPI
py-partiql-parserParses and executes PartiQL queries against…
permissive · top 5,000 on PyPI
esprimaEsprima parses ECMAScript (JavaScript) source…
permissive · top 15,000 on PyPI
luaparserParses Lua source code into an abstract syntax…
permissive · top 15,000 on PyPI