Quickstart¶
This guide will get you up and running with litestar-flags in under 5 minutes.
Step 1: Install the Package¶
uv add litestar-flags
pip install litestar-flags
Step 2: Create Your First App¶
Create a file called app.py:
from litestar import Litestar, get
from litestar_flags import (
FeatureFlagsPlugin,
FeatureFlagsConfig,
FeatureFlagsClient,
FeatureFlag,
)
# Configure the plugin
config = FeatureFlagsConfig()
plugin = FeatureFlagsPlugin(config=config)
@get("/")
async def index(feature_flags: FeatureFlagsClient) -> dict:
# Create a feature flag if it doesn't exist
await feature_flags.create_flag(
FeatureFlag(
name="welcome_message",
enabled=True,
description="Show welcome message",
)
)
# Check if the flag is enabled
if await feature_flags.is_enabled("welcome_message"):
return {"message": "Welcome to litestar-flags!"}
return {"message": "Hello, World!"}
app = Litestar(
route_handlers=[index],
plugins=[plugin],
)
Step 3: Run Your App¶
litestar run
Visit http://localhost:8000 to see your feature flag in action!
Step 4: Toggle Features¶
You can toggle features at runtime:
@get("/toggle")
async def toggle(feature_flags: FeatureFlagsClient) -> dict:
# Get current state
flag = await feature_flags.get_flag("welcome_message")
# Toggle the flag
flag.enabled = not flag.enabled
await feature_flags.update_flag(flag)
return {"enabled": flag.enabled}
What’s Next?¶
Learn about Configuration options
Explore different Storage Backends
Set up Percentage Rollouts for gradual releases