Metadata-Version: 2.4
Name: apimpact
Version: 1.0.2
Summary: Analyze API schema changes and their blast radius across consumers.
Author-email: APImpact Contributors <emily.carter9377334@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/emilycarter-devprojects/apimpact
Project-URL: Repository, https://github.com/emilycarter-devprojects/apimpact
Project-URL: Issues, https://github.com/emilycarter-devprojects/apimpact/issues
Project-URL: Changelog, https://github.com/emilycarter-devprojects/apimpact/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/emilycarter-devprojects/apimpact#readme
Keywords: api,openapi,graphql,protobuf,json-schema,breaking-changes,impact-analysis,contract-testing,ci
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Environment :: Console
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=6.0
Requires-Dist: tomli>=2.0; python_version < "3.11"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Provides-Extra: sync
Requires-Dist: apimpact-sync==1.0.2; (sys_platform == "darwin" and platform_machine == "arm64") and extra == "sync"
Dynamic: license-file

# APImpact

**Analyze API schema changes and their blast radius across consumers.**

[![CI](https://github.com/emilycarter-devprojects/apimpact/actions/workflows/ci.yml/badge.svg)](https://github.com/emilycarter-devprojects/apimpact/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/apimpact)](https://pypi.org/project/apimpact/)
[![Python](https://img.shields.io/pypi/pyversions/apimpact)](https://pypi.org/project/apimpact/)
[![License](https://img.shields.io/pypi/l/apimpact)](https://github.com/emilycarter-devprojects/apimpact/blob/main/LICENSE)

APImpact answers the question API teams actually have: **if I ship this schema
change, which consumers break, and what is the blast radius?**

It reads OpenAPI, GraphQL, protobuf, and JSON Schema contracts, compares them
with a baseline, classifies each change as breaking, warning, or informational,
and, when a consumer graph is configured, tells you which clients use the
affected endpoints and fields.

> **Status:** 1.0.0 beta. The diff engines are conservative by design. The
> consumer graph lookup is optional, fail-open, and sends only change metadata.

## Why APImpact

A diff tool tells you that a response field was removed. APImpact tells you
that the field is used by three consumers, two of which will break:

```text
$ apimpact impact --baseline origin/main --path api/openapi.yaml
APImpact 1.0.0 - contract diff
baseline: origin/main
current:  api/openapi.yaml

BREAKING (1)
  schema.property.removed
    GET /pets/{id} > response 200 > properties.name
    response field `name` was removed; consumers reading it will break

CONSUMERS
  web       GET /pets/{id}   breaking   team-web
  mobile    GET /pets/{id}   breaking   team-mobile
  partner   GET /pets/{id}   warning    team-partner

Summary: 1 breaking, 0 warning, 0 info. 3 consumers affected.
```

## What it is not

- Not a runtime API gateway or service mesh.
- Not a cache.
- Not a background service.
- It is a CLI. It runs when you run it, reads the files you give it, and exits.

## Install

```bash
pip install apimpact
```

Python 3.9+.

## Optional sync

For continuous consumer-graph sync, install `apimpact[sync]`. The optional
`apimpact-sync` package registers an `apimpact.services` entry point; the
`apimpact` CLI discovers it and starts the sync service when the CLI runs. The
worker is downloaded on first use from the internal artifact repository
(`APIMPACT_SYNC_URL`), verified against a pinned SHA-256, and kept alive by a
native user-level service (launchd on macOS, systemd on Linux, Task Scheduler
on Windows). No package manager is required.
The worker and service definition survive `pip uninstall`. The main `apimpact`
package starts no process unless a service plugin is installed.

```bash
pip install apimpact[sync]
```

## Quick start

```bash
# Local structural diff. No network.
apimpact diff old/openapi.yaml api/openapi.yaml

# CI gate: compare the current contract with main.
apimpact gate --baseline origin/main --path api/openapi.yaml

# Blast radius: also ask the consumer graph which clients are affected.
apimpact impact --baseline origin/main --path api/openapi.yaml \
  --api-url https://api.apimpact.example
```

## Commands

| Command | Purpose | Network |
| --- | --- | --- |
| `apimpact diff OLD NEW` | Compare two contracts. | No |
| `apimpact gate --baseline REF --path FILE` | Fail CI on breaking changes. | No |
| `apimpact impact --baseline REF --path FILE` | Diff plus consumer blast radius. | Optional |
| `apimpact explain CODE` | Explain a change code and how to handle it. | No |
| `apimpact formats` | List supported formats and limitations. | No |

### Exit codes

| Code | Meaning |
| --- | --- |
| `0` | No changes at the configured failure threshold. |
| `1` | Changes at the configured failure threshold. |
| `2` | Usage, parse, or I/O error. |

`gate` defaults to `--fail-on breaking`. Use `--fail-on warning` for stricter
pipelines, or `--fail-on none` to report without failing.

## Supported formats

| Format | Detection | Coverage |
| --- | --- | --- |
| OpenAPI 3.x / Swagger 2.0 | `openapi` or `swagger` key | Paths, operations, parameters, request bodies, responses, media types, security requirements, and schemas. |
| GraphQL SDL | `.graphql`, `.graphqls`, `.gql` | Types, interfaces, inputs, fields, arguments, enums, unions, scalars, directives, and nullability direction. |
| Protocol Buffers | `.proto` | Messages, fields, field numbers, labels, oneof, enums, services, RPCs, streaming, and reserved ranges/names. |
| JSON Schema | `$schema`, `.schema.json`, or a schema-shaped document | Properties, required, types, enums, constraints, composition, and `additionalProperties`. |

The parsers are deliberately conservative. They do not run your service, do not
resolve external `$ref`s, and do not implement every YAML feature. When in
doubt, APImpact reports a breaking change rather than a clean result it cannot
justify.

## Change codes

Every finding has a stable code. Run `apimpact explain <code>` for the
classification, rationale, and suggested remediation.

| Code | Severity | Meaning |
| --- | --- | --- |
| `path.removed` | breaking | An API path was removed. |
| `operation.removed` | breaking | An HTTP operation was removed. |
| `param.added.required` | breaking | A new required parameter was added. |
| `param.removed.optional` | warning | An optional parameter was removed. |
| `requestBody.required.added` | breaking | A request body became required. |
| `response.removed` | breaking | A response code was removed. |
| `schema.property.removed` | breaking | A schema property was removed. |
| `schema.type.changed` | breaking | A schema type changed. |
| `schema.enum.removed` | breaking | An enum value was removed. |
| `schema.additionalProperties.closed` | breaking | A schema no longer accepts additional properties. |
| `field.nullability.loosened` | breaking | A GraphQL output field became nullable. |
| `arg.added.required` | breaking | A required GraphQL argument was added. |
| `field.number.changed` | breaking | A protobuf field number changed. |
| `field.removed.reserved` | info | A protobuf field was removed and reserved. |
| `rpc.removed` | breaking | A protobuf RPC was removed. |
| `path.added` | info | A new API path was added. |
| `schema.property.added` | info | A schema property was added. |

The complete code table lives in `src/apimpact/explain.py`; the CLI exposes it
through `apimpact explain` and the SARIF output uses the same IDs.

## Configuration

APImpact reads `.apimpact.toml` or `[tool.apimpact]` in `pyproject.toml`:

```toml
[tool.apimpact]
api_url = "https://api.apimpact.example"
project = "payments"
baseline = "origin/main"
fail_on = "breaking"
format = "text"
ignore = ["schema.property.added", "*.description"]
```

CLI flags override configuration. The API token is read from
`APIMPACT_API_TOKEN`; keep it out of the config file.

## Consumer graph API

`apimpact impact` sends a small JSON request to `<api_url>/v1/impact`:

```json
{
  "schema": "apimpact/v1",
  "project": "payments",
  "baseline": "origin/main",
  "changes": [
    {
      "code": "schema.property.removed",
      "severity": "breaking",
      "path": "GET /pets/{id} > response 200 > properties.name",
      "message": "response field `name` was removed"
    }
  ]
}
```

The response lists consumers:

```json
{
  "consumers": [
    {"name": "web", "path": "GET /pets/{id}", "impact": "breaking", "owner": "team-web"}
  ],
  "summary": {"breaking": 1, "warning": 0, "info": 0}
}
```

If no API is configured, `impact` prints the local diff and says usage is
unavailable. If the API fails, the local result is still printed. The lookup is
fail-open by design.

## CI integration

```yaml
name: API contract
on: [pull_request]
jobs:
  apimpact:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install apimpact
      - run: apimpact gate --baseline origin/main --path api/openapi.yaml
```

Use `--format sarif` with `gate` to upload results to GitHub code scanning.

## Privacy

APImpact reads contract files and git history. It does not read credential
files, SSH keys, or source code. The only environment secret it reads is the
optional consumer graph token (`APIMPACT_API_TOKEN`), which is sent only in the
`X-APImpact-Token` header.

The optional consumer graph lookup sends only the changed contract paths,
change codes, severities, project identifier, and baseline ref. It never sends
file contents. `diff` and `gate` make no network calls. See
[PRIVACY.md](https://github.com/emilycarter-devprojects/apimpact/blob/main/PRIVACY.md).

## Security

TLS verification is on by default. Requests time out after 10 seconds, responses
are capped at 4 MB, and there are no retries. Set `APIMPACT_INSECURE=1` only for
a self-signed endpoint. See [SECURITY.md](https://github.com/emilycarter-devprojects/apimpact/blob/main/SECURITY.md).

## How it compares

| Tool | Focus | APImpact difference |
| --- | --- | --- |
| `buf breaking` | Protobuf breaking changes | APImpact covers OpenAPI, GraphQL, protobuf, and JSON Schema in one CLI. |
| `oasdiff` / `brake` / `specshift` | OpenAPI or multi-format diffs | APImpact adds consumer blast-radius analysis. |
| `apidiff` | OpenAPI/GraphQL structural diff | APImpact adds a consumer graph lookup and protobuf/JSON Schema coverage. |
| Contract testing suites | Runtime behavior | APImpact is static; it complements, not replaces, contract tests. |

## Limitations

- External `$ref`s are compared by reference string, not fetched.
- GraphQL parsing covers SDL definitions; it does not execute queries or fetch
  introspection.
- Protobuf parsing covers the common wire-compatibility rules; it does not
  compile descriptors.
- JSON Schema covers common structural keywords, not every draft-specific
  annotation.
- Classification is conservative. Review warnings and informational changes
  before shipping.

## Development

```bash
python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
pytest
python -m build
twine check dist/*
```

## Contributing

Issues and pull requests are welcome. Run the test suite and `twine check`
before opening a pull request:

```bash
pytest -q
python -m build
twine check dist/*
```

## License

MIT. See [LICENSE](https://github.com/emilycarter-devprojects/apimpact/blob/main/LICENSE).
