Skip to main content

stubpy

Generate accurate .pyi stubs for your Python package, with **kwargs and *args traced back to the parameters they forward to. Standard library only.

Tests Docs PyPI Python CPython 3.10-3.15 PyPy GraalPy Free-threaded Pyodide License: MIT Documentation Ruff

Features

Feature What you get
**kwargs / *args back-tracing Forwarded parameters written into the stub signature.
Source and runtime Parses the source and imports the module, merged per symbol; an import policy (--imports none) executes nothing.
Alias preservation Aliases like Length stay as written, with imports added.
Special classes Dedicated stubs for dataclasses, enums, TypedDict, NamedTuple, Generic, overloads.
Compiled extensions C API, Cython, pybind11 and nanobind modules, including docstrings.
Package generation One command stubs a whole tree, with __init__.pyi.
Check mode stubpy check exits 1 on missing or stale stubs.
Orphan pruning --prune removes stubs whose module no longer exists; stubs tracked in git are kept.
Hints @hint.signature, @hint.returns, @hint.ignore for what introspection misses.
Incremental merge Rewrites only the marked region and keeps hand edits.
Stub-only packages --stub-package writes a PEP 561 <pkg>-stubs distribution, ready to build.
Run cache --cache reuses the stubs of modules unchanged since the last run.
Type-checked stubs --typecheck runs mypy (or pyright) over the stubs; errors are reported per stub.
Docstring types --infer-types fills missing types from NumPy, Google and Sphinx docstrings.
Extension points Annotation handlers, forwarding resolvers and stub hooks.
Configuration [tool.stubpy] in pyproject.toml; flags override it.
Version branches sys.version_info / sys.platform blocks kept, as typeshed does.
Lazy attributes Names behind a module __getattr__ become explicit.
Pre-commit hooks stubpy-check and stubpy-generate, ready to use.

CPython 3.10 to 3.15 (free-threaded 3.14t included), PyPy, GraalPy and Pyodide. No dependencies.

Install

pip install stubpy

Use

stubpy src/mypkg -o stubs        # write stubs/mypkg/**/*.pyi
stubpy check --diff              # exit 1 when a stub is stale
stubpy render mypkg/core.py      # print one stub
import stubpy

report = stubpy.generate("src/mypkg", "stubs")   # write stubs
print(stubpy.render("mypkg/core.py").text)       # one module, nothing written
stubpy.check("src/mypkg", "stubs").ok            # False when a stub is stale

Example

# shapes.py
class Shape:
    def __init__(self, color: str = "black", opacity: float = 1.0): ...


class Rect(Shape):
    def __init__(self, width: float, height: float, **kwargs):
        super().__init__(**kwargs)

stubpy render shapes.py:

class Shape:
    def __init__(self, color: str = 'black', opacity: float = 1.0) -> None: ...

class Rect(Shape):
    def __init__(
        self,
        width: float,
        height: float,
        *,
        color: str = 'black',
        opacity: float = 1.0,
    ) -> None: ...

Configuration

# pyproject.toml
[tool.stubpy]
targets    = ["src/mypkg"]
output_dir = "stubs"

With this, stubpy and stubpy check need no arguments.

CI and pre-commit

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/wzjoriv/stubpy
    rev: 1.4.0
    hooks:
      - id: stubpy-check
# GitHub Actions step
- run: stubpy check --diff --typecheck

Documentation

Contributing

Setup, the scripts/dev.py commands and the project's conventions are in the contributing guide.

License

MIT. See LICENSE.

Metadata

Release files for stubpy 1.4.0

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

Source distribution (sdist)

Source distribution for stubpy 1.4.0
File Size Uploaded Provenance Actions
stubpy-1.4.0.tar.gz 317.4 kB With provenance Details for stubpy-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stubpy 1.4.0
File Interpreter ABI Platform Actions
stubpy-1.4.0-py3-none-any.whl Python 3 none any Details for stubpy-1.4.0-py3-none-any.whl

Total release size: 727.4 kB

Release files / stubpy-1.4.0.tar.gz

Download URL stubpy-1.4.0.tar.gz
Size 317.4 kB
Tags Source
SHA-256 checksum
How to use checksums
22744b3521b8911c111007b9cee8ac051c03334003221473f6f7f8a14ae69cf4
BLAKE2b-256 checksum
How to use checksums
a6c9133cf6c7057f80e224b4945b6b449027e443470902e912861b5e01a3c62e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / stubpy-1.4.0-py3-none-any.whl

Download URL stubpy-1.4.0-py3-none-any.whl
Size 410.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c8af8690c2668467c8043d47d8f0dc26b09cb8074f0359a9622b9b2d465c87f
BLAKE2b-256 checksum
How to use checksums
037e090f9dc4c633d8456c6b165de940f61aacb197227c2ad25ea32676da79db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Security for stubpy 1.4.0

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 stubpy-1.4.0.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 Nov 29, 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.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files Full provenance

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