Skip to main content

FastApi Python worker extension for Azure Functions.

Project description

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) | Developer Reference | Samples

Getting started

Prerequisites

Instructions

  1. Follow the guide to create an app. If you're testing the function locally, make sure to update to the latest version of Core Tools.
  2. Ensure your app is using programming model v2 and contains an HttpTrigger function.
  3. Add azurefunctions-extensions-http-fastapi to your requirements.txt
  4. Import Request and different types of responses from azurefunctions.extensions.http.fastapi in your HttpTrigger functions.
  5. Change the request and response types to ones imported from azurefunctions.extensions.http.fastapi.
  6. Add "PYTHON_ENABLE_INIT_INDEXING": "1" to your local.settings.json file or App Settings.
  7. 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 FastApi Request type, and you can return a FastApi Response type.

FastApi is one of the top Python web frameworks that provides elegant and powerful Request/Response types and functionalities. With this integration, you are empowered to use Request/Response types the same way as with native FastApi. For example, HTTP streaming upload and download scenarios are now possible! Please reference the FastApi documentation for further information.

# This function app 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.FUNCTION)

@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:

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


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.0.tar.gz.

File metadata

File hashes

Hashes for azurefunctions_extensions_http_fastapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bd3ff59dd2ad4fffa30622354e3c2bbf6204177589d0592cab64710224fed6af
MD5 471944a401a58d6594f2e3b48874363a
BLAKE2b-256 a04eef335c74bd47e5ae3729abb94724bb1915c006375d2bf5917c3f1f3214eb

See more details on using hashes here.

File details

Details for the file azurefunctions_extensions_http_fastapi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azurefunctions_extensions_http_fastapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d71e89e0750ab981abb94d504cabe25f98d047daf8b669be667e04c81cced98
MD5 8f001f80bc9b8bf1e6adbcba698cf513
BLAKE2b-256 4477449d1f669801e1e81d313d0255f9677aca2a243ed44aef8ed748a129defd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page