ctypesgen
Python wrapper generator for ctypes
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 ctypesgenuv
uv add ctypesgenpoetry
poetry add ctypesgenInstalling 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
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
pyclibraryParses C header files and automates…
permissive · top 15,000 on PyPI
cxxheaderparserParses C++ header files into Python data…
permissive · top 15,000 on PyPI
comtypescomtypes is a pure Python library for defining,…
permissive · top 5,000 on PyPI
cwrapcwrap is a Python wrapper around C code that…
copyleft · top 15,000 on PyPI
pcppA pure Python implementation of a C99…
permissive · top 15,000 on PyPI
pycparserpycparser is a C language parser written in…
permissive · top 100 on PyPI
pyseccomppyseccomp provides a pure-Python interface to…
permissive · top 5,000 on PyPI
jaraco.windowsProvides a pure-Python interface to Windows…
permissive · top 15,000 on PyPI
cintWraps ctypes integer types to perform…
permissive · top 5,000 on PyPI
pywin32-ctypesA pure-Python reimplementation of pywin32 that…
permissive · top 5,000 on PyPI