Skip to main content

Ople Python Client

Project description

Ople Client

Table of Contents

  1. Overview
  2. Installation and Setup
  3. Python Client
  4. Terminal Client

Overview

Ople has created two clients to simplify the integration with your codebase and help you be more productive. You can use the python client to connect to your Ople models with your python code. You can also leverage the ople-client command to make predictions directly from the terminal.

Installation and Setup

  1. Install python3
  2. Run pip3 install ople (If it doesnt work run python3 -m pip install ople)
  3. Setup ENV variables to make the workflow easier
    1. Run export OPLE_KEY="<YOUR OPLE_KEY>"
    2. Run export OPLE_SECRET="<YOUR OPLE_SECRET>"
    3. Run export OPLE_MODEL_ID="<YOUR OPLE_MODEL_ID>"
  4. If you want to use S3 to get data then you need to setup aws
    1. Run export AWS_KEY="<YOUR AWS_KEY>"
    2. Run export AWS_SECRET="<YOUR AWS_SECRET>"

Python Client

Use the python code snippet below. All you need to update is the code for getting the input. The client handles the following inputs:

  • Dictionary with S3 information: '{"bucket": "<YOUR BUCKET>", "path": "<YOUR S3 FILEPATH>"}'`
  • Path to Local CSV File
  • String in CSV format
  • Dictioanry in Ople Format: '{"columns": [<YOUR COLUMNS>], "rows": [[<YOUR ROW>]]}'
  • Pandas DataFrame

Here is the code snippet:

from ople.client import OpleClient
import os

# ****************************************************

input = "<YOUR CODE TO GET INPUT>"

# ****************************************************

# Specify what model to run
ople_key = os.environ['OPLE_KEY']
ople_secret = os.environ['OPLE_SECRET']
ople_model_id = os.environ['OPLE_MODEL_ID']


# OPTIONAL Parameters to use S3 to upload
aws_key = os.environ['AWS_KEY']
aws_secret = os.environ['AWS_SECRET']

# Connect to Specified Model
if aws_key or aws_key:
    model = OpleClient(ople_key, ople_secret, ople_model_id)
else:
    model = OpleClient(ople_key, ople_secret, ople_model_id, aws_key, aws_secret)

# Specify Prediction Parameters
shap = False
global_shap = False
allow_unknown_categories = True

# Make a Prediction with model
result = model.predict(input,
              shap=shap,
              global_shap=global_shap,
              allow_unknown_categories=allow_unknown_categories)

Terminal Client

To run the terminal client you need to follow the installation and setup steps above. After that you will be able to run the ople-client command. Here are the parameters you can specify:

  • '-s', '--shap': This flag returns the shap values for each predictions
  • '-g', '--global_shap': This flag returns the Global Shap values for each predictions
  • '-u', '--allow_unknown_categories': This flag
  • '-K', '--key': This will set the ople key to whatever comes after it
  • '-S', '--secret': : This will set the ople secret to whatever comes after it
  • '-ID', '--model_id': : This will set the model_id to whatever comes after it
  • '-AS', '--aws_secret': : This will set the AWS secret to whatever comes after it
  • '-AK', '--aws_key': : This will set the AWS key to whatever comes after it

Here are some examples of how to run the command:

ople-client -u -s -g '<YOUR FILE PATH>/<FILENAME>'

ople-client -u -s -g '{"bucket": "<YOUR BUCKET>", "path": "<YOUR S3 FILEPATH>"}'

ople-client -u -s -g '<YOUR CSV STRING>'

ople-client -u -s -g '{"columns": [<YOUR COLUMNS>], "rows": [[<YOUR ROW>]]}'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ople, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size ople-1.0.1-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page