Java-to-Python source translator with line-level structural correspondence for side-by-side review
Project description
j2py
j2py is a Java-to-Python source translator. It converts Java classes to Python that preserves line-level structural correspondence — same method order, same control flow, camelCase→snake_case naming — so reviewers can audit output against the original Java side by side. The goal is reviewable equivalence, not a fully idiomatic rewrite.
How it works
Java source
→ parse (tree-sitter-java)
→ analyze (symbols, dependency graph)
→ translate (deterministic rule layer, then optional LLM completion)
→ validate (syntax, lint, types)
→ Python output
The rule layer handles common language constructs deterministically (~70% of typical code). Where rules stop, Claude (optional) fills gaps using disk-cached prompts. Every file gets a confidence score based on rule-layer coverage and structured diagnostics for anything left unhandled.
Status
Alpha. The library is usable for experimentation, fixture-driven development, and batch translation of real Java projects, but construct coverage is still incomplete and output on large enterprise codebases will contain TODOs and review warnings.
Deterministic support today includes:
- tree-sitter Java parsing and symbol extraction
- class, nested class, local/anonymous class helpers, interface, enum, and record skeletons
- interface abstract methods, default methods, and static methods
- fields, constructors, methods, and overloads: chained constructor delegation,
builder-style forwarding merged into default parameters, and type-dispatch overload
groups via a vendored
@overloadedruntime dispatcher (ADR 0009) - common expressions: literals, identifiers, field access, arrays, class literals,
assignments, updates, ternaries, null checks, collection calls, string concat, and
typed
get(...)lowering for lists, maps, and common API receivers - stream pipelines:
map,filter,flatMap,distinct,sorted, collectors such astoList,toSet,joining,groupingBy/mapping,toMap, and block lambdas - control flow:
if/else, enhanced and classicfor,while,do while, safeswitchforms,try/catch/finally,throw,break, andcontinue - configured import emission, naming policy, type maps, exception maps, and comment flags
- dependency-ordered directory translation
- structured diagnostics, confidence scoring, validation, post-LLM structural verification, and optional Anthropic completion
- side-by-side Java/Python review via
j2py compare
Known gaps include:
- overload groups whose erased Python signatures collide (e.g.
intvslong) and static-method overload groups that still fall back to manual-dispatch TODOs - enum constant class bodies and complex enum static initialization
- annotation semantics beyond syntactic metadata shells
- runtime/framework behavior (dependency injection, persistence mappings, container lifecycle) — j2py translates source structure, not application frameworks
Quick start
Install the alpha from PyPI:
pip install --pre j2py-converter
j2py --help
The PyPI distribution is j2py-converter; the import package and CLI command are
j2py. (The bare j2py name on PyPI is owned by an unrelated project.)
Local development:
uv sync --locked
make check
Translate a file without LLM completion:
uv run j2py translate tests/fixtures/java/HelloWorld.java --no-llm --no-validate --dry-run
Translate a directory in dependency order:
uv run j2py translate path/to/java/root --output translated_py --no-llm
Side-by-side review in VS Code:
uv run j2py compare tests/fixtures/java/HelloWorld.java --no-llm
Print compare paths without opening an editor:
uv run j2py compare tests/fixtures/java/HelloWorld.java --no-open --no-llm
LLM completion (requires ANTHROPIC_API_KEY):
ANTHROPIC_API_KEY=... uv run j2py translate SomeClass.java
Quality gates
make check # ruff + mypy strict + pytest (excludes behavior, live_llm)
make test-behavior # Java/Python stdout/stderr/exit-code equivalence (requires JDK)
make test-targets # future xfail roadmap targets (empty while all targets graduated)
make release-check # alpha release gate: check + targets + behavior + dist check
Benchmark corpus
Translation quality is measured against an external Spring Framework checkout plus
a curated set of small Java construct fixtures under tests/fixtures/corpus/. Spring
is used as a realistic, open-source stress test — not as a product scope or target
runtime.
make corpus-spring-dense-check # preferred: density sample + construct fixtures vs baseline
make corpus-spring-dense # run without baseline comparison
make corpus-spring-broad # larger spring-context sample + constructs
make corpus-spring # historical lexical Spring-only baseline
Baseline: tests/fixtures/corpus/spring-dense-baseline.json. See
docs/CORPUS_SCOREBOARD.md and
docs/TRANSLATION_TARGETS.md.
On-demand live LLM evaluation (excluded from make check):
make test-llm-e2e
# or: ANTHROPIC_API_KEY=... uv run pytest -m live_llm tests/llm/test_e2e_llm.py -v -s
Adding translation rules
- Add or update a Java/Python fixture pair under
tests/fixtures/. - Implement the smallest deterministic rule in
j2py/translate/. - Graduate the behavior into normal tests once it passes.
- Run
make checkandmake corpus-spring-dense-check. - Update the dense corpus baseline only when the comparison shows no regressions.
Material translation policy changes should get an ADR under docs/decisions/.
Alpha release notes
j2py-converter is published as an alpha package. Expect incomplete construct
coverage, diagnostics for unsupported regions, and manual review on production-scale
codebases. See docs/RELEASING.md for the release checklist.
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file j2py_converter-0.3.0a1.tar.gz.
File metadata
- Download URL: j2py_converter-0.3.0a1.tar.gz
- Upload date:
- Size: 138.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fd5e513873e2bacb70ac641ed856ee1c468605adf93a13b134245349bfa91cb
|
|
| MD5 |
564907e8c6a21d58154969dd72ec42f8
|
|
| BLAKE2b-256 |
e80ac088f20245fb6e9a4bccf2af71b83dcc878333f1a0e93747af95c66f1a61
|
Provenance
The following attestation bundles were made for j2py_converter-0.3.0a1.tar.gz:
Publisher:
publish.yml on tomanizer/j2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
j2py_converter-0.3.0a1.tar.gz -
Subject digest:
9fd5e513873e2bacb70ac641ed856ee1c468605adf93a13b134245349bfa91cb - Sigstore transparency entry: 1808612534
- Sigstore integration time:
-
Permalink:
tomanizer/j2py@abcbeab215b5656f494bb8271f2d9a686bbe9f9f -
Branch / Tag:
refs/tags/v0.3.0a1 - Owner: https://github.com/tomanizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abcbeab215b5656f494bb8271f2d9a686bbe9f9f -
Trigger Event:
release
-
Statement type:
File details
Details for the file j2py_converter-0.3.0a1-py3-none-any.whl.
File metadata
- Download URL: j2py_converter-0.3.0a1-py3-none-any.whl
- Upload date:
- Size: 75.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57215368aab8b1d4e67c5f9a9ae9bea18ec6cee555ff4ab94bad41981da43502
|
|
| MD5 |
e88c9a64df4189b234f6f25ce9de84a8
|
|
| BLAKE2b-256 |
69afdf0caa163f4b84ee3303c207e07db46f92883188cbfe3273b2f8f495c29b
|
Provenance
The following attestation bundles were made for j2py_converter-0.3.0a1-py3-none-any.whl:
Publisher:
publish.yml on tomanizer/j2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
j2py_converter-0.3.0a1-py3-none-any.whl -
Subject digest:
57215368aab8b1d4e67c5f9a9ae9bea18ec6cee555ff4ab94bad41981da43502 - Sigstore transparency entry: 1808612537
- Sigstore integration time:
-
Permalink:
tomanizer/j2py@abcbeab215b5656f494bb8271f2d9a686bbe9f9f -
Branch / Tag:
refs/tags/v0.3.0a1 - Owner: https://github.com/tomanizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abcbeab215b5656f494bb8271f2d9a686bbe9f9f -
Trigger Event:
release
-
Statement type: