xxii · xi · mmxxvi

Projects

pact-python

Contract testing for Python services, built on a Rust FFI core

View on GitHub ↗
stars
688
forks
147
watchers
688
open issues
14
latest release
pact-python-ffi/0.5.13.0 · 20 Nov 2026
pull requests
4 open PRs

Recent commits

  • 38d21b0chore(deps): update prek hooksJP-Ellis · 2d ago
  • 96de4bdchore: remove VS Code configurationJP-Ellis · 2d ago
  • 08a0807chore: replace markdownlint-cli2 with rumdlJP-Ellis · 2d ago
  • 3edd79bdocs: use the emphasis-style rule name in disable commentsJP-Ellis · 2d ago
  • 46fe5c3chore(release): diff pact.h and bump doc links in FFI release PRsJP-Ellis · 2d ago

Pact is a contract testing framework. The consumer records the requests it makes and the responses it expects in a pact file. The provider then replays that file against itself and checks each response. Neither test needs the other service running.

pact-python is the Python library in the Pact Foundation ecosystem. I rebuilt it from the ground up over a Rust FFI core (pact-reference), replacing the previous approach of shelling out to a Ruby binary. The result is a library that installs as a plain Python wheel with no system dependencies, supports the full Pact specification (V1–V4), and runs on all major platforms.

Usage

from pathlib import Path

from pact import Pact, match


def test_get_user() -> None:
    pact = Pact("user-consumer", "user-provider")
    (
        pact
        .upon_receiving("a request for user 1")
        .given("user 1 exists")
        .with_request("GET", "/users/1")
        .will_respond_with(200)
        .with_body(
            {"id": match.int(1), "name": match.str("Alice")},
            content_type="application/json",
        )
    )

    with pact.serve() as srv:
        client = UserClient(str(srv.url))  # your actual client code
        assert client.get_user(1).name == "Alice"

    pact.write_file(Path(__file__).parent / "pacts")

The library is published to PyPI.