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 deployramp

Requires 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

FunctionParametersReturnsDescription
initconfig: SdkConfig public_token: str, optional base_url, traitsNoneInitializes the SDK with your project token and optional default traits.
flagname: str, trait_overrides: dict | None = NoneboolEvaluates a feature flag. Returns False if the SDK is not initialized.
set_traitstraits: dict[str, str]NoneReplaces the current global traits.
reporterror: Exception | str, flag_name: str | None = None, trait_overrides: dict | None = NoneNoneReports an error for auto-rollback correlation.
closeNoneFlushes pending evaluations and disconnects the WebSocket.

We use cookies to analyze site usage and improve your experience.