Skip to main content

The official Amplitude Experiment Python SDK for server-side instrumentation.

Project description


PyPI version

Experiment Python SDK

Amplitude Python Server SDK for Experiment.

Installation

pip install amplitude-experiment

Remote Evaluation Quick Start

from amplitude_experiment import Experiment, RemoteEvaluationConfig, RemoteEvaluationClient, User

# (1) Get your deployment's API key
apiKey = 'YOUR-API-KEY'

# (2) Initialize the experiment remote evaluation
experiment = Experiment.initialize_remote(api_key)

# (3) Fetch variants for a user
user = User(
    device_id="abcdefg",
    user_id="user@company.com",
    user_properties={
        'premium': True
    }
)

# (4) Lookup a flag's variant
#
# To fetch synchronous
variants = experiment.fetch(user)
variant = variants['YOUR-FLAG-KEY']
if variant:
    if variant.value == 'on':
        # Flag is on
    else:
        # Flag is off

# To fetch asynchronous
experiment.fetch_async(user, fetch_callback)

def fetch_callback(user, variants):
    variant = variants['YOUR-FLAG-KEY']
    if variant:
        if variant.value == 'on':
            # Flag is on
        else:
            # Flag is off

Local Evaluation Quick Start

# (1) Initialize the local evaluation client with a server deployment key.
experiment = Experiment.initialize_local(api_key)

# (2) Start the local evaluation client.
experiment.start()

# (3) Evaluate a user.
user = User(
    device_id="abcdefg",
    user_id="user@company.com",
    user_properties={
        'premium': True
    }
)
variants = experiment.evaluate(user)

Running Unit Tests Suite

To setup for running test on local, create a .env file with following contents, and replace {API_KEY} and {SECRET_KEY} (or {EU_API_KEY} and {EU_SECRET_KEY} for EU data center) for the project in test:

API_KEY={API_KEY}
SECRET_KEY={SECRET_KEY}

More Information

Please visit our :100:Developer Center for more instructions on using our the SDK.

See our Experiment Python SDK Docs for a list and description of all available SDK methods.

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.

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

amplitude_experiment-1.11.0.tar.gz (89.0 kB view details)

Uploaded Source

Built Distribution

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

amplitude_experiment-1.11.0-py3-none-any.whl (127.1 kB view details)

Uploaded Python 3

File details

Details for the file amplitude_experiment-1.11.0.tar.gz.

File metadata

  • Download URL: amplitude_experiment-1.11.0.tar.gz
  • Upload date:
  • Size: 89.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for amplitude_experiment-1.11.0.tar.gz
Algorithm Hash digest
SHA256 d404eab11c6f2b12c2438e87396661e6e7f3cc74e41272150aabc83cb9af9aab
MD5 8f74900acf93fbbb9668a29b598d6504
BLAKE2b-256 61c05655324150a4f68a579312d31a87c7453e4fe103a3bd845755ec09085b02

See more details on using hashes here.

Provenance

The following attestation bundles were made for amplitude_experiment-1.11.0.tar.gz:

Publisher: publish-to-pypi.yml on amplitude/experiment-python-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file amplitude_experiment-1.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for amplitude_experiment-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1278a84a0a060dfe672882903acfce17893f747e07753306e2b0ead34fe1c7a7
MD5 ddf9de15717fe698fa5499044991cb63
BLAKE2b-256 22ca250d19edfee55f6b5cc5e005fbc2986a6cafe1f22563564dfbbddc5d1d7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for amplitude_experiment-1.11.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on amplitude/experiment-python-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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