fastapi-mock-middleware


Namefastapi-mock-middleware JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryFastAPI middleware for mocking response data of non-implemented endpoints
upload_time2024-07-09 19:42:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Niyaz Batyrshin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords fastapi mock mock api mock fastapi mock response api first
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI mock middleware

[![license](https://img.shields.io/badge/License-MIT-dark)](https://github.com/NiyazNz/fastapi-mock-middleware/blob/main/LICENSE.txt)
[![pypi](https://img.shields.io/pypi/v/fastapi-mock-middleware?color=00FF00)](https://pypi.org/project/fastapi-mock-middleware/)
[![test](https://github.com/NiyazNz/fastapi-mock-middleware/workflows/Test/badge.svg)](https://github.com/NiyazNz/fastapi-mock-middleware/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/NiyazNz/fastapi-mock-middleware/graph/badge.svg?token=GX8A8HD0KL)](https://codecov.io/gh/NiyazNz/fastapi-mock-middleware)

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](https://github.com/litestar-org/polyfactory).

---

For more information on how to use fastapi-mock-middleware, please refer to the
[official documentation](https://niyaznz.github.io/fastapi-mock-middleware/).

## Installation

```shell
pip install fastapi-mock-middleware
```

## Usage example

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

```Python hl_lines="8 18"
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`.

```shell
curl http://127.0.0.1:8000/
```

Called API must return mocked data:

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi-mock-middleware",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "fastapi, mock, mock API, mock fastapi, mock response, API first",
    "author": null,
    "author_email": "Niyaz Batyrshin <Niyaz.Batyrshin@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b6/c6/9beaabff0c87aa69639039e57b89be80f15fbdd98e560f136319b8039c3f/fastapi_mock_middleware-0.1.1.tar.gz",
    "platform": null,
    "description": "# FastAPI mock middleware\n\n[![license](https://img.shields.io/badge/License-MIT-dark)](https://github.com/NiyazNz/fastapi-mock-middleware/blob/main/LICENSE.txt)\n[![pypi](https://img.shields.io/pypi/v/fastapi-mock-middleware?color=00FF00)](https://pypi.org/project/fastapi-mock-middleware/)\n[![test](https://github.com/NiyazNz/fastapi-mock-middleware/workflows/Test/badge.svg)](https://github.com/NiyazNz/fastapi-mock-middleware/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/NiyazNz/fastapi-mock-middleware/graph/badge.svg?token=GX8A8HD0KL)](https://codecov.io/gh/NiyazNz/fastapi-mock-middleware)\n\nFastAPI middleware for mocking response data of non-implemented endpoints.\n\nMock data is generated in accordance with endpoint return type or provided\nresponse_model using [polifactory](https://github.com/litestar-org/polyfactory).\n\n---\n\nFor more information on how to use fastapi-mock-middleware, please refer to the\n[official documentation](https://niyaznz.github.io/fastapi-mock-middleware/).\n\n## Installation\n\n```shell\npip install fastapi-mock-middleware\n```\n\n## Usage example\n\nAdd `MockAPIMiddleware` middleware to app and raise `APINotImplementedError` in\nyour endpoint stubs.\n\n```Python hl_lines=\"8 18\"\nimport uvicorn\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\nfrom fastapi_mock_middleware import MockAPIMiddleware, APINotImplementedError\n\napp = FastAPI()\napp.add_middleware(MockAPIMiddleware)\n\n\nclass Item(BaseModel):\n    id: int\n    name: str\n\n\n@app.get('/')\nasync def list_items() -> list[Item]:\n    raise APINotImplementedError()\n\n\nif __name__ == '__main__':\n    uvicorn.run('example:app', reload=True)\n```\n\nCheck the response using `curl`.\n\n```shell\ncurl http://127.0.0.1:8000/\n```\n\nCalled API must return mocked data:\n\n```json\n[\n  {\n    \"id\": 5392,\n    \"name\": \"gVzyVVUmGGevXlQvXGBW\"\n  }\n]\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Niyaz Batyrshin  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "FastAPI middleware for mocking response data of non-implemented endpoints",
    "version": "0.1.1",
    "project_urls": {
        "homepage": "https://NiyazNz.github.io/fastapi-mock-middleware",
        "issues": "https://github.com/NiyazNz/fastapi-mock-middleware/issues",
        "repository": "https://github.com/NiyazNz/fastapi-mock-middleware.git"
    },
    "split_keywords": [
        "fastapi",
        " mock",
        " mock api",
        " mock fastapi",
        " mock response",
        " api first"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64a21ab423724066e13fb5048762c56125adf5adc8d9f90b8d5635aaec8237c1",
                "md5": "7cf8fd33e230f7937677693f3039a92d",
                "sha256": "49534fd91a7f3cc24a0a8352bb09ea505e7465b6227dfdd499dcd77e3c4cadd6"
            },
            "downloads": -1,
            "filename": "fastapi_mock_middleware-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7cf8fd33e230f7937677693f3039a92d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6339,
            "upload_time": "2024-07-09T19:42:48",
            "upload_time_iso_8601": "2024-07-09T19:42:48.580323Z",
            "url": "https://files.pythonhosted.org/packages/64/a2/1ab423724066e13fb5048762c56125adf5adc8d9f90b8d5635aaec8237c1/fastapi_mock_middleware-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6c69beaabff0c87aa69639039e57b89be80f15fbdd98e560f136319b8039c3f",
                "md5": "f4c106a5bbab9029a0abb09b930e3249",
                "sha256": "d2a6ccc07a5a8c89891be3bb2542f57de62fb7312da8bf6093bac634ac7a521d"
            },
            "downloads": -1,
            "filename": "fastapi_mock_middleware-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f4c106a5bbab9029a0abb09b930e3249",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11562,
            "upload_time": "2024-07-09T19:42:49",
            "upload_time_iso_8601": "2024-07-09T19:42:49.875291Z",
            "url": "https://files.pythonhosted.org/packages/b6/c6/9beaabff0c87aa69639039e57b89be80f15fbdd98e560f136319b8039c3f/fastapi_mock_middleware-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-09 19:42:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NiyazNz",
    "github_project": "fastapi-mock-middleware",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-mock-middleware"
}
        
Elapsed time: 4.78386s