Created
December 1, 2021 14:26
-
-
Save sroecker/71e1544d4417d5872ba081f8471875de to your computer and use it in GitHub Desktop.
Simple Python client for the Paxata REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import collections | |
class BearerAuth(requests.auth.AuthBase): | |
def __init__(self, token): | |
self.token = token | |
def __call__(self, r): | |
r.headers['Authorization'] = 'Bearer ' + self.token | |
return r | |
class PaxataClient: | |
def __init__(self, paxata_url, paxata_token): | |
self.PAXATA_URL = paxata_url | |
self.PAXATA_TOKEN = paxata_token | |
def get_users(self): | |
get_request = (self.PAXATA_URL + '/users') | |
resp = requests.get(get_request, auth=BearerAuth(self.PAXATA_TOKEN)) | |
json_data = [] | |
if(resp.ok): | |
json_data = json.loads(resp.content) | |
return json_data | |
def list_datasets(self, state='DONE'): | |
get_request = (PAXATA_URL + "/library/data?state="+state) | |
resp = requests.get(get_request, auth=BearerAuth(PAXATA_TOKEN)) | |
json_data = [] | |
if(resp.ok): | |
json_data = json.loads(resp.content) | |
return json_data | |
def get_dataset(self, dataset_id): | |
post_request = (PAXATA_URL + "/datasource/exports/local/" + dataset_id + "?format=json") | |
resp = requests.post(post_request, auth=BearerAuth(PAXATA_TOKEN)) | |
json_data = [] | |
if(resp.ok): | |
json_data = json.loads(resp.content, object_pairs_hook=collections.OrderedDict) | |
return json_data | |
PAXATA_URL = 'https://datarobot.paxata.com/rest' | |
PAXATA_TOKEN = 'YOUR_TOKEN' | |
pc = PaxataClient(PAXATA_URL, PAXATA_TOKEN) | |
users = pc.get_users() | |
print(json.dumps(users, indent=4)) | |
datasets = pc.list_datasets() | |
print(json.dumps(datasets, indent=4)) | |
#test_file = pc.get_dataset('dataset_id') | |
#print(json.dumps(test_file, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment