Skip to main content

Build Status PyPI version License Python versions

cffi-stubgen

cffi-stubgen is a tool for automatically generating PEP 561 type stubs (.pyi files) for Python modules built with cffi. This makes it easy to add type hints to your CFFI-based extensions, unlocking the full power of static type checking and IDE features.

Why generate stubs?

  • Type checking: Use tools like mypy to catch bugs before runtime.
  • IDE support: Get autocompletion, inline documentation, and better navigation in editors like VS Code and PyCharm.
  • Documentation: Stubs make your API clearer for users and contributors.

How does it work?

cffi-stubgen inspects the compiled CFFI module (not your Python source!) and generates stubs for all the functions and types exposed via CFFI. You simply point it at the built module, and it does the rest.

Quick Example

Suppose you have a CFFI module built in example_module._example. After installing your package, just run:

cffi-stubgen example_module._example

This will generate .pyi stubs for your module, ready for type checking and IDE use.

For a full walkthrough, see the example/README.md in this repository.

It will show you how cffi-stubgen can make mypy (and your IDE) aware of the arguments of

int add(int a, int b);

VSCode Autocomplete Example

Command Line Options

cffi-stubgen provides several options to customize stub generation:

  • -o, --output-dir: Set the output directory for stubs (default: same as module).
  • -t, --typedefs: Additional C types to define (space-separated).
  • --dry-run: Parse the module and report errors, but don’t write stubs.
  • --no-cleanup: If stub generation fails, do not remove incomplete stubs.
  • --verbose: Print detailed information during stub generation.
  • --stub-extension: Choose the file extension for stubs (pyi [default] or py).
  • MODULE_NAME: The fully qualified name of your cffi module (e.g., example_module._example).

Learn More

See the example for a hands-on guide!

Metadata

Release files for cffi-stubgen 1.0.2

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

Source distribution (sdist)

Source distribution for cffi-stubgen 1.0.2
File Size Uploaded
cffi_stubgen-1.0.2.tar.gz 44.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cffi-stubgen 1.0.2
File Interpreter ABI Platform
cffi_stubgen-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.2 kB

Release files / cffi_stubgen-1.0.2.tar.gz

Download URL cffi_stubgen-1.0.2.tar.gz
Size 44.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d354491e4dc77bbbfb70aaf223a5b5e6937ba55823ae587a6734a53e6292ecb3
BLAKE2b-256 checksum
How to use checksums
217d40a02764c4b9d3f4c4c47c5356afe2016e913e36a10760c1808e50071e4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / cffi_stubgen-1.0.2-py3-none-any.whl

Download URL cffi_stubgen-1.0.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63ae1ca3d7aa75f5f1ece2dcaca085b67ef2e561c41207c81bab852f2ee7fff4
BLAKE2b-256 checksum
How to use checksums
0f57625be1eddb36ad3db5d57d33d4370b8aea0e05e7699cc357d4155d1de056
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

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