Python SDK
Segment membership
Create the list in the dashboard and attach it to a Targeting filter. Sync members with a Backend application key. Evaluation uses the published list after the next definitions refresh. Flow · HTTP API
Server only
Requires a Backend application key. Do not call this from a browser, mobile app, or other public client.
import os
from toggly import SegmentMembershipClient
segments = SegmentMembershipClient(app_key=os.environ["TOGGLY_APP_KEY"])
segments.add_segment_members("Beta Testers", ["user-123"])
segments.remove_segment_members("Beta Testers", ["user-123"])
segments.replace_segment_members("Beta Testers", ["user-123"])
The official Python SDK for Toggly provides a comprehensive solution for feature flag management in Python applications.
Quick reference
Grab the printable Python cheat sheet (download PDF) — Django, Flask, FastAPI, async, caching.
Features
- Zero-dependency core - The core package has no external dependencies
- Django integration - Middleware, template tags, decorators, and context processors
- Flask integration - Extension, decorators, and Jinja2 template helpers
- FastAPI integration - Middleware, dependencies, and route decorators
- Distributed caching - Redis and Memcached support
- Async/await support - Native async client for async frameworks
- Type hints - Full type annotations for IDE support
- Python 3.8+ - Core
togglysupports Python 3.8 or higher - FastAPI package 3.9+ -
toggly-fastapirequires Python 3.9+ - Live updates - Optional WebSocket streaming via
toggly[websocket] - Signed definitions - ES256 verification with JWKS
Installation
- Core Only
- Django
- Flask
- FastAPI
- With Caching
pip install toggly
pip install toggly-django
pip install toggly-flask
pip install toggly-fastapi
# Redis caching
pip install toggly-cache[redis]
# Memcached caching
pip install toggly-cache[memcached]
# Both
pip install toggly-cache[all]