Server framework guides
Use the official Node.js or Python SDK from the server runtime your application already has.
SWITCHPILOT_API_KEY in the server environment. Create one reusable client, then evaluate flags inside routes, controllers, services, jobs, or server-rendered code.Express
Install
pnpm add @switchpilot/nodeConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import express from "express";
import { createSwitchPilot } from "@switchpilot/node";
const app = express();
const flags = createSwitchPilot({
apiKey: process.env.SWITCHPILOT_API_KEY!,
});
app.get("/api/features", async (_request, response) => {
const newCheckout = await flags.isEnabled("new-checkout");
response.json({ newCheckout });
});Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.
NestJS
Install
pnpm add @switchpilot/nodeConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import { Injectable } from "@nestjs/common";
import { createSwitchPilot } from "@switchpilot/node";
@Injectable()
export class FeaturesService {
private readonly flags = createSwitchPilot({
apiKey: process.env.SWITCHPILOT_API_KEY!,
});
isNewCheckoutEnabled() {
return this.flags.isEnabled("new-checkout");
}
}Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.
Nuxt server routes
Install
pnpm add @switchpilot/nodeConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import { createSwitchPilot } from "@switchpilot/node";
const flags = createSwitchPilot({
apiKey: process.env.SWITCHPILOT_API_KEY!,
});
export default defineEventHandler(async () => ({
newCheckout: await flags.isEnabled("new-checkout"),
}));Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.
Django
Install
pip install switchpilotConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import os
from django.http import JsonResponse
from switchpilot import SwitchPilot
flags = SwitchPilot(api_key=os.environ["SWITCHPILOT_API_KEY"])
def features(_request):
return JsonResponse({
"newCheckout": flags.is_enabled("new-checkout")
})Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.
FastAPI
Install
pip install switchpilotConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import os
from fastapi import FastAPI
from switchpilot import SwitchPilot
app = FastAPI()
flags = SwitchPilot(api_key=os.environ["SWITCHPILOT_API_KEY"])
@app.get("/api/features")
def features() -> dict[str, bool]:
return {"newCheckout": flags.is_enabled("new-checkout")}Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.
Flask
Install
pip install switchpilotConfigure
SWITCHPILOT_API_KEY="sp_live_your_project_key"Initialize and evaluate a flag
import os
from flask import Flask, jsonify
from switchpilot import SwitchPilot
app = Flask(__name__)
flags = SwitchPilot(api_key=os.environ["SWITCHPILOT_API_KEY"])
@app.get("/api/features")
def features():
return jsonify(newCheckout=flags.is_enabled("new-checkout"))Evaluation reads the local in-memory cache. Synchronization happens when needed, or immediately when you call refresh(). The default cache TTL is 60 seconds and the default stale-if-error window is 5 minutes. See the Reliability guide.