FastApi Python worker extension for Azure Functions.
Project description
Azure Functions Extension 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) | Package (Conda) | API reference documentation | Product documentation | Samples
Getting started
Prerequisites
- Python 3.8 or later is required to use this package. For more details, please read our page on Python Functions version support policy.
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 requirement.txt
- Import Request and different types of responses from azure.functions.extensions.fastapi in your httptrigger functions.
- Change the request and response types to ones imported from azure.functions.extensions.fastapi.
- Run your function app and try it out!
Bind to the FastApi-type
The Azure Functions Extension 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 (https://fastapi.tiangolo.com/reference/responses/?h=custom)
# This Azure Function receives streaming data from a client and processes it in real-time.
# It demonstrates streaming upload capabilities for scenarios such as uploading large files,
# processing continuous data streams, or handling IoT device data.
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."""
# Process each chunk of data as it arrives
async for chunk in req.stream():
process_data_chunk(chunk)
# Once all data is received, return a JSON response indicating successful processing
return JSONResponse({"status": "Data uploaded and processed successfully"})
def process_data_chunk(chunk: bytes):
"""Process each data chunk."""
# Add custom processing logic here
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:
-
fastapi_samples_streaming_upload - An example on how to send and receiving a streaming request within your function.
-
fastapi_samples_streaming_download - An example on how to send your http response via streaming to the caller.t
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file azurefunctions-extensions-http-fastapi-1.0.0a1.tar.gz
.
File metadata
- Download URL: azurefunctions-extensions-http-fastapi-1.0.0a1.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a9bda00c32ab8c1bb19a1d9ab86d40bab7eebd60afd9386c9de355117ce539 |
|
MD5 | ceff5abec70c1f5b8bc96cbaa5f529be |
|
BLAKE2b-256 | acb948d42292affc6a54ec82248f0f72960b3a732bf0b231b249bd91c093ee09 |
File details
Details for the file azurefunctions_extensions_http_fastapi-1.0.0a1-py3-none-any.whl
.
File metadata
- Download URL: azurefunctions_extensions_http_fastapi-1.0.0a1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d3054d5f3bcdad6e9ef768b874c61837124971b414dd54eda50709b9671750f |
|
MD5 | a63c6741bbbd18b5e970509712f5457d |
|
BLAKE2b-256 | 4d99251213f1f4fec1eec8deb7d56b568e77a17696851051a69d45770d287a6c |