Configuration
The SDK is designed to work optimally out of the box with minimal configuration. Only your API key is required.
Basic Configuration
from featsync import Featsync
client = Featsync(api_key="fs_your_api_key")That’s it! The SDK automatically:
- Caches flags for 5 minutes
- Prefetches all flags on initialization
- Uses a 5-second request timeout
- Falls back to stale cache on API errors
Full Configuration
client = Featsync( # Required: Your API key from the dashboard api_key="fs_your_api_key",
# Optional: Environment to evaluate (default: 'production') environment="production",
# Optional: Override base URL (for development/testing) base_url="https://custom.featsync.io",)Configuration Options
api_key (required)
Your API key from the Featsync dashboard. Each environment has its own API key.
api_key="fs_abc123..."environment
The environment to evaluate flags against. Defaults to 'production'.
environment="production" # or 'staging', 'development'base_url
Override the API base URL. Useful for local development or testing.
base_url="http://localhost:3000"You can also use environment variables:
export FEATSYNC_URL=http://localhost:3000The SDK checks for FEATSYNC_SDK_BASE_URL or FEATSYNC_URL environment variables automatically.
Built-in Defaults
The SDK uses optimized defaults that work well for most applications:
| Setting | Value | Description |
|---|---|---|
| Cache duration | 5 minutes | Flags are cached to minimize API calls |
| Request timeout | 5 seconds | Balanced timeout for reliability |
| Prefetch | Always enabled | Flags load immediately on initialization |
| Stale cache | Always enabled | Returns stale data on API errors |
These values are carefully chosen based on best practices and cannot be overridden.
Environment Variables
We recommend using environment variables for configuration:
import osfrom featsync import Featsync
client = Featsync( api_key=os.environ["FEATSYNC_API_KEY"], environment=os.environ.get("FEATSYNC_ENVIRONMENT", "production"),)Django
FEATSYNC_API_KEY = os.environ.get("FEATSYNC_API_KEY")from django.conf import settingsfrom featsync import Featsync
client = Featsync(api_key=settings.FEATSYNC_API_KEY)Flask
import osfrom flask import Flaskfrom featsync import Featsync
app = Flask(__name__)featsync = Featsync(api_key=os.environ.get("FEATSYNC_API_KEY"))FastAPI
import osfrom fastapi import FastAPIfrom featsync import Featsync
app = FastAPI()featsync = Featsync(api_key=os.environ.get("FEATSYNC_API_KEY"))Singleton Pattern
Create a single SDK instance and reuse it throughout your application:
import osfrom featsync import Featsync
client = Featsync(api_key=os.environ["FEATSYNC_API_KEY"])from lib.featsync_client import client
if client.is_enabled("my-flag"): # ...Thread Safety
The SDK is thread-safe. You can safely share a single instance across multiple threads:
import threadingfrom featsync import Featsync
# Create one clientclient = Featsync(api_key=os.environ["FEATSYNC_API_KEY"])
def worker(): # Safe to use from multiple threads if client.is_enabled("feature"): do_work()
# Use across threadsthreads = [threading.Thread(target=worker) for _ in range(10)]for t in threads: t.start()Next Steps
- Learn basic usage patterns
- Set up targeting rules for user-specific flags