Skip to content

Workday/prism-python

Repository files navigation

Python package

Prism-Python

Python client library for interacting with Workday’s Prism API V2.

Install

You may install the latest version directly from GitHub with:

pip install git+git://github.com/Workday/prism-python.git

It is also possible to install a specific tagged release with:

pip install git+git://github.com/Workday/prism-python.git@0.2.0

Requirements

  1. Register a Workday Prism Analytics API Client.

In Workday, register an integrations API client with Prism Analytics as its scope. Obtain the Client ID, Client Secret, and Refresh Token values that the Prism class requires as parameters.

  1. Obtain the Workday REST API Endpoint.

In Workday, obtain the Workday REST API endpoint that the Prism class requires as a parameter.

  1. For ease of use, set the following environment variables using the values obtained above:
export workday_base_url=<INSERT WORKDAY BASE URL HERE>
export workday_tenant_name=<INSERT WORKDAY TENANT NAME HERE>
export prism_client_id=<INERT PRISM CLIENT ID HERE>
export prism_client_secret=<INSERT PRISM CLIENT SECRET HERE>
export prism_refresh_token=<INSERT PRISM REFRESH TOKEN HERE>

Example: Create a new table with Prism API Version 2

import os
import prism

# initialize the prism class with your credentials
p = prism.Prism(
    os.getenv("workday_base_url"),
    os.getenv("workday_tenant_name"),
    os.getenv("prism_client_id"),
    os.getenv("prism_client_secret"),
    os.getenv("prism_refresh_token"),
    version="v2"
)

# create the bearer token
p.create_bearer_token()

# read in your table schema
schema = prism.load_schema("/path/to/schema.json")

# create an empty API table with your schema
table = p.create_table('my_new_table', schema=schema['fields'])

# get the details about the newly created table
details = p.describe_table(table['id'])

# convert the details to a bucket schema
bucket_schema = p.convert_describe_schema_to_bucket_schema(details)

# create a new bucket to hold your file
bucket = p.create_bucket(bucket_schema, table['id'], operation="TruncateandInsert")

# add your file the bucket you just created
p.upload_file_to_bucket(bucket["id"], "/path/to/file.csv.gz")

# complete the bucket and upload your file
p.complete_bucket(bucket["id"])

# check the status of the bucket you just completed
status = p.list_bucket(bucket["id"])
print(status.get('errorMessage'))

Example: Manage data in an existing table with Prism API Version 2

Table Operations Available - “TruncateandInsert”, “Insert”, “Update”, “Upsert”, “Delete”.

To use the Update/Upsert/Delete operations you must specify an external id field within your table schema.

import os
import prism

# initialize the prism class with your credentials
p = prism.Prism(
    os.getenv("workday_base_url"),
    os.getenv("workday_tenant_name"),
    os.getenv("prism_client_id"),
    os.getenv("prism_client_secret"),
    os.getenv("prism_refresh_token"),
    version="v2"
)

# create the bearer token
p.create_bearer_token()

# look through all of the existing tables to find the table you intend to append
all_tables = p.list_table()
for table in all_tables['data']:
    if table['name'] == "my_new_table":
        print(table)
        break

# get the details about the newly created table
details = p.describe_table(table['id'])

# convert the details to a bucket schema
bucket_schema = p.convert_describe_schema_to_bucket_schema(details)

# create a new bucket to hold your file
bucket = p.create_bucket(bucket_schema, table['id'], operation="Insert")

# add your file to the bucket you just created
p.upload_file_to_bucket(bucket["id"], "/path/to/file.csv.gz")

# complete the bucket and upload your file
p.complete_bucket(bucket["id"])

# check the status of the bucket you just completed
status = p.list_bucket(bucket["id"])
print(status.get('errorMessage'))

Bugs

Please report any bugs that you find here. Or, even better, fork the repository on GitHub and create a pull request (PR). We welcome all changes, big or small, and we will help you make the PR if you are new to git.

License

Released under the Apache-2.0 license (see LICENSE)

About

Python client library for interacting with Workday’s Prism API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages