Azure Functions Extensions Http FastApi library for Python
This library contains HttpV2 extensions for FastApi Request/Response types to use in your function app code.
Source code
| Package (PyPi)
| API reference documentation
| Product documentation
| Samples
Getting started
Prerequisites
Instructions
- Follow the guide to create an app.
- Ensure your app is using programming model v2 and contains a http trigger function.
- Add
azurefunctions-extensions-http-fastapi
to your requirements.txt - Import Request and different types of responses from
azurefunctions.extensions.http.fastapi
in your HttpTrigger functions. - Change the request and response types to ones imported from
azurefunctions.extensions.http.fastapi
. - Run your function app and try it out!
Bind to the FastApi-type
The Azure Functions Extensions Http FastApi library for Python allows you to create a function app with FastApi Request or Response types. When your function runs, you will receive the request of FastApi Request type and you can return a FastApi response type instance. FastApi is one of top popular python web framework which provides elegant and powerful request/response types and functionalities to users. With this integration, you are empowered to use request/response the same way as using them in native FastApi. A good example is you can do http streaming upload and streaming download now! Feel free to check out Fastapi doc for further reference.
import azure.functions as func
from azurefunctions.extensions.http.fastapi import Request, JSONResponse
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="streaming_upload", methods=[func.HttpMethod.POST])
async def streaming_upload(req: Request) -> JSONResponse:
"""Handle streaming upload requests."""
async for chunk in req.stream():
process_data_chunk(chunk)
return JSONResponse({"status": "Data uploaded and processed successfully"})
def process_data_chunk(chunk: bytes):
"""Process each data chunk."""
pass
Next steps
More sample code
Get started with our FastApi samples.
Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with FastApi:
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.