flask-fastapi


Nameflask-fastapi JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryExtended version of Flask to offer FastAPI inspired functionality.
upload_time2024-08-17 11:49:13
maintainerNone
docs_urlNone
authorMatt Wilson
requires_python<4.0,>=3.11
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Flast-FastAPI

Extended version of Flask to offer FastAPI inspired functionality. I wanted a
way to offer similar functionality but run under AWS Lambda (and othre
non-async environments).

Flask-FastAPI uses python type hints extensively to understand request and
response data, and not including them will cause problems. Some examples below.

Pydantic is used extensively.

## This is unfinished software

This software was extracted from another project that I built and retired. This
portion of the software was of some use and so I thought I would rip it out and
give it to the world for free. It is:

- messy
- buggy
- incomplete
- poorly documented
- imperfect
- amazing
- working for me
- a complete strange to automated testing

As I find time to improve the quality of this code, the documentation, and the
test coverage I will aim to improve things a little. In the meantime please
consider adding in your own fixes, tests, etc.

## Decorators for common API methods

For each of the main HTTP requests there is an appropriate decorator. These
decorators share some common parameters:

### Route parameters

- tags - array used in OpenAPI to categorise endpoint
- summary - string used in OpenAPI to describe endpoint
- response_code - used to override default response codes for each HTTP method,
- requires_auth - boolean, whether this endpoint requires authentication, defaults to true
- private - boolean, if set to true will not include endpoint in public documentation, defaults to false

### Function

- Python function __doc__ - used as description in OpenAPI
- A parameter called "body" will be considered as the POST request, and type hints determine how it's parsed
- Parameter type hints will be used to coerce query parameters
- A parameter which defaults to a Pydantic Field type will take further validation and details (such as description) from the information provided (more below)
- Function response type hint will be used to determine response schema

### Default response codes

Response code can be specified using the `response_code` route parameter, or the default will be used.

- GET returns 200
- POST returns 201
- PUT returns 202
- PATCH returns 202
- DELETE returns 204, without content

## Examples

### GET

```
@api.get('/path/to/<id>', summary="Endpoint summary", tags=["tags","about","endpoint"])
def get_resource(
        id: int = Field(..., description="Unique identifier")
    ) -> ResponseSchema:

    ''' This documentation will be included to describe the endpoint.
    '''
    # this would return a Pydantic ResponseSchema in a real world example
    return ResponseSchema(...)
```

### POST, PUT, and PATCH

```
@api.post('/path/to/entity', summary="...")
def post_resource(body: RequestSchema) -> ResponseSchema:
    ''' Request schema is automatically picked up from the name of the parameter.
    '''
    # this would return a Pydantic ResponseSchema in a real world example
    return ResponseSchema(...)
```

### DELETE

```
@api.delete('/path/to/<id>', summary="Endpoint summary", tags=["tags","about","endpoint"])
def get_resource(
        id: int = Field(..., description="Unique identifier")
    ):

    ''' No return type hint is needed here, as delete does not return content by default
    '''
    pass
```

## Exceptions

The exceptions defined in flask_fastapi.exceptions handle the most common cases
encountered, but extension of exceptions.HttpException is trivial and can be
used to manage different non-OK responses.

## Automatic OpenAPI documentation

An openapi.json file will be generated from the routes that are created and can
be downloaded by visiting the /openapi.json endpoint. There will also be an
/openapi.yaml file available for anybody who wants it.

## Documentation serving

Through automated generation of the OpenAPI documentation you also have serving
of documentation through either Redoc of SwaggerUI, both of which have
templates bundled with this package.

### Redoc

Can be seen by navigating to $base_url/redoc/, e.g. http://localhost:5000/redoc/.

Github repo for redoc- https://github.com/Redocly/redoc

### SwaggerUI

Can be seen by navigating to $base_url/docs/, e.g. http://localhost:5000/docs/.

Website for SwaggerUI - https://swagger.io/tools/swagger-ui/

# To document

