Skip to content
  • There are no suggestions because the search field is empty.

Python Quickstart

Get Running with the Convert Python SDK in 5 Minutes

Author: Ahmed Abbas

THIS ARTICLE WILL HELP YOU:


Overview

The Convert Python SDK enables you to run Full Stack experiments and feature flags directly from your Python applications.

This quickstart demonstrates how to initialize the SDK using Direct Configuration, which requires no SDK key and performs no network requests. This approach is ideal for local development, testing, and offline environments.

For production deployments, you can initialize the SDK using an SDK key to automatically download the latest configuration from Convert.

1. Install the SDK

Install the SDK with pip:

pip install convert-python-sdk

Python 3.9 or later is required.

2. Initialize the SDK

Create a configuration object and initialize the SDK:

from convert_sdk import Core, SDKConfig

core = Core(
    SDKConfig(data=config_data)
).initialize()

assert core.is_ready

Initialization is synchronous and returns a ready-to-use SDK instance.

3. Create a Visitor Context

Create a visitor context before evaluating experiments.

context = core.create_context(
    "visitor-001",
    visitor_attributes={
        "country": "US",
        "plan": "pro"
    }
)

A visitor context represents a single visitor and can optionally include attributes used for audience targeting.

4. Run an Experiment

Use the experience key configured in Convert.

result = context.run_experience(
    "checkout-experiment"
)

if result is not None:
    print(result.variation_key)

If the visitor qualifies, the SDK returns an ExperienceResult. Otherwise, it returns None, which is an expected outcome and not an error.

5. Track a Conversion

Record a conversion using the goal key configured in Convert.

context.track_conversion(
    "purchase_completed",
    revenue=49.99
)

Conversions are queued locally and can be flushed later.

6. Flush and Close

Before your application exits, flush queued events and release SDK resources.

core.flush()
core.close()

For short-lived scripts, using the SDK as a context manager automatically performs cleanup.

Complete Example

from convert_sdk import Core, SDKConfig

core = Core(
    SDKConfig(data=config_data)
).initialize()

context = core.create_context("visitor-001")

result = context.run_experience("checkout-experiment")

if result:
    print(result.variation_key)

context.track_conversion(
    "purchase_completed",
    revenue=49.99
)

core.flush()
core.close()

Next Steps

To learn more about advanced SDK features, see the developer documentation:

  • Installation – Python version requirements and installation options
  • Initialization – Direct configuration and SDK key initialization
  • Configuration – Available SDK configuration options
  • Running Experiences – Experience evaluation in detail
  • Running Features – Feature flag evaluation
  • Tracking Conversions – Revenue tracking and deduplication
  • Code Examples – Complete implementation examples

Developer documentation:
https://docs.developers.convert.com/docs/python-quickstart