Skip to main content

Version, diff, and visualize your OpenAPI spec

Project description

ApiLens

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.

How It Works

  1. 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 under openapi-snapshots/.
  2. 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).
  3. Locally, run apilens serve to browse and compare any two snapshots in a visual UI.

The openapi-snapshots/ folder is created automatically by the workflow on first run.

Features

  • 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

Requirements

Python 3.10 or higher. Check yours with:

python3 --version

Setup

1. Install

pip3 install "openapi-lens[serve]"

2. Copy apilens.toml into your project root

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 path

This is the same path you'd pass to uvicorn — e.g. if you run uvicorn ocular.main:app, use "ocular.main:app". No secrets, safe to commit.

3. Copy the workflow files into your .github/workflows/

Grab both files from [workflow-templates/](workflow-templates/):

  • **openapi-snapshot.yml** — on every push to main, generates your spec and commits a new snapshot to openapi-snapshots/ if anything changed
  • **api-diff.yml** — on every PR, posts a comment showing exactly what endpoints and fields changed

Both use the built-in GITHUB_TOKEN — no secrets to configure.

4. Push to your repo

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 first openapi-snapshots/<timestamp>.json file 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.

5. Browse snapshots

Once at least two snapshots exist in your repo (after the first merge to main), 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 main that each changed the API.

Option A — Local only

Run from your project root:

apilens serve

This 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.

Option B — Mount inside your FastAPI app (recommended for teams)

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.

Disabling PR Comments

Set pr_comments = false in your apilens.toml:

[apilens]
pr_comments = false

Set it back to true to re-enable.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_lens-1.0.3.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_lens-1.0.3-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file openapi_lens-1.0.3.tar.gz.

File metadata

  • Download URL: openapi_lens-1.0.3.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openapi_lens-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b1718abe33e18e965ddcbfccb08bd4b092c38762bdd38ebeb72f166dd3f70832
MD5 e2443e02ea320b2986f82b7890feb70a
BLAKE2b-256 c79c750a20c602017c1cbe6ec91fca08bb32400b8465e164ad9acb39bb2dbbba

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_lens-1.0.3.tar.gz:

Publisher: publish.yml on MariaC27/api-lens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_lens-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: openapi_lens-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openapi_lens-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 402fe8cec5c16e32daf8136122deab701ecc3b2b8e0112128e2889e9cdb44f5b
MD5 bf624896cc1b93b8aa1830123302b3c7
BLAKE2b-256 b8eb4a19372e5972e89446edb42cdfef743f995b07b63646f133cf098b3d5bdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_lens-1.0.3-py3-none-any.whl:

Publisher: publish.yml on MariaC27/api-lens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page