Python SDK
The DeployRamp Python SDK lets you evaluate feature flags, set user traits, and report errors for automatic rollback in any Python 3.10+ application.
Installation
pip install deployrampRequires Python 3.10 or later.
Initialization
Import the deployramp module and call init() with an SdkConfig. Optionally pass initial traits that will be sent with every flag evaluation.
import deployramp
deployramp.init(deployramp.SdkConfig(
public_token="pk_live_abc123",
traits={"plan": "pro", "region": "us-east"},
))Evaluating Flags
Use flag() to check whether a feature is enabled. It returns False if the SDK has not been initialized. You can pass trait overrides to evaluate the flag for a different context without changing the global traits.
if deployramp.flag("new-checkout"):
render_new_checkout()
else:
render_old_checkout()
# With trait overrides
enabled = deployramp.flag("beta-feature", trait_overrides={"role": "admin"})Setting Traits
Call set_traits() to replace the current global traits. These traits are sent with every subsequent flag evaluation.
deployramp.set_traits({"plan": "enterprise", "region": "eu-west"})Error Reporting
Report errors to DeployRamp so it can correlate failures with flag states and trigger automatic rollbacks when error rates spike.
try:
process_payment()
except Exception as e:
deployramp.report(e, flag_name="new-checkout")Shutdown
Call close() before your process exits to flush pending evaluations and disconnect the WebSocket connection.
deployramp.close()API Reference
| Function | Parameters | Returns | Description |
|---|---|---|---|
init | config: SdkConfig — public_token: str, optional base_url, traits | None | Initializes the SDK with your project token and optional default traits. |
flag | name: str, trait_overrides: dict | None = None | bool | Evaluates a feature flag. Returns False if the SDK is not initialized. |
set_traits | traits: dict[str, str] | None | Replaces the current global traits. |
report | error: Exception | str, flag_name: str | None = None, trait_overrides: dict | None = None | None | Reports an error for auto-rollback correlation. |
close | — | None | Flushes pending evaluations and disconnects the WebSocket. |