Code Monkey home page Code Monkey logo

sift-python's Introduction

Sift Science Python Bindings

Bindings for Sift Science's Events, Labels, and Score APIs.

Installation

Set up a virtual environment with virtualenv (otherwise you will need to make the pip calls as sudo): :

virtualenv venv
source venv/bin/activate

Get the latest released package from pip:

Python 2: :

pip install sift

Python 3: :

pip3 install sift

or install newest source directly from GitHub:

Python 2: :

pip install git+https://github.com/SiftScience/sift-python

Python 3: :

pip3 install git+https://github.com/SiftScience/sift-python

Usage

Here's an example:

import sift.client

sift.api_key = '<your api key here>'
client = sift.Client()

user_id= "23056"    # User ID's may only contain a-z, A-Z, 0-9, =, ., -, _, +, @, :, &, ^, %, !, $

# Track a transaction event -- note this is blocking
event = "$transaction"

properties = {
  "$user_id" : user_id, 
  "$user_email" : "[email protected]", 
  "$seller_user_id" : "2371", 
"seller_user_email" : "[email protected]", 
  "$transaction_id" : "573050", 
  "$payment_method" : {
    "$payment_type"    : "$credit_card",
    "$payment_gateway" : "$braintree",
    "$card_bin"        : "542486",
    "$card_last4"      : "4444"             
}, 
"$currency_code" : "USD",
"$amount" : 15230000,
}

response = client.track(event, properties)


response.is_ok()  # returns True of False

print response # prints entire response body and http status code


# Request a score for the user with user_id 23056
response = client.score(user_id)

# Label the user with user_id 23056 as Bad with all optional fields
response = client.label(user_id,{ "$is_bad" : True, "$reasons" : ["$chargeback", ], "$description" : "Chargeback issued", "$source" : "Manual Review", "$analyst" : "analyst.name@your_domain.com"})

Testing

Before submitting a change, make sure the following commands run without errors from the root dir of the repository:

PYTHONPATH=. python tests/client_test.py
PYTHONPATH=. python3 tests/client_test.py

sift-python's People

Contributors

alvinchow86 avatar berndverst avatar bstein-sift avatar cbcase avatar divad12 avatar eviegillie avatar miped avatar yschatzberg avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.