Skip to main content


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.

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.12.0.tar.gz (89.3 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.12.0-py3-none-any.whl (127.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: amplitude_experiment-1.12.0.tar.gz
  • Upload date:
  • Size: 89.3 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.12.0.tar.gz
Algorithm Hash digest
SHA256 ad0631e86c7e93f2ecc5e6cb305cde530e4aabd67432e6c91abca112476abc88
MD5 de53fda0eca9819709e5fc51957d2132
BLAKE2b-256 0955208cc7531c0e237a959ea2c48f664e8fe232e33f6c0b3b830cb94c0a2868

See more details on using hashes here.

Provenance

The following attestation bundles were made for amplitude_experiment-1.12.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.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for amplitude_experiment-1.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c539e727d58858990dd6ed6429ed90d2a72f4b3bddab69ce1a327c50e5b9fd2
MD5 d4fef24a71d025e16cb4b64fb0b397cc
BLAKE2b-256 86dadaf250e98ad767e65e11802eab8daee07290de2b222712bd17f7867e4360

See more details on using hashes here.

Provenance

The following attestation bundles were made for amplitude_experiment-1.12.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 Sentry Error logging StatusPage Status page