Skip to main content

FastAPI mock middleware

license pypi test codecov

FastAPI middleware for mocking response data of non-implemented endpoints.

Mock data is generated in accordance with endpoint return type or provided response_model using polifactory.


For more information on how to use fastapi-mock-middleware, please refer to the official documentation.

Installation

pip install fastapi-mock-middleware

Usage example

Add MockAPIMiddleware middleware to app and raise APINotImplementedError in your endpoint stubs.

import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel

from fastapi_mock_middleware import MockAPIMiddleware, APINotImplementedError

app = FastAPI()
app.add_middleware(MockAPIMiddleware)


class Item(BaseModel):
    id: int
    name: str


@app.get('/')
async def list_items() -> list[Item]:
    raise APINotImplementedError()


if __name__ == '__main__':
    uvicorn.run('example:app', reload=True)

Check the response using curl.

curl http://127.0.0.1:8000/

Called API must return mocked data:

[
  {
    "id": 5392,
    "name": "gVzyVVUmGGevXlQvXGBW"
  }
]

Release files for fastapi-mock-middleware 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 fastapi-mock-middleware 0.1.1
File Size Uploaded
fastapi_mock_middleware-0.1.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-mock-middleware 0.1.1
File Interpreter ABI Platform
fastapi_mock_middleware-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / fastapi_mock_middleware-0.1.1.tar.gz

Download URL fastapi_mock_middleware-0.1.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d2a6ccc07a5a8c89891be3bb2542f57de62fb7312da8bf6093bac634ac7a521d
BLAKE2b-256 checksum
How to use checksums
b6c69beaabff0c87aa69639039e57b89be80f15fbdd98e560f136319b8039c3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

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

Download URL fastapi_mock_middleware-0.1.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49534fd91a7f3cc24a0a8352bb09ea505e7465b6227dfdd499dcd77e3c4cadd6
BLAKE2b-256 checksum
How to use checksums
64a21ab423724066e13fb5048762c56125adf5adc8d9f90b8d5635aaec8237c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

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