Code Monkey home page Code Monkey logo

fastapi-on-azure-functions's Introduction

page_type languages products urlFragment name description
sample
azdeveloper
python
bicep
azure
azure-functions
fastapi-on-azure-functions
Using FastAPI Framework with Azure Functions
This is a sample Azure Function app created with the FastAPI framework.

Using FastAPI Framework with Azure Functions

Azure Functions supports WSGI and ASGI-compatible frameworks with HTTP-triggered Python functions. This can be helpful if you are familiar with a particular framework, or if you have existing code you would like to reuse to create the Function app. The following is an example of creating an Azure Function app using FastAPI.

Prerequisites

You can develop and deploy a function app using either Visual Studio Code or the Azure CLI. Make sure you have the required prerequisites for your preferred environment:

Setup

Clone or download this sample's repository, and open the fastapi-on-azure-functions folder in Visual Studio Code or your preferred editor (if you're using the Azure CLI).

Using FastAPI Framework in an Azure Function App

The code in the sample folder has already been updated to support use of the FastAPI. Let's walk through the changed files.

The requirements.txt file has an additional dependency of the fastapi module:

azure-functions
fastapi

The file host.json includes the a routePrefix key with a value of empty string.

{
  "version": "2.0",
  "extensions": {
    "http": {
        "routePrefix": ""
    }
  }
}

The root folder contains function_app.py which initializes an AsgiFunctionApp using the imported FastAPI app:

import azure.functions as func

from WrapperFunction import app as fastapi_app

app = func.AsgiFunctionApp(app=fastapi_app, http_auth_level=func.AuthLevel.ANONYMOUS)

In the WrapperFunction folder, the __init__.py file defines a FastAPI app in the typical way (no changes needed):

import azure.functions as func

import fastapi

app = fastapi.FastAPI()

@app.get("/sample")
async def index():
    return {
        "info": "Try /hello/Shivani for parameterized route.",
    }


@app.get("/hello/{name}")
async def get_name(name: str):
    return {
        "name": name,
    }

Running the sample

Testing locally

  1. Create a Python virtual environment and activate it.

  2. Run the command below to install the necessary requirements.

    python -m pip install -r requirements.txt
    
  3. If you are using VS Code for development, click the "Run and Debug" button or follow the instructions for running a function locally. Outside of VS Code, follow these instructions for using Core Tools commands directly to run the function locally.

  4. Once the function is running, test the function at the local URL displayed in the Terminal panel: =======

Functions:
        http_app_func: [GET,POST,DELETE,HEAD,PATCH,PUT,OPTIONS] http://localhost:7071//{*route}
```log
Functions:
        WrapperFunction: [GET,POST] http://localhost:7071/{*route}
```

Try out URLs corresponding to the handlers in the app, both the simple path and the parameterized path:

```
http://localhost:7071/sample
http://localhost:7071/hello/YourName
```

Deploying to Azure

There are three main ways to deploy this to Azure:

All approaches will provision a Function App, Storage account (to store the code), and a Log Analytics workspace.

Azure resources created by the deployment: Function App, Storage Account, Log Analytics workspace

Testing in Azure

Once deployed, test different paths on the deployed URL, using either a browser or a tool like Postman.

http://<FunctionAppName>.azurewebsites.net/sample
http://<FunctionAppName>.azurewebsites.net/hello/Foo

Next Steps

Now you have a simple Azure Function App using the FastAPI framework, and you can continue building on it to develop more sophisticated applications.

To learn more about leveraging WSGI and ASGI-compatible frameworks, see Web frameworks.

fastapi-on-azure-functions's People

Contributors

jianingwang123 avatar karolpawlowski avatar microsoftopensource avatar pamelafox avatar shreyabatra4 avatar timotk avatar tonybaloney avatar vrdmr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastapi-on-azure-functions's Issues

Logging not working for synchronous path operations

This issue is for a: (mark with an x)

- [x] bug report
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  • Define a synchronous path operation with logging:
@app.get("/sample")
def index():
    logging.info("sample")
    return {
        "info": "Try /hello/Shivani for parameterized route.",
    }
  • Start the function and call the operation with an http request

Expected/desired behavior

Expected: A line with the logged text appears in the logs (same behaviour as with async operations)
Actual: Nothing is logged.

OS and Version?

Windows 10

Versions

Python version: 3.9.10
Core Tools Version: 4.0.4704
Function Runtime Version: 4.7.3.18953
azure-functions==1.12.0
fastapi==0.88.0

