Skip to main content

chaquopy-stubgen

This tool is a Python type stub generator from Java classes. It is optimized for the usage with Android via chaquopy v17 and briefcase.

The generated stubs can be used with Python 3.10 or higher.

⚠️ Disclaimer: This is not an official tool of the Chaquopy project. It is an independent, community-maintained project.

CLI Usage

Example call uv run -m chaquopy_stubgen "$ANDROID_HOME/platforms/android-35/android.jar"

$ uv run -m chaquopy_stubgen --help
usage: __main__.py [-h] [--jvmpath JVMPATH] [--output-dir OUTPUT_DIR] [--no-clean] [--cache-dir CACHE_DIR] inputs [inputs ...]

Generate Python Type Stubs for Java classes that are optimized for chaquopy.

positional arguments:
  inputs                List of .jar/.aar files, directories containing .class files, Android platform shorthands (e.g.
                        'android-35'), or Maven coordinates (e.g. 'androidx.appcompat:appcompat:1.0.2') to generate stubs for.

options:
  -h, --help            show this help message and exit
  --jvmpath JVMPATH     path to the JVM ("libjvm.so", "jvm.dll", ...) (default: use system default JVM)
  --output-dir OUTPUT_DIR
                        path to write stubs to (default: ./dist/stubs)
  --no-clean            skip clearing the output directory before generating stubs
  --cache-dir CACHE_DIR
                        directory for caching downloaded artifacts (default: ~/.cache/chaquopy-stubgen)

Caveats & Limitations

Importing Java Packages

Always use from java.lang import String rather than import java.lang.String. While the stubs permit both forms, only the first works at runtime under chaquopy's import hook. See the chaquopy documentation for details.

Handling of null Values

In Java, any reference type can in principle be null. Annotating every return type as X | None would be technically correct, but makes the generated stubs very noisy and forces callers to perform if ... is not None: checks everywhere.

Whether a method can actually return null usually only becomes apparent from its documentation. chaquopy-stubgen therefore ships a whitelist of methods that are documented to return null; those are emitted with | None appended to their return type. All other reference return types are treated as non-optional, even though they could theoretically be null at runtime.

The whitelist is not exhaustive and may have gaps or false positives. Feel free to open an issue or pull request if you find a missing or incorrect entry.

Development

  • Create venv: uv sync
  • Test: uv run pytest

Credits

This is based on stubgenj, but generates stubs optimized for chaquopy and is internally reworked to use ASM instead of Java Reflection.

Metadata

Release files for chaquopy-stubgen 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chaquopy-stubgen 0.3.3
File Size Uploaded Provenance Actions
chaquopy_stubgen-0.3.3.tar.gz 26.8 MB With provenance Details for chaquopy_stubgen-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chaquopy-stubgen 0.3.3
File Interpreter ABI Platform Actions
chaquopy_stubgen-0.3.3-py3-none-any.whl Python 3 none any Details for chaquopy_stubgen-0.3.3-py3-none-any.whl

Total release size: 27.1 MB

Release files / chaquopy_stubgen-0.3.3.tar.gz

Download URL chaquopy_stubgen-0.3.3.tar.gz
Size 26.8 MB
Tags Source
SHA-256 checksum
How to use checksums
4e870c960abdb8ad7a6e4f6a7beb0e1083bb8535a13e44ba6f2e412bc3c6c367
BLAKE2b-256 checksum
How to use checksums
29180f28723413f41b7e0216c71a956b9103bfa0ecc61a8edc8348f78bc6d5e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Release files / chaquopy_stubgen-0.3.3-py3-none-any.whl

Download URL chaquopy_stubgen-0.3.3-py3-none-any.whl
Size 226.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a248c48e9af8439098ce6486feed9c9e738792e16d9b16e7b685d1682a513fe5
BLAKE2b-256 checksum
How to use checksums
f343fdbfc094f1ab3810f3eb623a5e77d20c193d3678ee2226ee4d88340b4e93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Security for chaquopy-stubgen 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chaquopy_stubgen-0.3.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page