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.1.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.1-py3-none-any.whl (127.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: amplitude_experiment-1.11.1.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.1.tar.gz
Algorithm Hash digest
SHA256 54ac4ec07646e7f82c66a5506093d33b2aff327aebfb3c1e9a6723545cdb73f4
MD5 d90f80d12ed6f06f09b5f3f8b1667641
BLAKE2b-256 059f3af827a76be5aa9fb6e4de959e5b1d6abd18f05fa9beccab3a9919d829f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for amplitude_experiment-1.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b638434afa5dc706b1f56a872b862f13ab27169a43874725fae5540472fb9e6
MD5 f1f0f637028c556b3837a3b465c18c3d
BLAKE2b-256 6f392981cf34c9d1759e2b3080d49b3c0a97838cdc51edfa8f3f368470f194fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for amplitude_experiment-1.11.1-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