Skip to main content

Cactus

Adapter to run an Azure Function HTTP triggers with a WSGI or ASGI Web Server.

How it works

Given the path of a folder containing a Function App, it builds a WSGI or ASGI App parsing the Function settings. The app simply calls the Function main according to the route/methods settings.

Supported Function

This software is meant to support only Function which use binding httpTrigger as input and http as output. No other binding types. This is not an Azure emulator.

Function App structure

V1
FunctionApp
|-- host.json
|-- function_1
|	|-- function.json
|	|-- __init__.py
|-- function_2
|	|-- function.json
|	|-- __init__.py
V2
FunctionApp
|-- host.json
|-- local.settings.json
|-- function_app.py

Installing

pip install pycactus
pip install pycactus[flask] # to use Flask as web framework
pip install pycactus[fastapi] # to use FastAPI as web framework

How to run

Create a file "app.py"
from cactus.appfactory import build_app
app = build_app("YourFunctionAppFolder")

Or, to use Flask as web framework:

from cactus.flask import build_app
app = build_app("YourFunctionAppFolder")

Or, for V2 projects:

from cactus.flask import build_app_v2
app = build_app_v2("YourFunctionAppFolder")

Or, for FastAPI projects:

from cactus.fastapi import build_app_v2
app = build_app_v2("YourFunctionAppFolder")
Run it with a WSGI or ASGI Web Server
gunicorn app:app
uwsgi --http localhost:7071 --module app:app
uvicorn app:app

Checkout the examples for more.

Using Flask blueprints

from cactus.flask import build_blueprint
from cactus.route_info import parse_project

app = flask.Flask(__name__)
b = build_blueprint("myfunctionapp", parse_project("/path"))
app.register_blueprint(b)

Or, for V2 projects:

from cactus.flask import build_blueprint
from cactus.route_info import parse_project_v2

app = flask.Flask(__name__)
b = build_blueprint("myfunctionapp", parse_project_v2("/path"))
app.register_blueprint(b)

Using FastAPI APIRouter

from cactus.fastapi import build_api_router
from cactus.route_info import parse_project_v2

app = fastapi.FastAPI()
b = build_api_router("myfunctionapp", parse_project_v2("/path"))
app.include_router(b)

Testing

This module is tested using Fir WSGI client.

# Create a virtual environment 
python3 -m venv venv
source venv/bin/activate
# Install requirements
pip install -r requirements -r test-requirements
# Run tests with coverage
python -m pytest tests --cov=cactus

Release files for pycactus 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycactus 0.5.0
File Size Uploaded
pycactus-0.5.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycactus 0.5.0
File Interpreter ABI Platform
pycactus-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / pycactus-0.5.0.tar.gz

Download URL pycactus-0.5.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7886fc2dd624db701a2607f10f551fe1624149338856de13f7195d5552e69936
BLAKE2b-256 checksum
How to use checksums
9405fbd85362103b84ace81dca3914ad8d99c7da567eb0f4da82c03cbab6d571
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Release files / pycactus-0.5.0-py3-none-any.whl

Download URL pycactus-0.5.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5a7c99dff402c2af1a1052a963143a57c54d6e4e5a2a9bc1bd40c0054d7de40
BLAKE2b-256 checksum
How to use checksums
46c20373bc3e7f70bc6c8f61e840951fe398ef4055d156056089e48638c5b8a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page