Skip to content

Pacto for Developers

You own the service, so you own its contract. This guide shows how to write one next to your code: a pacto.yaml file that says what your service exposes, what it needs and how it behaves. Platform engineers, CI and other teams then read the same file instead of asking you.

New to Pacto? Start with the five-minute Quickstart. The CLI reference lists every command and contract sections lists every field.


Your workflow

flowchart LR
    A[Write code] --> B[Infer schemas]
    B --> C[Define pacto.yaml]
    C --> D[pacto validate]
    D --> F[pacto ci]
    F --> G[CI / Platform picks it up]

1. Initialize your contract

pacto init my-service

This creates a my-service/ directory (a bundle) with a valid starter contract. Edit pacto.yaml to match your service.

2. Infer schemas from your code (optional)

If your config already ships a JSON Schema, such as your Helm chart's values.schema.json, vendor that file into your bundle and point configurations[].schema at it. Otherwise the schema-infer plugin generates one from a config file.

Generating a configuration schema

Pacto resolves the --option file= path relative to the bundle directory, so keep the config file inside the bundle. With config.yaml in my-service/:

pacto generate schema-infer my-service --option file=config.yaml -o my-service

This generates my-service/config.schema.json. Reference it in your contract:

configurations:
  - name: default
    required: true
    schema: config.schema.json

Secret leak trap

The plugin leaves your config.yaml sitting in the bundle, and a bundle directory is published whole. pacto pack and pacto push upload every file under it, so pacto pull hands your config values, secrets included, to anyone who can read the artifact. The contract needs only the inferred schema. Delete the input once the schema exists, or list it in .pactoignore if you want to keep it beside the contract.

Generating an OpenAPI spec

If your service exposes an HTTP API using FastAPI or Huma, use the openapi-infer plugin to extract an OpenAPI 3.1 spec from your source code:

# Auto-detect the framework: FastAPI or Huma (generates interfaces/openapi.yaml)
pacto generate openapi-infer my-service -o my-service

# Override framework detection
pacto generate openapi-infer my-service -o my-service --option framework=fastapi

Both plugins need the pacto.yaml that step 1 wrote. The starter contract already points its api interface at interfaces/openapi.yaml. A contract that pacto init read from a Dockerfile and manifests has an interface only when it found an OpenAPI file, so add the interfaces entry yourself.

Both plugins live in a separate repository and ship as separate binaries. The installer script fetches them alongside the CLI; go install and make build build only pacto. See Official plugins for how to get them.

3. Define the contract

See Contract sections for interfaces, workload, state and capabilities; Dependencies and state for dependencies; and Configuration and policy for configurations and policies.

4. Validate and publish

pacto ci              # on a pull request: validate and plan every service
pacto ci --publish    # on the merged commit: publish every changed service

See Validation layers for the rules and error codes. In CI, pacto ci init writes the one step that runs both; see Put it in your repository. A published version is signed and never overwritten.

On Kubernetes, the operator checks what your service does on the network against this contract. See runtime conformance.


Offerings and infrastructure

Your platform team may publish contracts for the infrastructure it offers, such as a PostgreSQL database. Find them on the dashboard's Offerings page or with pacto fleet search --offering <slug>, pick a version with pacto fleet versions <slug>, then reference the contract from yours and write the values its schema lets you control. pacto validate checks those values against the provider's schema, and the Offerings page shows what the platform reports about your resource. See Provision infrastructure through contracts.


Golden paths

Your platform team may publish golden paths: contracts a new service starts from. List them with pacto fleet entities --template or on the dashboard's Golden paths page, then create your service with pacto init <dir> --from <path> --owner <team>. See Create a service from a golden path.


What's next