CLI Reference¶
The autopxd command-line tool generates Cython .pxd files from C/C++ headers.
Basic Usage¶
Options¶
-v, --version¶
Print program version and exit.
-b, --backend <name>¶
Select the parser backend. Options: auto (default), libclang, pycparser.
auto: Use libclang if available, fall back to pycparserlibclang: Full C/C++ support via LLVMpycparser: Legacy C99 parser (no C++ support)
--list-backends¶
Show available backends and exit.
--json¶
Output in JSON format (for use with --list-backends).
-x, --cpp¶
Parse as C++ (requires libclang backend).
--std <standard>¶
Specify the language standard (requires libclang backend).
-I, --include-dir <dir>¶
Add a directory to the include search path. Can be specified multiple times.
Note: The libclang backend automatically detects system include paths (e.g., /usr/include), so you typically only need -I for project-specific directories.
-D, --define <macro>¶
Define a preprocessor macro. Can be specified multiple times.
-w, --whitelist <file>¶
Only generate declarations from specified files. Can be specified multiple times.
--clang-arg <arg> [libclang]¶
Pass an argument directly to libclang. Can be specified multiple times.
--no-default-includes [libclang]¶
Disable automatic detection of system include directories. By default, the libclang backend queries the system clang compiler to find standard include paths. Use this option if you need full control over include paths.
# Disable auto-detection and specify all paths manually
autopxd --no-default-includes -I /my/custom/sysroot/include myheader.h
-P, --project-prefix <path> [libclang]¶
Treat headers under the specified path as project headers rather than system headers. This is essential for umbrella headers—headers that include many sub-headers but have few declarations of their own (like sodium.h, openssl/ssl.h).
Without this option, declarations from sub-headers in system locations (e.g., /usr/include, /opt/homebrew/include) are filtered out. The --project-prefix option whitelists paths so their declarations are included.
Can be specified multiple times for multiple prefixes.
# Include declarations from all sodium/*.h sub-headers
autopxd -I /opt/homebrew/include \
--project-prefix /opt/homebrew/include/sodium \
/opt/homebrew/include/sodium.h
# Multiple prefixes
autopxd -I /usr/include \
-P /usr/include/openssl \
-P /usr/include/crypto \
/usr/include/openssl/ssl.h
--no-recursive [libclang]¶
Disable recursive parsing of umbrella headers. By default, when an umbrella header is detected, autopxd recursively parses included project headers to collect all declarations. Use this option to only parse the top-level header.
--max-depth <n> [libclang]¶
Set the maximum recursion depth for umbrella header processing (default: 10). This prevents infinite recursion in cases of circular includes.
-q, --quiet¶
Suppress warnings (e.g., backend fallback warnings).
--debug / --no-debug¶
Dump preprocessor output to stderr for debugging.
-h, --help¶
Show help message and exit.
Examples¶
Generate pxd from a header¶
With include directories¶
Using libclang for C++¶
Using C++17 standard¶
Working with umbrella headers¶
Umbrella headers like sodium.h include many sub-headers but define few declarations themselves. Use --project-prefix to include declarations from sub-headers:
# Generate bindings for libsodium (installed via homebrew)
autopxd -I /opt/homebrew/include \
-P /opt/homebrew/include/sodium \
/opt/homebrew/include/sodium.h sodium.pxd
# Generate bindings for OpenSSL
autopxd -I /usr/include \
-P /usr/include/openssl \
/usr/include/openssl/ssl.h ssl.pxd
Check available backends¶
Troubleshooting¶
libclang not available¶
If you see "libclang not available, falling back to pycparser", install the system libclang library:
Ubuntu/Debian:
macOS:
Or use Docker:
C++ parsing fails¶
Make sure you're using the libclang backend:
Empty output from umbrella headers¶
If you're parsing an umbrella header (like sodium.h) and getting empty or minimal output, the sub-headers are probably in a system location. Use --project-prefix to whitelist them:
# Find where the library headers are installed
pkg-config --cflags libsodium
# Output: -I/opt/homebrew/include
# Use --project-prefix with the sub-header directory
autopxd -I /opt/homebrew/include \
-P /opt/homebrew/include/sodium \
/opt/homebrew/include/sodium.h
You can verify the prefix is working by using --debug to see which declarations are being found.
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Parse error or invalid input |
| 2 | Invalid command-line arguments |