Java‑to‑PYI is a Rust tool that reads compiled Java classes from .jar archives and generates Python stub files (.pyi) with type definitions only. It was originally designed to generate class declarations to provide accurate type hints in the Telegram codebase when developing Exteragram plugins.
cargo install java2pyi
- Clone this repo
git clone https://github.com/n08i40k/java2pyi
- Compile and install
cargo install --path .
- Collect the
.jarfiles you want stubs for, including the JDK ones (required for all use-cases, otherwise non-primitive java types won't be resolved)
mkdir jars
cp "$JAVA_HOME/jmods/../lib/../jre/lib/rt.jar" ./jars/ # or any jar holding the JDK classes
cp ./Telegram/TMessagesProj/build/outputs/*.jar ./jars/
- Create directory for stub files
mkdir stubs
- Start generator
java2pyi -i ./jars -o ./stubs
Where -i is a .jar file or a directory searched recursively for .jar files, and -o is the output directory for generated stubs.