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 x-forwarded-for header to evaluate their country:
import httpx
from fastapi import FastAPI, Request
app = FastAPI()
EDGE_API_URL = "https://api.parityedge.app/v1/lookup"
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={"x-forwarded-for": 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://api.parityedge.app/v1/lookup',
params={'pid': 'prj_live_YOUR_KEY'},
headers={'x-forwarded-for': client_ip},
timeout=1.5
)
return JsonResponse(res.json())Next: Go (Golang) Backend Guide
Discover high-concurrency Go middleware for microservices.