pact-python
Tool for creating and verifying consumer-driven contracts using the Pact framework.
What it is and what it does
Pact Python is a consumer-driven contract testing framework that replaces expensive end-to-end integration tests with fast, reliable unit tests. Instead of spinning up full test environments and coordinating multiple services, you define contracts that specify what a client expects from a server and what a server will provide—then verify both sides independently against that contract. This catches breaking changes early and lets you test locally without complex fixtures or test environments.
The package wraps the Pact framework (which supports 12+ languages) and provides a configurable mock server, powerful matching rules to prevent brittle assertions, and integration with Pact Broker or PactFlow for CI/CD workflows. It supports HTTP/REST and event-driven systems, runs on Python 3.10 and later across macOS, Windows, and Linux, and collects optional anonymous telemetry (disableable via PACT_DO_NOT_TRACK=1).
Use it for:
- Test microservice interactions locally without spinning up dependent services or complex test environments
- Verify that API clients and servers remain compatible before deploying, catching breaking changes early
- Document API contracts automatically and share them across teams via Pact Broker or PactFlow
- Replace brittle end-to-end integration tests with fast, deterministic unit tests that run in CI/CD
- Test event-driven systems by defining and verifying message contracts between producers and consumers
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pact Python implements consumer-driven contract testing for APIs and microservices, letting you write fast unit tests that verify both client and server expectations against a shared contract instead of running brittle end-to-end integration tests.
Yes. Pact Python is actively maintained, production-stable (Development Status 5), has no known vulnerabilities, low install friction, and solves a real problem—replacing expensive integration tests with reliable contract tests. The MIT license is permissive. Install it if you're testing APIs or microservices and want to shift testing left and reduce test environment complexity.
Install
pact-python on PyPI
pip
pip install pact-pythonuv
uv add pact-pythonpoetry
poetry add pact-pythonInstalling pact-python
Before you install
Low friction installation with three runtime dependencies. Actively maintained with recent releases; last commit 2026-08-13 and 677 repository stars indicate ongoing development and community use.
License in practice
MIT License permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal restrictions—only requiring preservation of copyright and license notices.
Quickstart
pip install pact-python
from pact import Consumer, Provider
consumer = Consumer('MyConsumer')
provider = Provider('MyProvider')
# Define contract expectations and verify interactions
Requires Python 3.10 or later; pact-python-ffi dependency may require a compatible FFI runtime on your system.
Verify before relying
- Specific HTTP/REST and event-driven system capabilities and their scope of support
- Details on the configurable mock server's feature set and configuration options
- How the matching rules system works and what types of brittle test scenarios it prevents
- Integration workflow details with Pact Broker / PactFlow for CI/CD
- Whether telemetry can be fully disabled and what data collection occurs by default
Package facts
| License | MIT License Copyright (c) 2017 Pact Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — pact-python-ffi, typing-extensions, yarl |
| Maintenance | actively maintained — 102 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,600,435/month — #3,728 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pact_python-3.4.0-py3-none-any.whl
Keywords: contract-testing, pact, testing
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pact-python-ffiProvides direct Python bindings to the Pact FFI…
permissive · top 5,000 on PyPI
dealDeal is a Python library for design by contract…
permissive · top 15,000 on PyPI
icontracticontract enforces design-by-contract in Python…
permissive · top 15,000 on PyPI
eth-testereth-tester provides an in-memory Ethereum…
permissive · top 15,000 on PyPI
mockitoMockito is a spying and stubbing framework for…
permissive · top 5,000 on PyPI
grpcio-testingProvides testing utilities and fixtures for…
permissive · top 15,000 on PyPI
eth-brownieBrownie is a Python framework for developing,…
permissive · top 15,000 on PyPI
zope.interfaceProvides a Python implementation of object…
unclear · top 1,000 on PyPI
crosshair-toolCrossHair uses symbolic execution and SMT…
permissive · top 15,000 on PyPI
alchemy-mockProvides mock helpers for SQLAlchemy sessions…
permissive · top 15,000 on PyPI