Link Search Menu Expand Document

SDK

A software development kit for interacting with Matatika services.


Installation

Prerequisites

  • Python >=3.7
  • pip

The Matatika CLI/SDK is available through PyPi here and can be installed using pip:

pip install matatika

You can check if the CLI/SDK installed successfully by running the following command:

matatika --version

The available classes and methods are documented below.


matatika.library

library module

MatatikaClient Objects

class MatatikaClient()

Class to handle client context

Arguments:

  • auth_token str - Authentication token
  • endpoint_url str - Endpoint URL
  • workspace_id str - Workspace ID

Example:

# create 'auth_token', 'endpoint_url' and 'workspace-id' variables

client = Matatika(auth_token, endpoint_url, workspace_id)

auth_token

 | @property
 | auth_token() -> str

Gets the client auth token

Returns:

  • str - Client auth token

Example:

# create MatatikaClient object

auth_token = client.auth_token
print(auth_token)

endpoint_url

 | @property
 | endpoint_url() -> str

Gets the client endpoint URL

Returns:

  • str - Client endpoint URL

Example:

# create MatatikaClient object

endpoint_url = client.endpoint_url
print(endpoint_url)

workspace_id

 | @property
 | workspace_id() -> str

Gets the client workspace URL

Returns:

  • str - Client workspace URL

Example:

# create MatatikaClient object

workspace_id = client.workspace_id
print(workspace_id)

auth_token

 | @auth_token.setter
 | auth_token(value: str)

Sets the client authentication token

Arguments:

  • value str - Authentication token

Example:

# create MatatikaClient object
# create 'auth_token' variable

client.auth_token = auth_token
print(client.auth_token)

endpoint_url

 | @endpoint_url.setter
 | endpoint_url(value: str)

Sets the client endpoint URL

Arguments:

  • value str - Endpoint URL

Example:

# create MatatikaClient object
# create 'endpoint_url' variable

client.endpoint_url = endpoint_url
print(client.endpoint_url)

workspace_id

 | @workspace_id.setter
 | workspace_id(value: str)

Sets the client workspace ID

Arguments:

  • value str - Workspace ID

Example:

# create MatatikaClient object
# create 'workspace_id' variable

client.workspace_id = workspace_id
print(client.workspace_id)

profile

 | profile() -> dict

Gets the authenticated user profile

Returns:

  • dict - Authenticated user profile

Example:

# create MatatikaClient object

profile = client.profile()

print(profile['id'])
print(profile['name'])
print(profile['email'])

publish

 | publish(datasets: List[Dataset]) -> List[Tuple[Dataset, int]]

Publishes datasets

Arguments:

  • datasets List[Dataset] - Datasets to publish

Returns:

  • List[Tuple[Dataset,int]] - Published datasets and status actions

Example:

# create MatatikaClient object
# create 'datasets' variable

responses = client.publish(datasets)

for dataset, status_code in responses:
    print(
        f"[{status_code}]\tSuccessfully published the dataset {dataset.dataset_id}")

list_resources

 | list_resources(resource: Resource) -> Union[list, None]

Lists all available resources of the specified type

Arguments:

  • resource_type Resource - Resource type to return (workspaces/datasets)

Returns:

  • Union[list,None] - Available resources

Examples:

List all workspaces

# create MatatikaClient object

from matatika.types import Resource

workspaces = client.list_resources(Resource.WORKSPACE)

for workspace in workspaces:
    print(workspace['id'], workspace['name'], workspace['domains'])

List all datasets in the workspace provided upon client object instantiation

# create MatatikaClient object

from matatika.types import Resource

datasets = client.list_resources(Resource.DATASET)

for dataset in datasets:
    print(dataset['id'], dataset['alias'], dataset['title'])

List all datasets in the workspace ‘c6db37fd-df5e-4ac6-8824-a4608932bda0’

# create MatatikaClient object

client.workspace_id = '8566fe13-f30b-4536-aecf-b3879bd0910f'
datasets = client.list_resources('datasets')

for dataset in datasets:
    print(dataset['id'], dataset['alias'], dataset['title'])

delete_resources

 | delete_resources(resource_type: Resource, *resource_ids) -> None

Deletes a resource of the specified type

Arguments:

  • resource_type Resource - Resource type to delete (dataset)
  • resource_id str - Resource ID

Returns:

None

Examples:

Delete a workspace

# create MatatikaClient object
# create 'workspace_id' variable

from matatika.types import Resource

client.delete_resources(Resource.WORKSPACE, workspace_id)
print(f"Successfully deleted workspace {workspace_id}")

Delete multiple workspaces

# create MatatikaClient object
# create 'workspace1_id', 'workspace2_id' and 'workspace3_id' variables

from matatika.types import Resource

client.delete_resources(Resource.WORKSPACE, workspace1_id, workspace2_id, workspace3_id)
print(f"Successfully deleted workspaces: {workspace1_id}, {workspace2_id}, {workspace3_id}")

Delete a dataset

# create MatatikaClient object
# create 'dataset_id' variable

from matatika.types import Resource

client.delete_resources(Resource.DATASET, dataset_id)
print(f"Successfully deleted dataset {dataset_id}")

Delete multiple datasets

# create MatatikaClient object
# create 'dataset1_id', 'dataset2_id' and 'dataset3_id' variables

from matatika.types import Resource

client.delete_resources(Resource.DATASET, dataset1_id, dataset2_id, dataset3_id)
print(f"Successfully deleted datasets: {dataset1_id}, {dataset2_id}, {dataset3_id}")

fetch

 | fetch(dataset_id_or_alias: str, data_format: DataFormat = None) -> Union[dict, list, str]

Fetches the data of a dataset using the query property

Arguments:

  • dataset_id_or_alias str - Dataset ID or alias
  • data_format DataFormat, optional - Format to return the data as (defaults to a native Python object)

Returns:

  • Union[dict,list,str] - Dataset data

Examples:

Fetch data as a native Python object

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

data = client.fetch(dataset_id_or_alias)

if data:
    print(data)
else:
    print(f"No data was found for dataset {dataset_id_or_alias}")

Fetch data as a raw string

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

from matatika.types import DataFormat

data = client.fetch(dataset_id_or_alias, data_format=DataFormat.RAW)

if data:
    print(data)
else:
    print(f"No data was found for dataset {dataset_id_or_alias}")

Fetch data formatted as per the Chart.js specification

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

from matatika.types import DataFormat

data = client.fetch(dataset_id_or_alias,
                    data_format=DataFormat.CHARTJS)

if data:
    print(data)
else:
    print(f"No data was found for dataset {dataset_id_or_alias}")

Fetch data in CSV format

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

from matatika.types import DataFormat

data = client.fetch(dataset_id_or_alias, data_format=DataFormat.CSV)

if data:
    print(data)
else:
    print(f"No data was found for dataset {dataset_id_or_alias}")

get_dataset

 | get_dataset(dataset_id_or_alias: str, raw: bool = False) -> Dataset

Gets a dataset

Arguments:

  • dataset_id_or_alias(str) - Dataset ID or alias raw(bool, optional): Whether to return the dataset as a raw string or not (defaults to False)

Returns:

  • Dataset - Dataset object

Examples:

Fetch a dataset as a Dataset object

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

dataset = client.get_dataset(dataset_id_or_alias)
print(dataset)

Fetch a dataset as a raw string

# create MatatikaClient object
# create 'dataset_id_or_alias' variable

dataset = client.get_dataset(dataset_id_or_alias, raw=True)
print(dataset)