Skip to main content

PEP 561 type stubs generator for cffi modules

Project description

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/README.md for a hands-on guide!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cffi_stubgen-1.0.0.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cffi_stubgen-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file cffi_stubgen-1.0.0.tar.gz.

File metadata

  • Download URL: cffi_stubgen-1.0.0.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cffi_stubgen-1.0.0.tar.gz
Algorithm Hash digest
SHA256 744ca556d2fe2f44b44bec2e1624be5e293634e2908cdb687165657d99c8bc1d
MD5 168bb8024fd14a116e8bf364d398a1df
BLAKE2b-256 8305d9dd0739a2ed0157f0766dbb965fe8d48fa90033117819c6974516689bc5

See more details on using hashes here.

File details

Details for the file cffi_stubgen-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cffi_stubgen-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cffi_stubgen-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f602c550dfaa670688cd5496756a9e25ef5fee56e42010951a3f9aa87add765
MD5 0a6058be34b5f748e9e3ccd76bae707b
BLAKE2b-256 9b2fccf2d982caa85df39bd0d51756f56d3efc28e678a43e66a4fdde3363fc52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page