Server framework guides

Use the official Node.js or Python SDK from the server runtime your application already has.

Server-side essentials
Security and runtime requirements for every integration.

Official SDKs are server-side only.

Never expose API keys in browser or client code.

Store API keys in environment variables.

The default fallback is false.

SDKs fail safely if SwitchPilot is unreachable.

Default cache TTL: 60 seconds.

Default stale-if-error window: 5 minutes.

Express

Install

terminal
pnpm add @switchpilot/node

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

server.ts
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

terminal
pnpm add @switchpilot/node

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

features.service.ts
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

terminal
pnpm add @switchpilot/node

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

server/api/features.get.ts
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

terminal
pip install switchpilot

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

views.py
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

terminal
pip install switchpilot

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

main.py
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

terminal
pip install switchpilot

Configure

.env
SWITCHPILOT_API_KEY="sp_live_your_project_key"

Initialize and evaluate a flag

app.py
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.