Chapter 5.5 • Backend Runtimes
Python (FastAPI, Django & Flask) Backend Integration
Resolve visitor purchasing power parity pricing policies server-side in Python microservices and API gateways.
FastAPI Async Backend Client
Use httpx to query the ParityEdge Edge API asynchronously. Pass the visitor's IP in the CF-Connecting-IP header to evaluate their country:
import httpx
from fastapi import FastAPI, Request
app = FastAPI()
EDGE_API_URL = "https://parityedge-edge-api.g-saichakri.workers.dev/v1/resolve"
PROJECT_ID = "prj_live_YOUR_KEY"
@app.get("/api/pricing")
async def get_localized_pricing(request: Request):
# Extract client IP from proxy headers
client_ip = request.headers.get("x-forwarded-for", request.client.host).split(",")[0].strip()
async with httpx.AsyncClient(timeout=2.0) as client:
try:
resp = await client.get(
EDGE_API_URL,
params={"projectId": PROJECT_ID},
headers={"CF-Connecting-IP": client_ip}
)
parity_data = resp.json()
except Exception:
# Safe fail-open default
parity_data = {"eligible": False, "discountPercentage": 0}
return {
"base_price_usd": 49.0,
"parity": parity_data
}Django View / Middleware
import requests
from django.http import JsonResponse
def pricing_view(request):
client_ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR'))
res = requests.get(
'https://parityedge-edge-api.g-saichakri.workers.dev/v1/resolve',
params={'projectId': 'prj_live_YOUR_KEY'},
headers={'CF-Connecting-IP': client_ip},
timeout=1.5
)
return JsonResponse(res.json())Next: Go (Golang) Backend Guide
Discover high-concurrency Go middleware for microservices.