A production-ready platform for running advanced A/B tests and multi-armed bandit experiments. This platform implements both Thompson Sampling and Epsilon-Greedy strategies for efficient experimentation.
- Multiple bandit strategies (Thompson Sampling, Epsilon-Greedy)
- REST API with automatic documentation
- Real-time variant selection
- Results tracking and export
- Comprehensive test suite
- Clone the repository:
git clone https://github.com/yourusername/mab-platform.git
cd mab-platform
- Install the package with development dependencies:
python3 -m pip install -e ".[dev]"
- Start the API server:
uvicorn mab_platform.api.main:app --reload
- The server will start at
http://localhost:8000
- API Documentation:
http://localhost:8000/docs
- Alternative Documentation:
http://localhost:8000/redoc
- API Documentation:
-
Open
http://localhost:8000/docs
in your browser -
Create an Experiment:
- Click on
POST /experiments/
- Click "Try it out"
- Enter experiment details in the JSON body:
{ "name": "Button Color Test", "variants": ["blue", "green", "red"], "end_date": null }
- Click "Execute"
- Save the returned
experiment_id
(e.g., "exp_1")
- Click on
-
Get a Variant:
- Click on
GET /experiments/{experiment_id}/variant
- Click "Try it out"
- Enter your experiment_id
- Click "Execute"
- The API will return a variant to test
- Click on
-
Record a Reward:
- Click on
POST /experiments/{experiment_id}/reward
- Click "Try it out"
- Enter your experiment_id
- Enter reward details:
{ "variant": "blue", "reward": 1 }
- Click "Execute"
- Click on
-
View Results:
- Click on
GET /experiments/{experiment_id}/results
- Click "Try it out"
- Enter your experiment_id
- Click "Execute"
- View the performance of each variant
- Click on
import requests
# Create experiment
response = requests.post(
"http://localhost:8000/experiments/",
json={
"name": "Button Test",
"variants": ["blue", "green", "red"]
}
)
exp_id = response.json()["experiment_id"]
# Get variant
variant = requests.get(
f"http://localhost:8000/experiments/{exp_id}/variant"
).json()["variant"]
# Record reward
requests.post(
f"http://localhost:8000/experiments/{exp_id}/reward",
json={"variant": variant, "reward": 1}
)
# Get results
results = requests.get(
f"http://localhost:8000/experiments/{exp_id}/results"
).json()
print(results)
Run the full test suite with coverage:
pytest --cov=mab_platform --cov-report=term-missing
Run specific test files:
pytest tests/test_api.py
pytest tests/test_platform.py
pytest tests/test_strategies.py
mab-platform/
├── src/mab_platform/ # Main package
│ ├── api/ # FastAPI application
│ ├── core/ # Core MAB implementation
│ └── models/ # Data models
├── tests/ # Test suite
└── examples/ # Usage examples
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite
- Submit a pull request
MIT License