Rapid
Rapid
__init__(auth=None)
The rAPId class is the main SDK class for the rAPId API. It acts as a wrapper for the various API endpoints, providing a simple and intuitive programmatic interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
int
|
An instance of the rAPId auth class, which is used for authentication and authorization with the API. Defaults to None. |
None
|
convert_dataframe_for_file_upload(df)
Converts a pandas DataFrame to a format that can be used for file uploads to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to convert. |
required |
Returns:
| Type | Description |
|---|---|
|
A dictionary containing the converted DataFrame in a format suitable for file uploads to the API. |
create_client(client_name, client_permissions)
Creates a new client on the API with the specified permissions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_name
|
str
|
The name of the client to create. |
required |
client_permissions
|
list[str]
|
The permissions of the client to create. |
required |
Raises:
| Type | Description |
|---|---|
InvalidPermissionsException
|
If an error occurs while trying to create the client. |
create_protected_domain(name)
Creates a new protected domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the protected domain to create. |
required |
Raises:
| Type | Description |
|---|---|
InvalidDomainNameException
|
If the domain name is invalid. |
DomainConflictException
|
If the domain already exists. |
create_schema(schema)
Creates a new schema on the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema rapid.items.schema.Schema
|
The schema model for which you want to create for. |
required |
Raises:
| Type | Description |
|---|---|
SchemaAlreadyExistsException
|
If you try to create a schema that already exists in rAPId. |
SchemaCreateFailedException
|
If an error occurs while trying to update the schema. |
create_user(user_name, user_email, user_permissions)
Creates a new user on the API with the specified permissions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_name
|
str
|
The name of the user to create. |
required |
user_email
|
str
|
The email of the user to create. |
required |
user_permissions
|
list[str]
|
The permissions of the user to create. |
required |
Raises:
| Type | Description |
|---|---|
InvalidPermissionsException
|
If an error occurs while trying to create the user. |
delete_client(client_id)
Deletes a client from the API based on their id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
str
|
The id of the client to delete. |
required |
Raises:
| Type | Description |
|---|---|
SubjectNotFoundException
|
If the client does not exist. |
delete_dataset(layer, domain, dataset)
Deletes a dataset from the API based on their id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
The dataset layer to delete. |
required |
domain
|
str
|
The dataset domain to delete. |
required |
dataset
|
str
|
The dataset to delete. |
required |
Raises:
| Type | Description |
|---|---|
DatasetNotFoundException
|
If the dataset does not exist. |
delete_user(user_name, user_id)
Deletes a client from the API based on their id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
str
|
The id of the client to delete. |
required |
Raises:
| Type | Description |
|---|---|
SubjectNotFoundException
|
If the client does not exist. |
download_dataframe(layer, domain, dataset, version=None, query=Query())
Downloads data to a pandas DataFrame based on the domain, dataset and version passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
The layer of the dataset to download the DataFrame from. |
required |
domain
|
str
|
The domain of the dataset to download the DataFrame from. |
required |
dataset
|
str
|
The dataset from the domain to download the DataFrame from. |
required |
version
|
int
|
Version of the dataset to download. |
None
|
query
|
Query
|
An optional query type to provide when downloading data. Defaults to empty. |
Query()
|
Raises:
| Type | Description |
|---|---|
DatasetNotFoundException
|
rapid.exceptions.DatasetNotFoundException: If the specificed domain, dataset and version to download does not exist in the rAPId instance we throw the dataset not found exception. |
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
A pandas DataFrame of the data |
fetch_dataset_info(layer, domain, dataset)
Fetches information about the specified dataset in the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
The layer of the dataset to fetch metadata for. |
required |
domain
|
str
|
The domain of the dataset to fetch metadata for. |
required |
dataset
|
str
|
The name of the dataset to fetch metadata for. |
required |
Raises:
| Type | Description |
|---|---|
DatasetInfoFailedException
|
If an error occurs while fetching the dataset information. |
DatasetNotFoundException
|
If the specified dataset does not exist. |
Returns:
| Type | Description |
|---|---|
|
A dictionary containing the metadata information for the dataset. |
fetch_job_progress(_id)
Makes a GET request to the API to fetch the progress of a specific job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_id
|
str
|
The ID of the job to fetch the progress for. |
required |
Returns:
| Type | Description |
|---|---|
|
A JSON response of the API's response. |
generate_schema(df, layer, domain, dataset, sensitivity)
Generates a schema for a pandas DataFrame and a specified dataset in the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to generate a schema for. |
required |
layer
|
str
|
The layer of the dataset to generate a schema for. |
required |
domain
|
str
|
The domain of the dataset to generate a schema for. |
required |
dataset
|
str
|
The name of the dataset to generate a schema for. |
required |
sensitivity
|
str
|
The sensitivity level of the schema to generate. |
required |
Raises:
| Type | Description |
|---|---|
SchemaGenerationFailedException
|
If an error occurs while generating the schema. |
Returns:
| Type | Description |
|---|---|
Schema
|
rapid.items.schema.Schema: A Schema class type from the generated schema for the DataFrame and dataset. |
list_datasets()
List all current datasets within rAPId instance.
Returns:
| Type | Description |
|---|---|
|
A JSON response of the API's response. |
list_layers()
List all current layers within rAPId instance.
Returns:
| Type | Description |
|---|---|
|
A JSON response of the API's response. |
list_protected_domains()
List all current protected domains within rAPId instance.
Returns:
| Type | Description |
|---|---|
|
A JSON response of the API's response. |
list_subjects()
List all current subjects within rAPId instance.
Returns:
| Type | Description |
|---|---|
|
A JSON response of the API's response. |
update_schema(schema)
Uploads a new updated schema to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The new schema model that will be used for the update. |
required |
Raises:
| Type | Description |
|---|---|
SchemaUpdateFailedException
|
If an error occurs while trying to update the schema. |
update_subject_permissions(subject_id, permissions)
Updates the permissions of a subject on the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str
|
The id of the subject to update. |
required |
permissions
|
list[str]
|
The permissions to update the subject with. |
required |
Raises:
| Type | Description |
|---|---|
InvalidPermissionsException
|
If an error occurs while trying to create the client. |
upload_dataframe(layer, domain, dataset, df, wait_to_complete=True)
Uploads a pandas DataFrame to a specified dataset in the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
The layer of the dataset to upload the DataFrame to. |
required |
domain
|
str
|
The domain of the dataset to upload the DataFrame to. |
required |
dataset
|
str
|
The name of the dataset to upload the DataFrame to. |
required |
df
|
DataFrame
|
The pandas DataFrame to upload. |
required |
wait_to_complete
|
bool
|
Whether to wait for the upload job to complete before returning. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
DataFrameUploadValidationException
|
If the DataFrame's schema is incorrect. |
DataFrameUploadFailedException
|
If an unexpected error occurs while uploading the DataFrame. |
DatasetNotFoundException
|
If the specified dataset does not exist. |
Returns:
| Type | Description |
|---|---|
|
If wait_to_complete is True, returns "Success" if the upload is successful. |
|
|
If wait_to_complete is False, returns the ID of the upload job if the upload is accepted. |
wait_for_job_outcome(_id, interval=1)
Makes periodic requests to the API to wait for the outcome of a specific job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_id
|
str
|
The ID of the job to wait for the outcome of. |
required |
interval
|
int
|
The number of seconds to sleep between requests to the API. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
|
None if the job is successful. |
Raises:
| Type | Description |
|---|---|
JobFailedException
|
If the job outcome failed. |