Sift Python Bindings
Bindings for Sift's APIs -- including the [Events](https://developers.sift.com/docs/python/events-api/, Labels, and Score APIs.
Installation
# install from PyPi
pip install Sift
Documentation
Please see here for the most up-to-date documentation.
Changelog
Please see the CHANGELOG for a history of all changes.
Usage
Here's an example:
import sift
client = sift.Client(api_key='<your API key here>', account_id='<your account ID here>')
# User ID's may only contain a-z, A-Z, 0-9, =, ., -, _, +, @, :, &, ^, %, !, $
user_id = "23056"
# Track a transaction event -- note this is a blocking call
properties = {
"$user_id": user_id,
"$user_email": "buyer@gmail.com",
"$seller_user_id": "2371",
"seller_user_email": "seller@gmail.com",
"$transaction_id": "573050",
"$payment_method": {
"$payment_type": "$credit_card",
"$payment_gateway": "$braintree",
"$card_bin": "542486",
"$card_last4": "4444"
},
"$currency_code": "USD",
"$amount": 15230000,
# Identity / KYC signals
"$kyc": {
"$names_match": True,
"$kyc_level": "$basic", # "$basic" or "$full"
"$bin_nationality_match": True,
"$provider": "lexisnexis",
},
# Geo/compliance signals
"$geo": {
"$uuid": "gc-abc-123",
"$provider": "geocomply",
},
# Bot detection signals
"$bot_identification": {
"$result": "$human", # "$bot", "$human", or "$suspected"
"$provider": "datadome",
},
}
try:
response = client.track(
"$transaction",
properties,
)
except sift.client.ApiException:
# request failed
pass
else:
if response.is_ok():
print("Successfully tracked event")
# Track a transaсtion event and receive a score with percentiles in response (sync flow).
# Note: `return_score` or `return_workflow_status` must be set `True`.
properties = {
"$user_id": user_id,
"$user_email": "buyer@gmail.com",
"$seller_user_id": "2371",
"seller_user_email": "seller@gmail.com",
"$transaction_id": "573050",
"$payment_method": {
"$payment_type": "$credit_card",
"$payment_gateway": "$braintree",
"$card_bin": "542486",
"$card_last4": "4444"
},
"$currency_code": "USD",
"$amount": 15230000,
}
try:
response = client.track(
"$transaction",
properties,
return_score=True,
include_score_percentiles=True,
abuse_types=("promotion_abuse", "content_abuse", "payment_abuse"),
)
except sift.client.ApiException:
# request failed
pass
else:
if response.is_ok():
score_response = response.body["score_response"]
print(score_response)
# In order to include `warnings` field to Events API response via calling
# `track()` method, set it by the `include_warnings` param:
try:
response = client.track("$transaction", properties, include_warnings=True)
# ...
except sift.client.ApiException:
# request failed
pass
# Request a score for the user with user_id 23056
try:
response = client.score(user_id)
except sift.client.ApiException:
# request failed
pass
else:
print(response.body)
try:
# Label the user with user_id 23056 as Bad with all optional fields
response = client.label(user_id, {
"$is_bad": True,
"$abuse_type": "payment_abuse",
"$description": "Chargeback issued",
"$source": "Manual Review",
"$analyst": "analyst.name@your_domain.com"
})
except sift.client.ApiException:
# request failed
pass
# Remove a label from a user with user_id 23056
try:
response = client.unlabel(user_id, abuse_type='content_abuse')
except sift.client.ApiException:
# request failed
pass
# Get the status of a workflow run
try:
response = client.get_workflow_status('my_run_id')
except sift.client.ApiException:
# request failed
pass
# Get the latest decisions for a user
try:
response = client.get_user_decisions('example_user')
except sift.client.ApiException:
# request failed
pass
# Get the latest decisions for an order
try:
response = client.get_order_decisions('example_order')
except sift.client.ApiException:
# request failed
pass
# Get the latest decisions for a session
try:
response = client.get_session_decisions('example_user', 'example_session')
except sift.client.ApiException:
# request failed
pass
# Get the latest decisions for a piece of content
try:
response = client.get_content_decisions('example_user', 'example_content')
except sift.client.ApiException:
# request failed
pass
# The send call triggers the generation of a OTP code that is stored by Sift and email/sms the code to the user.
send_properties = {
"$user_id": "billy_jones_301",
"$send_to": "billy_jones_301@gmail.com",
"$verification_type": "$email",
"$brand_name": "MyTopBrand",
"$language": "en",
"$site_country": "IN",
"$event": {
"$session_id": "SOME_SESSION_ID",
"$verified_event": "$login",
"$verified_entity_id": "SOME_SESSION_ID",
"$reason": "$automated_rule",
"$ip": "192.168.1.1",
"$browser": {
"$user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
}
}
}
try:
response = client.verification_send(send_properties)
except sift.client.ApiException:
# request failed
pass
# The resend call generates a new OTP and sends it to the original recipient with the same settings.
resend_properties = {
"$user_id": "billy_jones_301",
"$verified_event": "$login",
"$verified_entity_id": "SOME_SESSION_ID"
}
try:
response = client.verification_resend(resend_properties)
except sift.client.ApiException:
# request failed
pass
# The check call is used for verifying the OTP provided by the end user to Sift.
check_properties = {
"$user_id": "billy_jones_301",
"$code": 123456,
"$verified_event": "$login",
"$verified_entity_id": "SOME_SESSION_ID"
}
try:
response = client.verification_check(check_properties)
except sift.client.ApiException:
# request failed
pass
Metadata
Release files for Sift 6.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sift-6.1.0.tar.gz | 21.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sift-6.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.8 kB
Release files / sift-6.1.0.tar.gz
| Download URL | sift-6.1.0.tar.gz |
|---|---|
| Size | 21.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
669b39041d21f45473f9c6c991a8b247e552ae6646e228f80af0064f5ece5c3b
|
|
BLAKE2b-256 checksum How to use checksums |
0b4e067180a7f2200d22e2b14db1a0ba7ac00cd01b9ead3741a1bbbbf7969c16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / sift-6.1.0-py3-none-any.whl
| Download URL | sift-6.1.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97e753c17bd4adcb89d5d486d787166ff443a035615841b733b73198f9ef1e9c
|
|
BLAKE2b-256 checksum How to use checksums |
2ce77a238f5bfdb160917796bf8fe437d6c39482602fbbbba4c9955755b37033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for Sift 6.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.