This directory contains example projects demonstrating how to use the Replane Python SDK for feature flags and remote configuration.
| Example | Description |
|---|---|
| basic-sync | Basic usage with the synchronous client |
| basic-async | Basic usage with the asynchronous client |
| flask-integration | Integration with Flask web framework |
| fastapi-integration | Integration with FastAPI framework |
| django-integration | Integration with Django framework |
| testing | How to test code that uses Replane |
| feature-flags | Various feature flag patterns and use cases |
Each example is a standalone project that can be copied and used as a starting point. To run any example:
-
Navigate to the example directory:
cd examples/basic-sync -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Update the configuration (BASE_URL and SDK_KEY) in the main file
-
Run the example:
python main.py # or app.py for web examples
Demonstrates the fundamental usage of Replane:
- Context manager usage
- Reading feature flags and configs
- Passing context for override evaluation
- Default values
- Manual lifecycle management
Demonstrates the asynchronous AsyncReplane:
- Async context manager usage
- Real-time update subscriptions
- Async callbacks
- Integration with asyncio applications
Shows how to integrate Replane with a Flask application:
- Application startup/shutdown lifecycle
- Building context from request headers
- Feature flags in route handlers
- Dynamic rate limits and upload sizes
Shows how to integrate Replane with FastAPI:
- Lifespan handler for async client
- Dependency injection
- Pydantic response models
- Middleware for maintenance mode
- Health check endpoints
Shows how to integrate Replane with Django:
- App initialization in
AppConfig.ready() - Singleton client pattern
- Custom middleware for maintenance mode
- Class-based views with feature flags
- Health check endpoints
Demonstrates testing patterns using InMemoryReplaneClient:
- Simple test configurations
- Override rules in tests
- Pytest fixtures
- Testing services with dependency injection
- Subscription testing
Comprehensive examples of feature flag patterns:
- Basic on/off toggles
- User targeting
- Plan-based limits
- Regional features
- Gradual rollouts
- Environment configs
- Complex conditions
- Real-time updates
- Python 3.10 or higher
- A Replane server (for non-testing examples)
- An SDK key from your Replane dashboard