Skip to main content

Bridgekeeper

Fail tests if API's do not have input or output models

Supports:

  • FastAPI
  • Flask

Usage

You can use Bridgekeeper to validate your API endpoints and ensure they have explicitly typed input and output models.

Basic Example

from fastapi import FastAPI
from bridgekeeper import check_models

app = FastAPI()

@app.get("/items/{item_id}")
def read_item(item_id: int) -> dict:
    return {"item_id": item_id}

# Run the checker against your initialized app
results = check_models(app)

# `results` will contain a list of endpoints missing type models
print(results)

Options

check_models(app, allow_list=None, check_only=None)

  • allow_list (list of strings, optional): A list of API paths to ignore (e.g., ["/health", "/metrics"]). If an endpoint matches a path in the list, it is skipped.
  • check_only (literal string, optional): If you only want to validate inputs or outputs exclusively, pass "request" or "response".
  • allow_any (boolean, optional): Defaults to False. When False, explicitly typing a parameter or return type as typing.Any is flagged as missing a strict model. Set to True if you want to allow Any as a valid type hint.
results = check_models(
    app, 
    allow_list=["/health"], 
    check_only="response",  # Will strictly look for missing return types
    allow_any=False         # typing.Any will be rejected
)

Handling Complex Apps (Databases/Secrets)

If your FastAPI or Flask app connects to a database (like Postgres) or external service (like Redis) during initialization, trying to run bridgekeeper in a GitHub Action might crash when the app imports, before the tests even run.

Bridgekeeper provides generic mocking utilities to safely bypass these side effects. For highly complex apps where you don't want to list out every single dependency, you can use auto_mock_missing=True to seamlessly mock any module that isn't installed!

from bridgekeeper import mock_modules, mock_env

# 1. Mock critical environment variables
mock_env({
    "DATABASE_URL": "sqlite:///:memory:",
    "SECRET_KEY": "dummy_secret_for_ci"
})

# 2. Automatically mock ANY missing dependency!
# This is extremely useful if you don't want to install heavy libraries (like SQLAlchemy, boto3, etc.)
# just to run a quick static analysis check.
mock_modules(auto_mock_missing=True)

# You can also explicitly mock specific modules with custom fakes:
# mock_modules({"app.core.db": PostgresTestDb}, auto_mock_missing=True)

# 3. Now it is safe to import the app
from myapp.main import app
from bridgekeeper import check_models

results = check_models(app)

Why the name bridgekeeper?

He guards the Bridge of Death and requires travelers to answer "questions three" before crossing safely.

Metadata

Release files for api-bridgekeeper 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 api-bridgekeeper 0.1.1
File Size Uploaded
api_bridgekeeper-0.1.1.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for api-bridgekeeper 0.1.1
File Interpreter ABI Platform
api_bridgekeeper-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / api_bridgekeeper-0.1.1.tar.gz

Download URL api_bridgekeeper-0.1.1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6dffec38776ab7c65f1e90f33c7d855c2605bfc7fa630d548b228ee53795b978
BLAKE2b-256 checksum
How to use checksums
7686949c418af8507fae7a115ad53c4bf050adfa9c9324a30b13d00856eeb908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

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

Download URL api_bridgekeeper-0.1.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea05027b620c3022b9028c314c422d2a6abc0cd3b9a07301c52cae702d432df9
BLAKE2b-256 checksum
How to use checksums
8bd16fed3640200608cce9c99a4844dda85166bfe59188819dad44f63a733d76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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