Cannot Deploy to Az via VS Code Azure Functions Extension

  • bug report -> please search issues before submitting
  • feature request
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Download the repo as a zip file, install the Azure Functions extension. Follow the instructions (https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python?pivots=python-mode-decorators#publish-the-project-to-azure) on how to deploy. The extension does not recognize any function from the code -- hopefully, I can correctly upload a screenshot
az_func_issue

Any log messages given by the failure

No, since it is not possible to even start deploying the function.

Expected/desired behavior

You can see the function in the menu as shown in the instructions.

OS and Version?

Windows 10.0.19045

Versions

VS Code: v1.82.1 (user setup)
Commit: 6509174151d557a81c9d0b5f8a5a1e9274db5585
Date: 2023-09-08T08:45:05.575Z
Electron: 25.8.0
ElectronBuildId: 23503258
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045VS
Code Azure Functions Extension: v1.12.4

Mention any other details that might be useful

If I add a function.json file in the WrapperFunction folder, the function becomes visible to the Azure Functions extension. However, I am not sure this is a good idea -- or in any case, the recommended solution.

testing locally process ends directly

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

I just try to run the sample locally to see if it works, but it just dies
Below is the run with debug output from vscode:

 & 'c:\dist\venvs\fastapi-on-azure-functions\Scripts\python.exe' 'c:\Users\mobj\.vscode\extensions\ms-python.python-2023.10.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '63728' '--' 'c:\dist\work\fastapi-on-azure-functions\function_app.py' 
just go back to the prompt. so there is no process taking the prompt.

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
windows11

Versions

python --version
Python 3.11.4

< pip freeze
anyio==3.7.0
azure-functions==1.15.0
fastapi==0.99.1
idna==3.4
pydantic==1.10.11
sniffio==1.3.0
starlette==0.27.0
typing_extensions==4.7.1

Mention any other details that might be useful


Thanks! We'll be in touch soon.

AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async' when running locally

Hi, I'm trying to run this locally (OSX BigSur v11.7) to get to grips with a basic example before integrating functions into my main FastApi project. I've set up the CLI integration as suggested in Azure docs, and am running:

> func --version
4.0.4829
> az --version
azure-cli                         2.42.0

core                              2.42.0
telemetry                          1.0.8

Dependencies:
msal                              1.20.0
azure-mgmt-resource             21.1.0b1

The repo is cloned to a directory with a virtualenv running Python 3.7.5. When I run func start, the worker starts as expected, but when I send a GET request to http://localhost:7071/sample, I get an exception to the effect that handle_async isn't a recognised attribute of AsgiMiddleware:

[2022-11-01T13:04:51.693Z] Executed 'Functions.WrapperFunction' (Failed, Id=7f65d33d-f786-44e0-ad6a-a173327fe49a, Duration=157ms)
[2022-11-01T13:04:51.694Z] System.Private.CoreLib: Exception while executing function: Functions.WrapperFunction. System.Private.CoreLib: Result: Failure
[2022-11-01T13:04:51.694Z] Exception: AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async'
[2022-11-01T13:04:51.694Z] Stack:   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 445, in _handle__invocation_request
[2022-11-01T13:04:51.694Z]     fi_context, fi.func, args
[2022-11-01T13:04:51.694Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 698, in _run_async_func
[2022-11-01T13:04:51.694Z]     context, func, params
[2022-11-01T13:04:51.694Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.4829/workers/python/3.7/OSX/X64/azure_functions_worker/extension.py", line 147, in get_async_invocation_wrapper
[2022-11-01T13:04:51.694Z]     result = await function(**args)
[2022-11-01T13:04:51.694Z]   File "/<user-dir>/fastapi-on-azure-functions/WrapperFunction/__init__.py", line 21, in main
[2022-11-01T13:04:51.694Z]     return await func.AsgiMiddleware(app).handle_async(req, context)

I reverted to the previous handle code (using nest_asyncio), and that works fine. I suspect some library mismatch, as PyCharm can find the handle_async method just fine, but any ideas? I'm not sure on the inner workings of this stuff, so really unsure how to dig deeper in debugging this.

"No job functions found" when migrating from folder structure to fast API

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  1. Start a project where the code is generated from VSCode
  2. Try to add the FastAPI feature as suggested in this documentation

Any log messages given by the failure

image

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Here is my files:

image

Contents of WrapperFunction/__init__.py

import azure.functions as func

import fastapi

app = fastapi.FastAPI()

@app.get("/sample")
async def index():
    return {
        "info": "Try /hello/Shivani for parameterized route.",
    }


@app.get("/hello/{name}")
async def get_name(name: str):
    return {
        "name": name,
    }

Contents of function_app.py

import azure.functions as func

from WrapperFunction import app as fastapi_app

app = func.AsgiFunctionApp(app=fastapi_app, http_auth_level=func.AuthLevel.ANONYMOUS)

Contents of host.json

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "http": {
      "routePrefix": ""
    }
  }
}

Expected/desired behavior

Should just work like when I clone your repo

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Windows 11 Pro - 22621.2134

Versions

> pip freeze           
annotated-types==0.5.0
anyio==3.7.1
azure-common==1.1.28
azure-core==1.26.4
azure-functions==1.14.0
azure-identity==1.11.0
azure-keyvault-secrets==4.6.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
colorama==0.4.6
cryptography==40.0.2
et-xmlfile==1.1.0
exceptiongroup==1.1.1
fastapi==0.103.1
idna==3.4
iniconfig==2.0.0
isodate==0.6.1
msal==1.22.0
msal-extensions==1.0.0
msrest==0.7.1
numpy==1.24.3
oauthlib==3.2.2
openpyxl==3.0.10
packaging==23.1
pandas==2.0.1
pluggy==1.0.0
portalocker==2.7.0
pycparser==2.21
pydantic==2.3.0
pydantic_core==2.6.3
PyJWT==2.7.0
pyodbc==4.0.32
pytest==7.3.1
python-dateutil==2.8.2
pytz==2023.3
pywin32==306
requests==2.30.0
requests-oauthlib==1.3.1
six==1.16.0
sniffio==1.3.0
starlette==0.27.0
tomli==2.0.1
typing_extensions==4.7.1
tzdata==2023.3
urllib3==2.0.2

Mention any other details that might be useful


Thanks! We'll be in touch soon.

When setting up Azure Functions "Always On", HTTP status code 401.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

#function_app.py
import azure.functions as func
from fastapi import FastAPI


fast_app = FastAPI()
app = func.AsgiFunctionApp(app=fast_app, http_auth_level=func.AuthLevel.FUNCTION)
  1. In the Azure portal, search for and select App Services, and then select your app. In the app's left menu, select Configuration > General settings.
  2. I enable Always On.

Any log messages given by the failure

2024-04-04T05:58:14Z [Verbose] Request successfully matched the route with name 'http_app_func' and template '/{*route}'
2024-04-04T05:58:14Z [Information] Executing StatusCodeResult, setting HTTP status code 401

Expected/desired behavior

Expected: HTTP status code 200.

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Linux (App Service Plan Premium v3 P1V3)

Versions

  • Python: 3.10.x
  • Runtime version: 4.31.1.1

Mention any other details that might be useful

allow custom function name instead of http_app_func

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ x ] feature request
- [  ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Clone the repo and follow the instruction

Any log messages given by the failure

[2024-03-06T00:53:18.773Z] Worker failed to index functions
[2024-03-06T00:53:18.775Z] Result: Failure
Exception: AttributeError: 'AsgiFunctionApp' object has no attribute 'function_name'

Expected/desired behavior

OS and Version?

Windows 11

Versions

Found Python version 3.9.13 (py).
Azure Functions Core Tools
Core Tools Version: 4.0.5530 Commit hash: N/A +c8883e7f3c06e2b424fbac033806c19d8d91418c (64-bit)
Function Runtime Version: 4.28.5.21962

Mention any other details that might be useful

Is it possible to set the function name instead of http_app_func? Something like this?

app = func.AsgiFunctionApp(app=fastapi_app, http_auth_level=func.AuthLevel.FUNCTION).function_name(name="test123")


Thanks! We'll be in touch soon.

Updating/work-with this template for GHA and Azd Devcontainer feature.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

We are updating this template to support new features in Github Action and Azd Devcontainer.

  1. For the Github Action feature: We will remove two lines of code on container image and add GHA code after checkout step in the .github/workflow/azure-dev.yml file. (Shown as below)
image
  1. For the Azd Devcontainer feature: We will add the following code in devcontainer.json file.
"ghcr.io/azure/azure-dev/azd:latest": {}

And remove the relevant code for installing azd in Dockerfile under .devcontainer folder.

RUN curl -fsSL https://aka.ms/install-azd.sh | bash \

@rajeshkamal5050 , @pamelafox , @shreyabatra4 for notification.

fastapi background tasks do not work on azure function apps

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

I added background tasks as described in https://fastapi.tiangolo.com/tutorial/background-tasks/.
You can see this in my fork of this repo: https://github.com/warreee/fastapi-on-azure-functions-background-tasks.
When running locally or in Azure will see that a response is not returned immediately but only after 5 seconds (the delay set in the background task).

Any log messages given by the failure

Expected/desired behavior

I expect the function app to give an immediate response while still finishing the background task afterwards.

OS and Version?

MacOs Sonoma

Versions

Function runtime: 4.33.2.2
Python: 3.11

Mention any other details that might be useful


Thanks! We'll be in touch soon.

FR: Show use of bindings in sample

This issue is for a:

- [ ] bug report -> please search issues before submitting
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Expected/desired behavior

It would be really great to demonstrate the use of output bindings in this sample.

Customer packages not in sys path.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Clone repo. Then run:

python -m venv . venv
pip install -r requirements.txt
func start

Any log messages given by the failure

[2024-02-10T16:12:42.877Z] Customer packages not in sys path. This should never happen!

[...]

Worker failed to index functions
[2024-02-10T16:12:43.200Z] Result: Failure
Exception: ModuleNotFoundError: No module named 'fastapi'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound
Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 345, in handle__functions_metadata_request
fx_metadata_results = self.index_functions(function_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 617, in index_functions
indexed_functions = loader.index_function_app(function_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 48, in call
raise extend_exception_message(e, message)
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 44, in call
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\loader.py", line 214, in index_function_app
imported_module = importlib.import_module(module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2032.0_x64__qbz5n2kfra8p0\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap.gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jonny\dev\magpi\fastapi-on-azure-functions\function_app.py", line 3, in
from WrapperFunction import app as fastapi_app
File "C:\Users\jonny\dev\magpi\fastapi-on-azure-functions\WrapperFunction_init
.py", line 3, in
import fastapi

Expected/desired behavior

Function should start

OS and Version?

Windows 11.

Versions

Azure Functions Core Tools
Core Tools Version: 4.0.5455 Commit hash: N/A (64-bit)
Function Runtime Version: 4.27.5.21554

Mention any other details that might be useful

Same issue when I try on my own repo (with similar architecture).


Thanks! We'll be in touch soon.

request.client (Method of request class in fastapi) is None when deployed to azure function

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Deploy the fastapi on azure function
Create a route that reads request object
Check the value of request.client which is None when fastapi is deployed on azure function

Any log messages given by the failure

Expected/desired behavior

request.client should show the information such as ip address and port number of requesting client

OS and Version?

When deployed in azure function

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Container is marked as unhealthy when "routePrefix" is empty

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Follow example of using FastAPI on Azure Functions

Any log messages given by the failure

Container logs:

2022-11-07T05:03:23.905498754Z Starting OpenBSD Secure Shell server: sshd.
2022-11-07T05:03:25.784337592Z Hosting environment: Production
2022-11-07T05:03:25.784372792Z Content root path: /azure-functions-host
2022-11-07T05:03:25.784378492Z Now listening on: http://[::]:80
2022-11-07T05:03:25.784381892Z Application started. Press Ctrl+C to shut down.

Service log:

2022-11-07T05:01:48.563Z INFO  - Initiating warmup request to container <name>-dtest_0_975e4ee4 for site <name>-dtest
2022-11-07T05:02:07.615Z ERROR - Container <name>-dtest_0_975e4ee4 for site <name>-dtest has exited, failing site start
2022-11-07T05:02:07.627Z ERROR - Container <name>-dtest_0_975e4ee4 didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.

Expected/desired behavior

Service would start and would be accessible. It works just fine locally.

OS and Version?

Linux Container with non-consumption App Service Plan

Versions

4.0.4829 local, latest deployed

Mention any other details that might be useful

Once I adjusted the routePrefix to be "api" again it started working, had to re-write a bunch of code to be at a different base URL.

fastapi with Python programming model v2

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Is it possible to use fastapi with Python programming model v2? I can not find any information about this

Async doesn't work - is sequential instead

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

The app doesn't handle multiple request with async. If you add a asyncio.sleep(1) like this it will only be able to handle 1 request per second.

import azure.functions as func
from FastAPIApp import app  # Main API application
import nest_asyncio
import asyncio
nest_asyncio.apply()

@app.get("/sample")
async def index():
  await asyncio.sleep(1)
  return {
      "info": "Try /hello/Shivani for parameterized route.",}

async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
    return func.AsgiMiddleware(app).handle(req, context)

Which is in contrast to following which can take a large amount of requests.

import azure.functions as func

async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
  print("called 1")
  await asyncio.sleep(1)
  return "Try /hello/Shivani for parameterized route."

You can test it out with locust using the following:

  1. pip install locust
  2. create file locustfile.py
##  locustfile.py
from locust import HttpUser, task

class HelloWorldUser(HttpUser):
    @task
    def hello_world(self):
        self.client.get("/sample")
  1. run locust

Any log messages given by the failure

Expected/desired behavior

That the async would work.

OS and Version?

Windows 10. Linux

Versions

fastapi==0.80.0
azure-functions== 1.11.2

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.