Automatically generate versioned API snapshots on every merge. Explore changes between any two versions in a UI with color-coded diff highlighting. Built for FastAPI + TypeScript teams.
https://pypi.org/project/openapi-lens/
- Every time code merges to
main, a GitHub Actions workflow imports your FastAPI app, generates its OpenAPI spec, and compares it to the previous snapshot. If anything changed, it commits a new snapshot file to your repo underopenapi-snapshots/. Theopenapi-snapshots/folder is created automatically by the workflow on first run. - On every pull request, a second workflow computes the diff between the PR branch and the latest snapshot, and posts a comment summarizing what changed (comment can be disabled).
- Install the PyPi package (openapi-lens), then locally run
apilens serveto browse and compare any two snapshots in a visual UI. Optionally, add a few lines to deploy the viewer alongside your app.
- Automatic snapshots — captures your spec on every merge to
main; skips if nothing changed - Visual diff viewer — color-coded UI showing new, removed, and modified endpoints with field-level detail
- PR comments — posts a Markdown summary of API changes on every pull request
- AI prompts — one-click copy of prompts to help update frontend TypeScript types
- Zero integration — no changes to your FastAPI app; runs completely standalone
Python 3.10 or higher. Check yours with:
python3 --versionpip3 install "openapi-lens[serve]"Grab [apilens.toml](apilens.toml) from this repo and place it at the root of your project. Edit one line:
[apilens]
app = "myapp.main:app" # ← change this to your FastAPI app's import pathGrab both files from [workflow-templates/](workflow-templates/):
**openapi-snapshot.yml**— on every push tomain, generates your spec and commits a new snapshot toopenapi-snapshots/if anything changed**api-diff.yml**— on every PR, posts a comment showing exactly what endpoints and fields changed
Set your app path: both workflow files have an
APP_PATHenv var near the top of the job. Set it to the directory containing your FastAPI app'ssetup.pyorpyproject.tomlbefore committing:env: APP_PATH: ./backend # ← change to your FastAPI app's directoryThis is the only line you need to change in each workflow file.
Commit and push the three files (apilens.toml, openapi-snapshot.yml, api-diff.yml). From this point:
- On the next merge to
main— the snapshot workflow fires automatically. It imports your app, generates the spec, and commits the firstopenapi-snapshots/<timestamp>.jsonfile to your repo. You can watch it run in your repo's Actions tab. - On every subsequent PR — the diff workflow fires automatically and posts a comment to the PR showing what changed.
You don't need to do anything else to keep snapshots running, it's fully automatic from here.
Once at least two snapshots exist in your repo, pull the latest changes and choose one of the two options below.
Note: the dropdowns will be empty until at least one snapshot exists. You need at least two snapshots to compare — meaning two separate merges to
mainthat each changed the API.
Run from your project root:
apilens serveThis starts the viewer at http://127.0.0.1:8765, visible only on your machine. ApiLens reads the snapshots_dir from your apilens.toml automatically.
If you want the viewer deployed alongside your app so your whole team can access it, add these lines to your main.py:
import os
from apilens.viewer.app import mount
mount(app, path="/apilens", password=os.environ.get("APILENS_PASSWORD"))Then set APILENS_PASSWORD in your server's environment variables. The viewer will be available at yourapp.com/apilens and anyone visiting it will be prompted for the password.
If you want to disable the PR comments, set pr_comments = false in your apilens.toml:
[apilens]
pr_comments = falseMIT