Skip to main content

Accord

Accord is a Python library for consumer-driven contract testing between web services, you define a Contract once using Pydantic models and an @endpoint decorator, which then automatically takes care of the rest for you:

  • Spins up a mock http-server using werkzeug
  • Generates a pact compatible JSON contract file

This ensures both sides of a service boundary stay in sync without requiring a shared test environment.

Why not Pact?

Pact is definitely the industry-standard library, and if you are working with multiple different languages or environments then it is the better choice. But if your stack is Python-only, Pact comes with a lot of overhead; that you may not need:

  • A separate DSL
    • Pact has its own way of defining contracts that lives outside your existing code. Accord uses the Pydantic models you're already writing.
  • The broker
    • Pact strongly encourages (and in practice, requires) a Pact broker to share contracts between teams. Accord generates a JSON file and you share it however you want: a shared repo, a CI artifact, or S3.
  • Usage time
    • Getting Pact fully set up across two services takes time. Accord is designed to be useful in an afternoon.

Accord is not supposed to replace Pact, it is for simplicity and less overhead. In reality, Pact is more useful across the board.

Learn how to use Accord

Before you learn how to use Accord, here are some simple diagrams that showcase how our Contracts & Systems work.

Contracts

Contract Flow

Consumer Flow

Consumer Flow

Producer Verification

Producer Verification Flow

Now with all of those flows out of the way, the example may make more sense that we provide here.

A basic contract is defined as such:

from pydantic import BaseModel
from core.contract import Contract, endpoint

class UserResponse(BaseModel):
    id: int
    name: str

class GetUserContract(Contract):
    consumer = "order-service"
    producer = "user-service"

    @endpoint(http_method="GET", path="/users/{id}")
    def get_user(self, user_id: int) -> UserResponse: ...

Once we have this contract defined, we use it to spin up a MockServer to test the Consumer:

import httpx
from server.mock import MockServer

with MockServer(GetUserContract) as server:
    server.given("get_user").example(UserResponse(id=1, name="Alice"))

    response = httpx.get("http://127.0.0.1:5000/users/1")
    assert response.status_code == 200
    assert response.json()["name"] == "Alice"

This writes the contract to ./accords/ once the ContextManager exits. The other side of the testing flow is producer, which you can do as such:

from pathlib import Path
from verification.verifier import ContractVerifier

# This assumes your server is running on 8080

verifier = ContractVerifier(
    contract_path=Path("accords/order-service-user-service.json"),
    base_url="http://127.0.0.1:8080",
)
verifier.verify()

Metadata

Release files for accord-contracts 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for accord-contracts 0.1.1
File Size Uploaded Provenance Actions
accord_contracts-0.1.1.tar.gz 7.5 kB Without provenance Details for accord_contracts-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for accord-contracts 0.1.1
File Interpreter ABI Platform Actions
accord_contracts-0.1.1-py3-none-any.whl Python 3 none any Details for accord_contracts-0.1.1-py3-none-any.whl

Total release size: 16.8 kB

Release files / accord_contracts-0.1.1.tar.gz

Download URL accord_contracts-0.1.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c2cb81143cc883474ce5985dceee99a16ef603b030951d8fd3f88e6a55474495
BLAKE2b-256 checksum
How to use checksums
9ca178a21181a42b986421bae43a66d04c919c654c1e2e1071bc3233e40c7145
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / accord_contracts-0.1.1-py3-none-any.whl

Download URL accord_contracts-0.1.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
393bb3823ff4cf194ab5c413e1ae44c395e95047ebbef2cbcbcdea1e11d6767e
BLAKE2b-256 checksum
How to use checksums
d73cfcd346b38f056852f75f5e14851713433a9d2e8fde3ca67fe853686a694b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for accord-contracts 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page