Frequently Asked Questions¶
Start with the question closest to your task. Each answer links to the complete, tested workflow.
Fortran¶
How do I call Fortran from Python?
Use PRIK to build your Fortran source into an importable Python extension, then call it with NumPy values that match the generated contract. Follow Call Your First Fortran Function from Python for a complete source-to-result example.
How do I generate Python bindings for a Fortran module?
Pass the module source to PRIK. It generates the extension and exposes supported public procedures and module state through Python. Start with Generate Python Bindings for a Fortran Module.
How do I wrap an existing Fortran library for Python?
Build the public Fortran sources with PRIK and link their native dependencies into the same extension. The shared-library guide explains the build options, while the tested BLAS, LAPACK, FFTPACK, MINPACK, and BSPLINE-FORTRAN examples show complete libraries. The example gallery also includes the C libm and TA-Lib.
How do I expose Fortran derived types as Python classes?
PRIK maps supported derived types to Python classes with constructors, methods, fields, and explicit ownership rules. See Wrap Fortran Derived Types as Python Classes.
How do I pass NumPy arrays to Fortran without unnecessary copies?
Pass arrays with the dtype, rank, shape, layout, strides, and writeability required by the generated contract. Compatible arrays can cross the wrapper without a layout conversion; incompatible inputs are rejected instead of being silently copied. See Pass NumPy Arrays to Fortran.
C¶
How do I call C from Python?
Build a supported C source with PRIK and import the generated extension. A
primitive function can be wrapped directly from source; pointers, arrays,
strings, hidden outputs, and status handling use an editable semantic .pyi
contract. Follow Build a Scalar C Function
for the complete first example.
Why do I need to edit the generated C `.pyi` contract?
C pointer syntax does not say whether a pointer represents one value, an output, an array, or caller-owned storage. PRIK generates a conservative starter contract instead of guessing. Edit it to state the intended storage, shape, and result projection, then build it against the C implementation. See Author a Contract for Pointers and Arrays.
Which C arrays and strings are supported?
C wrappers support primitive non-Boolean NumPy arrays of ranks 1–15 with C-contiguous storage. Strings are supported as rank-zero inputs and caller-owned storage. Arrays of strings, Boolean arrays, native C array declarators, ranks outside 1–15, and non-C-contiguous arrays are unsupported. See C Support: What Is Supported for the complete boundary.
How do I wrap an existing C library or large header?
First create symbols.txt with one C function name per line:
vendor_add
vendor_scale
Generate a target-specific contract containing only those functions:
python3 -m prik generate --pyi --language c include/vendor.h \
--include-exposure roots-only \
--export-symbols symbols.txt \
--out vendor.pyi
Pass the header's normal -I, -D, and --std options when it needs them.
Review vendor.pyi before building. Primitive scalar signatures are ready to
use; edit pointer parameters when they represent arrays, outputs, or strings.
Build the contract against the installed library:
python3 -m prik --language c vendor.pyi \
--native-library vendor \
--native-library-dir /path/to/lib \
--out vendor
Here vendor is the linker name for a library such as libvendor.so. Use
--native-library-dir only when the library is outside the linker's normal
search path. Use --native-c-sources instead when you have implementation
sources, or --native-objects for existing objects or archives.
Continue with the page that matches the part you need:
- Select functions from a large or system
header explains the
symbols.txtformat, included-header visibility, and selection failures. - Choose the pointer
contract
explains how to describe one value, an output, an array, or caller-owned
storage in
vendor.pyi. - Supply native dependencies explains when to use implementation sources, objects, library names, library directories, include paths, and compiler definitions.
- Wrap the system math library is the complete example for selecting scalar functions from an installed system header and linking an already compiled library.
- Wrap TA-Lib is the complete example for a large third-party header with NumPy arrays, output storage, an edited contract, and a reviewed API inventory.
What happens when a C API is not supported?
PRIK rejects unsupported C forms before wrapper planning or native compilation; parser acceptance alone is not a build promise. The diagnostic identifies the blocked declaration or contract. Check Current C Limits, the feature matrix, and diagnostic codes.
Choosing a Tool¶
Should I use PRIK or f2py?
Use NumPy's f2py when its established
generated API — or an editable
.pyf signature — is
enough for your project.
Choose PRIK when you want to design the Python API rather than only generate a
wrapper: its editable semantic .pyi contract
renames, hides, flattens, and reprojects the surface, and it treats
NumPy arrays as complete contracts covering dtype, rank,
shape, layout, strides, and mutation. PRIK is alpha, so check the
feature matrix for exact limits.
The side-by-side comparison covers the trade-off in full, with measured runtime and build-time results.