skillfed

ctypesgen

Python wrapper generator for ctypes

ctypesgen v1.1.1 168.6K downloads/30d#10,441 on PyPI336
Permissive license BSD-2-Clause AGING released

What it is and what it does

ctypesgen is a command-line tool that reads C header files and generates Python code using ctypes to call functions in compiled C libraries. It handles preprocessor macros by translating them into equivalent Python functions, and can output either Python wrapper modules or JSON for use with other binding generators like Mork.

The tool is designed for developers who need to integrate C libraries into Python projects without writing manual ctypes bindings. It supports platform-specific library loading, handles calling conventions, and can manage dependencies between libraries. The generated wrappers use ctypes directly, so they work on any platform with Python 3.7+ and the target C library available.

Use it for:

  • Generate Python bindings for system libraries like APR or Neon to call their C functions directly.
  • Automate wrapper creation for third-party C libraries to avoid hand-writing ctypes boilerplate.
  • Create JSON output for generating Lua bindings via Mork using the alien module.
  • Handle platform-specific library loading and calling conventions automatically.
  • Translate C preprocessor macros into callable Python functions for library constants and utilities.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

ctypesgen parses C header files and automatically generates Python ctypes wrapper code, enabling direct calls to C library functions from Python without manual binding work.

Yes, if you need to call C library functions from Python and want to avoid manual ctypes binding work. The low install friction and permissive license make it a practical choice. However, the aging maintenance status (last release October 2022) means you should verify that generated wrappers work correctly for your specific headers and libraries before committing to production use.

Install

ctypesgen on PyPI

pip

pip install ctypesgen

uv

uv add ctypesgen

poetry

poetry add ctypesgen

Installing ctypesgen

Before you install

Low install friction; pure Python wheel with no runtime dependencies. Maintenance is aging—last release October 2022, though the repository remains active with recent commits and no archived status.

License in practice

BSD-2-Clause (permissive) allows commercial and private use with minimal restrictions; redistribution requires retaining copyright notice and disclaimer.

Quickstart

pip install ctypesgen
ctypesgen -lneon /usr/local/include/neon/ne_*.h -o neon.py

Requires Python 3.7 or later; C header files and target library must be accessible on the system.

Verify before relying

  • Whether generated wrappers handle all C constructs equally well or have known limitations with complex types.
  • Current state of JSON output feature and compatibility with Mork for Lua binding generation.
  • How preprocessor macro function translation handles edge cases in real-world headers.

Package facts

License BSD-2-Clause (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 1,395 days since the last release
Last repo commit
First released
Downloads 168,644/month — #10,441 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: ctypesgen-1.1.1-py3-none-any.whl

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Build ToolsTopic :: Software Development :: Code GeneratorsTopic :: Software Development :: Pre-processors

Tags

ctypes wrapper generatorC header to Python bindingsautomatic FFI binding generationC library Python wrapperctypes code generationparse C headers Pythonforeign function interface generator
ctypescode-generationffi

More Build Tools packages