- Security

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-fastapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Matt Wilson",
    "author_email": "matt@callmematt.com",
    "download_url": "https://files.pythonhosted.org/packages/79/b7/0984c4822d484d9171fc73137848c9f4b872010ae599137397457957e736/flask_fastapi-0.0.2.tar.gz",
    "platform": null,
    "description": "# Flast-FastAPI\n\nExtended version of Flask to offer FastAPI inspired functionality. I wanted a\nway to offer similar functionality but run under AWS Lambda (and othre\nnon-async environments).\n\nFlask-FastAPI uses python type hints extensively to understand request and\nresponse data, and not including them will cause problems. Some examples below.\n\nPydantic is used extensively.\n\n## This is unfinished software\n\nThis software was extracted from another project that I built and retired. This\nportion of the software was of some use and so I thought I would rip it out and\ngive it to the world for free. It is:\n\n- messy\n- buggy\n- incomplete\n- poorly documented\n- imperfect\n- amazing\n- working for me\n- a complete strange to automated testing\n\nAs I find time to improve the quality of this code, the documentation, and the\ntest coverage I will aim to improve things a little. In the meantime please\nconsider adding in your own fixes, tests, etc.\n\n## Decorators for common API methods\n\nFor each of the main HTTP requests there is an appropriate decorator. These\ndecorators share some common parameters:\n\n### Route parameters\n\n- tags - array used in OpenAPI to categorise endpoint\n- summary - string used in OpenAPI to describe endpoint\n- response_code - used to override default response codes for each HTTP method,\n- requires_auth - boolean, whether this endpoint requires authentication, defaults to true\n- private - boolean, if set to true will not include endpoint in public documentation, defaults to false\n\n### Function\n\n- Python function __doc__ - used as description in OpenAPI\n- A parameter called \"body\" will be considered as the POST request, and type hints determine how it's parsed\n- Parameter type hints will be used to coerce query parameters\n- A parameter which defaults to a Pydantic Field type will take further validation and details (such as description) from the information provided (more below)\n- Function response type hint will be used to determine response schema\n\n### Default response codes\n\nResponse code can be specified using the `response_code` route parameter, or the default will be used.\n\n- GET returns 200\n- POST returns 201\n- PUT returns 202\n- PATCH returns 202\n- DELETE returns 204, without content\n\n## Examples\n\n### GET\n\n```\n@api.get('/path/to/<id>', summary=\"Endpoint summary\", tags=[\"tags\",\"about\",\"endpoint\"])\ndef get_resource(\n        id: int = Field(..., description=\"Unique identifier\")\n    ) -> ResponseSchema:\n\n    ''' This documentation will be included to describe the endpoint.\n    '''\n    # this would return a Pydantic ResponseSchema in a real world example\n    return ResponseSchema(...)\n```\n\n### POST, PUT, and PATCH\n\n```\n@api.post('/path/to/entity', summary=\"...\")\ndef post_resource(body: RequestSchema) -> ResponseSchema:\n    ''' Request schema is automatically picked up from the name of the parameter.\n    '''\n    # this would return a Pydantic ResponseSchema in a real world example\n    return ResponseSchema(...)\n```\n\n### DELETE\n\n```\n@api.delete('/path/to/<id>', summary=\"Endpoint summary\", tags=[\"tags\",\"about\",\"endpoint\"])\ndef get_resource(\n        id: int = Field(..., description=\"Unique identifier\")\n    ):\n\n    ''' No return type hint is needed here, as delete does not return content by default\n    '''\n    pass\n```\n\n## Exceptions\n\nThe exceptions defined in flask_fastapi.exceptions handle the most common cases\nencountered, but extension of exceptions.HttpException is trivial and can be\nused to manage different non-OK responses.\n\n## Automatic OpenAPI documentation\n\nAn openapi.json file will be generated from the routes that are created and can\nbe downloaded by visiting the /openapi.json endpoint. There will also be an\n/openapi.yaml file available for anybody who wants it.\n\n## Documentation serving\n\nThrough automated generation of the OpenAPI documentation you also have serving\nof documentation through either Redoc of SwaggerUI, both of which have\ntemplates bundled with this package.\n\n### Redoc\n\nCan be seen by navigating to $base_url/redoc/, e.g. http://localhost:5000/redoc/.\n\nGithub repo for redoc- https://github.com/Redocly/redoc\n\n### SwaggerUI\n\nCan be seen by navigating to $base_url/docs/, e.g. http://localhost:5000/docs/.\n\nWebsite for SwaggerUI - https://swagger.io/tools/swagger-ui/\n\n# To document\n\n- Security\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Extended version of Flask to offer FastAPI inspired functionality.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86bde0ab528ea7869c3d815a2f74df9b7c07da3ee9aaad50094a1433df3d31fa",
                "md5": "5d4ca89573e5d4211c78da46eeedcfa5",
                "sha256": "30cd64a2a2768dde64d2d7a372c8fc21c47a4052d77a97922c11a3fbb27d7ca3"
            },
            "downloads": -1,
            "filename": "flask_fastapi-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5d4ca89573e5d4211c78da46eeedcfa5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 12526,
            "upload_time": "2024-08-17T11:49:11",
            "upload_time_iso_8601": "2024-08-17T11:49:11.805641Z",
            "url": "https://files.pythonhosted.org/packages/86/bd/e0ab528ea7869c3d815a2f74df9b7c07da3ee9aaad50094a1433df3d31fa/flask_fastapi-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79b70984c4822d484d9171fc73137848c9f4b872010ae599137397457957e736",
                "md5": "cf7878cef3062bb46c1c31131b4878f5",
                "sha256": "d3c9745b04d95006b6ec426a472214cfd0fdd6a3dee55872420175985b76a59e"
            },
            "downloads": -1,
            "filename": "flask_fastapi-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cf7878cef3062bb46c1c31131b4878f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 11233,
            "upload_time": "2024-08-17T11:49:13",
            "upload_time_iso_8601": "2024-08-17T11:49:13.415677Z",
            "url": "https://files.pythonhosted.org/packages/79/b7/0984c4822d484d9171fc73137848c9f4b872010ae599137397457957e736/flask_fastapi-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-17 11:49:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "flask-fastapi"
}
        
Elapsed time: 0.38485s