Python SDK
Install and integrate the ABMeter Python SDK
Installation
Install the abmeter package from PyPI:
pip install abmeterPython 3.11 or newer is required.
Configuration
Configure the SDK once at application startup. In a Django project this typically goes in an AppConfig.ready() hook or a settings module:
import os
import abmeter
abmeter.configure(api_key=os.environ["ABMETER_API_KEY"])
The api_key is required. You can find or create API keys on the
API Keys page (available after signing in).
Core Concepts
Parameters represent feature variations - a parameter has a set of possible values assigned to users through experiments or feature flags. Use resolve_parameter to get the value for a specific user.
Events are user actions you want to measure - page views, purchases, clicks. Track them with track_event to analyze how parameter variations affect user behavior.
Users are identified by a user_id - the randomization unit the SDK hashes to assign parameter values randomly across your users but consistently for each one, so the same user_id always sees the same variation (no stored state, no network call). A "user" is your end-user - a customer, visitor, or account - and user_id can be any string you choose (a customer id, visitor id, account id). An optional email may be provided; ABMeter uses it only for audience rules that target email patterns (e.g. @acme.com), never for identity or bucketing.
Resolve a Parameter
Create a user and resolve a parameter to get the assigned value:
user = abmeter.User(user_id="user-123")
value = abmeter.resolve_parameter(user, "checkout-button-color")
# => "blue" (the assigned variant's value for this parameter)
The return value is the parameter value from the variant assigned to this user. If no experiment or feature flag controls the parameter, the method returns None.
email is optional and safe to omit - do so for anonymous or server-side users, such as front-end visitors keyed by a cookie id. Leaving it out raises no error: a user with no email simply never matches an audience that targets email patterns, so email-predicate feature flags and experiments don't apply to them. Every other path (random experiments, user-list audiences, event tracking) uses user_id alone. Pass an email only when you use email-pattern audiences: abmeter.User(user_id="user-123", email="[email protected]").
Track an Event
Record user actions to measure the impact of your experiments:
abmeter.track_event("purchase", user.user_id, {"price": 49.99, "currency": "USD"})Events are queued and submitted asynchronously in batches, so tracking calls are fast and non-blocking. The third argument is a data dict with any properties relevant to your metrics.
Full Example
A realistic Django class-based view showing parameter resolution and event tracking together:
import abmeter
from django.views import View
from django.shortcuts import redirect, render
class CheckoutView(View):
def get(self, request):
button_color = self._resolve_button_color(request.user)
return render(request, "checkout/show.html", {"button_color": button_color})
def post(self, request):
order = Order.objects.create(user=request.user, **self._order_params(request))
abmeter.track_event("purchase", str(request.user.id), {
"price": float(order.total),
"currency": order.currency,
})
return redirect("order_detail", order_id=order.id)
def _resolve_button_color(self, user):
abmeter_user = abmeter.User(
user_id=str(user.id),
email=user.email, # optional, only used for email-predicate audiences
)
return abmeter.resolve_parameter(abmeter_user, "checkout-button-color") or "green" # fallback if no experiment is runningNext Steps
- Quick Start Guide → - MCP-guided setup for managing experiments with AI
- Setup MCP Connection → - Connect ABMeter to Claude or other MCP clients