-
Notifications
You must be signed in to change notification settings - Fork 0
Python Serverless Functions
Akshay B edited this page Mar 16, 2026
·
1 revision
This document tracks the Python backend implemented in PluckIt.Processor.
It keeps shared runtime/setup behavior here and links to feature-level pages for endpoint contracts and per-feature behavior.
The page intentionally avoids duplicating domain-level behavior that is documented under each service-domain page.
- Audience: external contributors
- Last reviewed: 2026-03-16
- Scope: Python runtime contracts and behavior only
- Entry file:
PluckIt.Processor/function_app.py - Runtime: Python (
FUNCTIONS_WORKER_RUNTIME=python) - Stack: FastAPI application mounted into Azure Functions via
func.AsgiFunctionApp - HTTP route prefix:
/api - Health endpoint:
GET /api/health - Notable characteristics:
- FastAPI docs disabled (
docs_url=None,redoc_url=None) - Chat route uses SSE (
text/event-stream) - Optional telemetry integration via OpenTelemetry and Langfuse
- FastAPI docs disabled (
- Install Python 3.12+, Azure Functions Core Tools 4.x, Azurite, and local Cosmos emulator.
- Create local settings from template:
cp PluckIt.Processor/local.settings.json.example PluckIt.Processor/local.settings.json
- Configure local secrets (
AZURE_OPENAI_*, metadata auth keys) inPluckIt.Processor/local.settings.json. - Set up venv + dependencies:
cd PluckIt.Processorpython3 -m venv .venv-
source .venv/bin/activate(or.venv\Scripts\activateon Windows) pip install -r requirements-prod.txt-
pip install -r requirements-test.txt(for local unit tests)
- Run service:
func start --port 7071
- Confirm health:
curl http://localhost:7071/api/health
- Run local unit tests:
python -m pytest tests/unit/ -v --tb=short -m unit
-
python -m pytest tests/unit/ -v --tb=short -m unit --cov=. --cov-report=xml - Validate that
.github/workflows/function-ci.ymlcompletestestbefore deploy stage.
-
PluckIt.Processor/function_app.pydefines:fastapi_app = FastAPI(...)app = func.AsgiFunctionApp(app=fastapi_app, http_auth_level=func.AuthLevel.ANONYMOUS)
- Non-HTTP triggers (queue + timer) are declared on the same
app.
- Canonical token and local-auth behavior is documented in
Authentication and Identity. - This page documents only the shared Python service contract (separate from .NET contracts).
- Most functional routes depend on
Depends(get_user_id). - Administrative operations are explicitly called out in the matching domain pages.
- Public contract:
GET /api/health
- Protected routes:
- All non-public
/api/*contracts below use resolved user identity.
- All non-public
- Admin routes:
-
POST /api/admin/*requires membership inADMIN_USER_IDS.
-
-
Health Functions(/api/health) -
Auth Functions(/api/auth/*) -
Media and Metadata(/api/process-image,/api/extract-clothing-metadata) -
Chat and Memory(/api/chat*,/api/chat/memory) -
Digest and Analytics(/api/digest*,/api/insights/vault) -
Moods(/api/moods*) -
Scraper(/api/scraper*,/api/admin/*) -
Taste Calibration(/api/taste/quiz*) -
Background Processing(queue + timer workers)
- Route ownership and behavior details are documented in domain pages.
- Route authentication model for each page should align with shared token flow documented in
Authentication and Identity. - Endpoint-level policy checks:
-
POST /api/admin/*routes require caller membership inADMIN_USER_IDS. -
GET /api/healthis intentionally public.
-
- Endpoint contracts are versioned implicitly by domain pages in this backend area.
- Route behavior and endpoint-specific constraints are documented in the linked domain pages.
FUNCTIONS_WORKER_RUNTIME=python- Storage / blobs:
-
StorageQueue(orSTORAGE_ACCOUNT_NAME+STORAGE_ACCOUNT_KEY) ARCHIVE_CONTAINER_NAME
-
- Cosmos:
COSMOS_DB_ENDPOINTCOSMOS_DB_KEYCOSMOS_DB_DATABASECOSMOS_DB_TASTE_JOBS_CONTAINERCOSMOS_DB_TASTE_JOB_DEAD_LETTER_CONTAINER
- AI / metadata:
AZURE_OPENAI_ENDPOINTAZURE_OPENAI_API_KEY-
AZURE_OPENAI_DEPLOYMENT(default:gpt-4.1-mini) SEGMENTATION_ENDPOINT_URLSEGMENTATION_SHARED_TOKEN
ADMIN_USER_IDSCORS_ALLOWED_ORIGINSMETADATA_EXTRACT_AUTH_MODEMETADATA_EXTRACT_API_KEYMETADATA_EXTRACT_AZURE_AD_AUDIENCEMETADATA_EXTRACT_AZURE_AD_ISSUER
TASTE_JOB_QUEUE_NAMETASTE_JOB_DEAD_LETTER_QUEUE_NAMETASTE_JOB_DEDUPE_TTL_SECONDSTASTE_JOB_COMPLETED_TTL_SECONDSTASTE_JOB_MAX_RETRIESTASTE_JOB_BASE_BACKOFF_SECONDSTASTE_JOB_MAX_BACKOFF_SECONDSTASTE_JOB_JITTER_SECONDSTASTE_JOB_PROFILE_UPDATE_MAX_RETRIESWEEKLY_DIGEST_MAX_CONCURRENCYSCRAPER_MAX_CONCURRENCY
OTEL_EXPORTER_OTLP_ENDPOINTOTEL_EXPORTER_OTLP_TRACES_ENDPOINTOTEL_EXPORTER_OTLP_METRICS_ENDPOINTOTEL_EXPORTER_OTLP_LOGS_ENDPOINTOTEL_SERVICE_NAMEOTEL_EXPORTER_OTLP_HEADERSOTEL_EXPORTER_OTLP_PROTOCOLOTEL_TRACES_EXPORTEROTEL_METRICS_EXPORTEROTEL_LOGS_EXPORTERLANGFUSE_PUBLIC_KEYLANGFUSE_SECRET_KEYLANGFUSE_HOSTLANGFUSE_BASE_URL
PluckIt.Processor/local.settings.jsonPluckIt.Processor/local.settings.local.json
- Keep variable names, but do not document concrete secret values or tenant-specific hostnames.
- If auth behavior changes, update
Authentication and Identityfirst, then synchronize this page.