Skip to content

Commit a2b6c44

Browse files
authored
update README (#8)
* add fastapi readme * update * Update README.md
1 parent 251c4d0 commit a2b6c44

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

azure-functions-extension-base/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
This is the base library for allowing Python Function Apps to recognize and bind to SDk-types and HttpV2-types. It is not to be used directly.
33
Instead, please reference one of the extending packages:
44
* azure-functions-extension-blob
5-
* azure-functions-extension-fastapi
5+
* azure-functions-extension-fastapi
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Azure Functions Extension FastApi library for Python
2+
This library contains HttpV2 extensions for FastApi Request/Response types to use in your function app code.
3+
4+
[Source code](https://github.com/Azure/azure-functions-python-extensions/tree/main/azure-functions-extension-fastapi)
5+
| Package (PyPi)
6+
| Package (Conda)
7+
| API reference documentation
8+
| Product documentation
9+
| [Samples](hhttps://github.com/Azure/azure-functions-python-extensions/tree/main/azure-functions-extension-fastapi/samples)
10+
11+
12+
## Getting started
13+
14+
### Prerequisites
15+
* Python 3.8 or later is required to use this package. For more details, please read our page on [Python Functions version support policy](https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=isolated-process%2Cv4&pivots=programming-language-python#languages).
16+
17+
18+
### Instructions
19+
1. Follow the guide to [create an app](https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=windows%2Cbash%2Cazure-cli%2Cbrowser).
20+
2. Ensure your app is using programming model v2 and contains a http trigger function.
21+
3. Add azure-functions-extension-fastapi to your requirement.txt
22+
4. Import Request and different types of responses from azure.functions.extensions.fastapi in your httptrigger functions.
23+
5. Change the request and response types to ones imported from azure.functions.extensions.fastapi.
24+
6. Run your function app and try it out!
25+
26+
### Bind to the FastApi-type
27+
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)
28+
29+
30+
```python
31+
# This Azure Function receives streaming data from a client and processes it in real-time.
32+
# It demonstrates streaming upload capabilities for scenarios such as uploading large files,
33+
# processing continuous data streams, or handling IoT device data.
34+
35+
import azure.functions as func
36+
from azure.functions.extension.fastapi import Request, JSONResponse
37+
38+
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
39+
40+
@app.route(route="streaming_upload", methods=[func.HttpMethod.POST])
41+
async def streaming_upload(req: Request) -> JSONResponse:
42+
"""Handle streaming upload requests."""
43+
# Process each chunk of data as it arrives
44+
async for chunk in req.stream():
45+
process_data_chunk(chunk)
46+
47+
# Once all data is received, return a JSON response indicating successful processing
48+
return JSONResponse({"status": "Data uploaded and processed successfully"})
49+
50+
def process_data_chunk(chunk: bytes):
51+
"""Process each data chunk."""
52+
# Add custom processing logic here
53+
pass
54+
```
55+
56+
## Next steps
57+
58+
### More sample code
59+
60+
Get started with our [FastApi samples](hhttps://github.com/Azure/azure-functions-python-extensions/tree/main/azure-functions-extension-fastapi/samples).
61+
62+
Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with FastApi:
63+
64+
* [fastapi_samples_streaming_upload](https://github.com/Azure/azure-functions-python-extensions/tree/main/azure-functions-extension-fastapi/samples/fastapi_samples_streaming_upload) - An example on how to send and receiving a streaming request within your function.
65+
66+
* [fastapi_samples_streaming_download](https://github.com/Azure/azure-functions-python-extensions/tree/main/azure-functions-extension-fastapi/samples/fastapi_samples_streaming_download) - An example on how to send your http response via streaming to the caller.t
67+
68+
## Contributing
69+
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.
70+
71+
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.
72+
73+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

0 commit comments

Comments
 (0)