ToggleMesh Python SDK
Project description
ToggleMesh Python SDK (Local Evaluation)
A lightweight, robust Python SDK for evaluating feature flags with ToggleMesh.
This SDK uses Local Evaluation. It connects to the ToggleMesh control plane once to fetch all rules, establishes an SSE (Server-Sent Events) connection to listen for updates, and evaluates all flags locally in-memory without making network requests. This ensures ultra-fast responses (sub-millisecond) suitable for high-throughput backend services.
Installation
pip install togglemesh
Usage
import time
from togglemesh import ToggleMeshClient, ToggleMeshOptions
client = ToggleMeshClient(ToggleMeshOptions(
base_url="http://localhost:5000",
server_key="YOUR_API_KEY"
))
# 1. Check a flag locally (Zero network latency!)
# Pass identity and context per-evaluation, since the server handles multiple users concurrently.
if client.is_enabled("new-feature", default_value=False, identity="user-123", context={"tenant": "acme_corp"}):
print("Feature is ON")
else:
print("Feature is OFF")
# 2. Stop background threads when the app shuts down
client.stop()
Supported Features
- Percentage Rollouts (Murmur3 / FNV-1a hashing)
- Operator matching (Strings, Numbers, Dates, SemVer, Regex)
- Real-time SSE updates
- Contextual Rollouts
- Segment Evaluation
- Analytics Event Tracking (A/B testing conversions):
client.track("checkout_completed", properties={"cart_size": 3}, value=150.0, identity="user-123")
🚀 CLI Tool (Code Generation)
The togglemesh Python package also includes a powerful Command Line Interface for synchronizing feature flags from the control plane and generating strongly-typed Python classes. This eliminates typos and gives you full IDE autocomplete for your flag keys!
1. Setup Configuration
Run the configuration wizard to link the CLI to your ToggleMesh environment.
togglemesh config
2. Generate Typed Flags
Synchronize your flags and output a native Python file containing your flag constants:
togglemesh sync -l python -o ./flags.py
Now you can use the generated Flags class in your code:
from flags import Flags
from togglemesh import ToggleMeshClient, ToggleMeshOptions
# ...
client.is_enabled(Flags.NEW_CHECKOUT_FLOW, default_value=False, identity="user-123")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file togglemesh-0.3.0.tar.gz.
File metadata
- Download URL: togglemesh-0.3.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.15.0b1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
118ee7835cbd288e5d8cdaa90f8c2b1cae8c55c1b636a1a83f82d83eaefa1ffd
|
|
| MD5 |
f70d2ea6f4dd9060e9c2cb2a948bdef5
|
|
| BLAKE2b-256 |
ca4c32650b030be97d205ef0ef1daf150aad0fccde205ce8f014145e073d5697
|
File details
Details for the file togglemesh-0.3.0-py3-none-any.whl.
File metadata
- Download URL: togglemesh-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.15.0b1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7b7f06e2162afd756618525e08a7731a18d2327f107f90439b6d6781ab9d4fa
|
|
| MD5 |
fec48d662c064aa999db6adfd170a849
|
|
| BLAKE2b-256 |
9700f367235e75c28f18bba17858c63cdbf6f8f07455f29d2c6dda6588406a2d
|