Pact Python FFI

0.4.28.2 · active · verified Thu Apr 16

`pact-python-ffi` provides low-level Python bindings for the underlying Pact FFI (Foreign Function Interface) library, which is written in Rust. It enables Python applications to directly interact with the core Pact logic for contract testing. While often an internal dependency of the higher-level `pact-python` library, it can be used independently for advanced FFI control. The current version is `0.4.28.2`, and it is part of the `pact-python` monorepo, following its active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use basic functions from the `pact-python-ffi` library, such as initializing FFI logging and retrieving the underlying FFI library version. It shows how to interact with the FFI directly.

import os
from pact_ffi import ffi_version, ffi_log_level, ffi_init

# Initialize the FFI logging
# PACT_LOG_LEVEL can be 'trace', 'debug', 'info', 'warn', 'error'
log_level = os.environ.get('PACT_LOG_LEVEL', 'info')
ffi_init(log_level)
print(f"Pact FFI initialized with log level: {log_level}")

# Get and print the FFI library version
version = ffi_version()
print(f"Pact FFI library version: {version}")

# Example of setting log level dynamically (optional, usually set once)
# ffi_log_level("debug")
# print("Log level set to debug.")

view raw JSON →