skillfed

javalang

Pure Python Java parser and tools

javalang v0.13.0 369.8K downloads/30d#7,183 on PyPI795
Permissive license DORMANT released

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 javalang

uv

uv add javalang

poetry

poetry add javalang

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonTopic :: Software Development :: Libraries

Tags

java parser pythonjava source code analysisjava ast treejava lexer tokenizerparse java files python
java-parsingast-analysiscode-inspection

More Libraries packages