PEP 561 type stubs generator for cffi modules
Project description
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
mypyto 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);
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] orpy).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!
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 cffi_stubgen-1.0.2.tar.gz.
File metadata
- Download URL: cffi_stubgen-1.0.2.tar.gz
- Upload date:
- Size: 44.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d354491e4dc77bbbfb70aaf223a5b5e6937ba55823ae587a6734a53e6292ecb3
|
|
| MD5 |
3313abaec594bfb484c35593ccf87c3e
|
|
| BLAKE2b-256 |
217d40a02764c4b9d3f4c4c47c5356afe2016e913e36a10760c1808e50071e4a
|
File details
Details for the file cffi_stubgen-1.0.2-py3-none-any.whl.
File metadata
- Download URL: cffi_stubgen-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63ae1ca3d7aa75f5f1ece2dcaca085b67ef2e561c41207c81bab852f2ee7fff4
|
|
| MD5 |
b02713136fddfa2a31c5513733e80576
|
|
| BLAKE2b-256 |
0f57625be1eddb36ad3db5d57d33d4370b8aea0e05e7699cc357d4155d1de056
|