Skip to main content

ToggleMesh Python SDK

Project description

ToggleMesh Python SDK (Local Evaluation)

GitHub Repo

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",
    client_key="YOUR_API_KEY"
))

# 1. Identify the user
client.identify("user-123", {"tenant": "acme_corp", "plan": "enterprise"})

# 2. Check a flag locally (Zero network latency!)
if client.is_enabled("new-feature", default_value=False):
    print("Feature is ON")
else:
    print("Feature is OFF")

# 3. 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

togglemesh-0.2.7.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

togglemesh-0.2.7-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file togglemesh-0.2.7.tar.gz.

File metadata

  • Download URL: togglemesh-0.2.7.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0b1

File hashes

Hashes for togglemesh-0.2.7.tar.gz
Algorithm Hash digest
SHA256 c100e2f14f7c1bf87ef0a8478465ee6fcb83faad6bbbc13de30b26b8407cccce
MD5 00ba8e470689dcc0e100e6ee278eaedd
BLAKE2b-256 e4c8d5c51f00d7afe9967f214e1d4ddd52fdcb0a1b4a345a109d84bfaa07f6e1

See more details on using hashes here.

File details

Details for the file togglemesh-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: togglemesh-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0b1

File hashes

Hashes for togglemesh-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b00bb92d5d24f9355d8fcda39fd35dc12ef4c32e054912a82ab725884764e90d
MD5 ad862ee5ec4332fedde46a5732d0b259
BLAKE2b-256 91d7b8aebc96b609934585123ca084b1c040dd44e29dba1492ac5f924104a0a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page