Sift Science Python API Client

6.0.0 · active · verified Thu Apr 16

The `sift` library provides Python bindings for interacting with the Sift Science API, which offers real-time fraud prevention and risk assessment. It enables developers to send event data, retrieve scores and decisions, and manage labels. The library is actively maintained, with version 6.0.0 as the current release, and follows a regular release cadence to support new Python versions and API features.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the Sift client using your API key and Account ID, then demonstrate sending a `$login` event and fetching user decisions. Authentication details are expected via environment variables for security.

import os
import sift

# Ensure API_KEY and ACCOUNT_ID are set as environment variables
api_key = os.environ.get('SIFT_API_KEY', 'YOUR_API_KEY')
account_id = os.environ.get('SIFT_ACCOUNT_ID', 'YOUR_ACCOUNT_ID')

if api_key == 'YOUR_API_KEY' or account_id == 'YOUR_ACCOUNT_ID':
    print("WARNING: Please set SIFT_API_KEY and SIFT_ACCOUNT_ID environment variables or replace placeholders.")

client = sift.Client(api_key=api_key, account_id=account_id)

# Example: Send a $login event
try:
    response = client.track(
        event={
            '$type': '$login',
            '$user_id': 'billy_jones_301',
            '$session_id': 'gigtleqlbrcssi8tghzz2w4w2',
            '$login_status': '$success',
            '$user_email': 'billy_jones@example.com',
            '$ip': '128.148.1.10'
        }
    )
    print("Login event sent successfully:", response)
except sift.client.ApiException as e:
    print(f"Error sending login event: {e}")

# Example: Get decisions for a user
try:
    user_decisions = client.get_user_decisions('billy_jones_301')
    print("User decisions:", user_decisions)
except sift.client.ApiException as e:
    print(f"Error fetching user decisions: {e}")

view raw JSON →