Skip to Content
DocsSdksPython

Python SDK

Official Python SDK for GoGreen feature flags and experimentation. Supports real-time streaming, event tracking, and OpenFeature  provider.

Requirements

  • Python 3.10+
  • GoGreen evaluation API (e.g. https://app.gogreenflags.com)

Installation

From PyPI (when published)

pip install gogreen-sdk

From source (GitHub)

pip install git+https://github.com/MarkDurbin104/GoGreen.git#subdirectory=sdk/python

Or clone and install in editable mode:

git clone https://github.com/MarkDurbin104/GoGreen.git cd GoGreen/sdk/python pip install -e .

Quick start

from gogreen import GoGreenClient from gogreen.config import GoGreenConfig config = GoGreenConfig( sdk_key="YOUR_SDK_KEY", environment_id="YOUR_ENV_ID", default_context={"key": "user-123", "custom": {"plan": "enterprise"}}, api_base_url="https://app.gogreenflags.com", ) client = GoGreenClient(config) client.wait_for_initialization(timeout=5.0) # Boolean flag if client.bool_variation("new-checkout", False): show_new_checkout() # With optional context override user = {"key": "user-456", "custom": {"country": "US"}} theme = client.string_variation("ui-theme", "light", context=user) # Number flag (e.g. for gradual rollouts) limit = client.number_variation("rate-limit", 100) # JSON flag config_value = client.json_variation("feature-config", {}) # Detail (value + variation id, reason, prerequisite_key) detail = client.bool_variation_detail("new-checkout", False) print(detail.value, detail.reason, detail.variation_id) # Track custom events for experimentation client.track("checkout_completed", {"revenue": 49.99}) client.close()

Configuration

ParameterTypeRequiredDescription
sdk_keystrYesSDK key from your GoGreen environment
environment_idstrYesEnvironment ID (e.g. UUID)
default_contextdictYesDefault evaluation context; must include "key"
api_base_urlstrNoEvaluation API base URL (default: http://localhost:8092)
stream_urlstrNoStreaming SSE URL (default: same as api_base_url)
events_urlstrNoEvents ingestion URL (default: same as api_base_url)
enable_streamingboolNoReal-time flag updates via SSE (default: True)
offlineboolNoStart in offline mode (default: False)
bootstrapdictNoInitial flags to skip first fetch
request_timeoutfloatNoHTTP timeout in seconds (default: 10.0)
flush_intervalfloatNoEvent batch flush interval in seconds (default: 30.0)
private_attributeslist[str]NoAttribute names to redact in events (PII)

Evaluating flags

  • Variations: bool_variation, string_variation, number_variation, json_variation — each has a *_variation_detail variant returning value, variation_id, reason, rule_index, prerequisite_key.
  • Lifecycle: wait_for_initialization(timeout=None), initialized(), close()
  • Context: set_context(context), identify(context)
  • Offline: enter_offline_mode(), exit_offline_mode()
  • Events: on(event, handler) / off(event, handler) for "ready", "update", "error"; track(event_key, properties=None)
  • Test helper: GoGreenClient.test_client(flags: dict) for unit tests (offline client with fixed flag values).

OpenFeature provider

from gogreen import GoGreenClient, GoGreenProvider from gogreen.config import GoGreenConfig from openfeature import api config = GoGreenConfig( sdk_key="YOUR_SDK_KEY", environment_id="YOUR_ENV_ID", default_context={"key": "user-123", "custom": {}}, ) client = GoGreenClient(config) api.set_provider(GoGreenProvider(client)) client = api.get_client() value = client.get_boolean_value("my-flag", False)

Testing

# Create an offline test client with predetermined flag values client = GoGreenClient.test_client({ "feature-x": True, "ui-theme": "dark", "rate-limit": 50, }) # Use in tests — no network calls enabled = client.bool_variation("feature-x", False) # returns True