API Client

API Client represents a low level interface for Model API. All API operation can be performed using this.

class abeja.deployments.APIClient(credential: dict | None = None, timeout: int | None = None, max_retry_count: int | None = None)

A low-level client for Deployment API

from abeja.deployments import APIClient

api_client = APIClient()
create_deployment(organization_id: str, name: str | None = None, description: str | None = '', default_environment: Dict[str, str] | None = None) dict

create a deployment

API reference: POST /organizations/<organization_id>/deployments

Request Syntax:
organization_id = "1111111111111"
deployment_name = "deployment_name"
description = "description"
default_environment = {
    'SAMPLE_ENV': 'SAMPLE_VALUE'
}

response = api_client.create_deployment(organization_id, deployment_name, default_environment)
Params:
  • organization_id (str): organization identifier

  • name (str): deploymnet name

  • description (str): description

  • default_environment (dict): default environment variables on the running environment

Return type:

dict

Returns:
Response Syntax:
{
    "deployment_id": "1111111111111",
    "name": "deployment_name",
    "description": "description",
    "creator": {
        "display_name": null,
        "email": "platform-support@abeja.asia",
        "id": "1111111111111",
        "is_registered": true,
        "role": "admin",
        "created_at": "2017-05-29T07:48:55Z",
        "updated_at": "2017-11-29T10:21:24Z"
    },
    "default_environment": {},
    "runs": [],
    "services": [],
    "triggers": [],
    "created_at": "2018-06-05T08:52:02.428441Z",
    "modified_at": "2018-06-05T08:52:02.428587Z"
}
Raises:
  • BadRequest: the resource already exists or parameters is insufficient or invalid.

  • Unauthorized: Authentication failed

  • InternalServerError

create_deployment_from_template(organization_id: str, deployment_id: str, template_id: int, version: str, handler: str, image: str, user_parameters: Dict[str, str] | None = None) dict

create a deployment from template

API reference: POST /organizations/<organization_id>/deployments/<deployment_id>/code_templates

Request syntax:
deployment_id = '1111111111111',
template_id = 1,
version = '0.0.1'
handler = 'main:handler'
image = 'abeja-inc/all-cpu:18.10'
user_parameters = {
     'SAMPLE_ENV': 'SAMPLE_VALUE'
 }

response = api_client.create_deployment_from_template(
    organization_id, deployment_id, template_id, version, handler, image, user_parameters
)
Params:
  • organization_id (str): organization id

  • deployment_id (str): deployment id

  • template_id (int): template id

  • version (str): version

  • handler (str) : handler path

  • user_parameters (dict): user defined parameters.

Return type:

dict

Returns:
Response syntax:
{
    "deployment_id": "1111111111111",
    "version": "0.0.1",
    "version_id": "ver-abc1111111111111",
    "handler": "main:handler",
    "image": "abeja-inc/all-cpu:18.10",
    "user_parameters": {},
    "created_at": "2018-06-14T07:15:43.462664Z",
    "modified_at": "2018-06-14T07:15:43.462824Z"
}
Response Structure:
  • deployment_id (str) : deployment id

  • version (str) : version

  • version_id (str) : version id

  • handler (str) : handler path

  • image (str) : runtime enviornment

  • user_parameters (dict): user defined parameters.

  • upload_url (str) : url to upload archived file. archived file should be uploaded after creating model version using this upload_url

Raises:
  • BadRequest: specified deployment id does not exist or deployment version already exist, parameters is insufficient or invalid,

  • Unauthorized: Authentication failed

  • InternalServerError

create_deployment_version(organization_id: str, deployment_id: str, version: str, handler: str, image: str, user_parameters: Dict[str, str] | None = None) dict

create a deployment code version

API reference: POST /organizations/<organization_id>/deployments/<deployment_id>/versions

Request syntax:
deployment_id = '1111111111111',
version = '0.0.1'
handler = 'main:handler'
image = 'abeja-inc/all-cpu:18.10'
user_parameters = {
    'SAMPLE_ENV': 'SAMPLE_VALUE'
}

response = api_client.create_deployment_version(
    organization_id, deployment_id, version, handler, image, user_parameters
)

# Then, you need to upload the source code for prediction to the ABEJA Platform

# create an archive containing all the source codes.
# for example, source tree looks like:
# /path/
#   |-- to/
#       |-- project/
#             |-- root/
#                   |-- main.py
#                   |-- utils/
#                         |-- util.py
from shutil import make_archive
make_archive(
    './archive',
    'gztar',
    root_dir='/path/to/project/root',
    base_dir='.'
)

# upload archive
import requests
upload_url = response['upload_url']
with open('archive.tar.gz', 'rb') as file:
    requests.put(upload_url, data=file)
Params:
  • organization_id (str): organization id

  • deployment_id (str): deployment id

  • version (str): version

  • handler (str) : handler path

  • user_parameters (dict): user defined parameters.

Return type:

dict

Returns:
Response syntax:
{
    "deployment_id": "1111111111111",
    "version": "0.0.1",
    "version_id": "ver-abc1111111111111",
    "handler": "main:handler",
    "image": "abeja-inc/all-cpu:18.10",
    "user_parameters": {},
    "created_at": "2018-06-14T07:15:43.462664Z",
    "modified_at": "2018-06-14T07:15:43.462824Z",
    "upload_url": "https://abeja-model-api-src.s3.amazonaws.com/1462815098134/ver-/source.tgz?xxxxxx"
}
Response Structure:
  • deployment_id (str) : deployment id

  • version (str) : version

  • version_id (str) : version id

  • handler (str) : handler path

  • image (str) : runtime enviornment

  • user_parameters (dict): user defined parameters.

  • upload_url (str) : url to upload archived file. archived file should be uploaded after creating model version using this upload_url

Raises:
  • BadRequest: specified deployment id does not exist or deployment version already exist, parameters is insufficient or invalid,

  • Unauthorized: Authentication failed

  • InternalServerError

delete_deployment(organization_id: str, deployment_id: str) dict

delete a deployment

API reference: DELETE /organizations/<organization_id>/deployments/<deployment_id>

Request syntax:
response = api_client.delete_deployment(organization_id='1111111111111', deployment_id='1111111111111')
Params:
  • organization_id (str): ORGANIZATION_ID

  • deployment_id (str): deployment identifier

Return type:

dict

Responses:
Response syntax:
{
    "message": "1111111111111 deleted"
}
Raises:
  • NotFound: model not found

  • Unauthorized: Authentication failed

  • InternalServerError

delete_deployment_version(organization_id: str, deployment_id: str, version_id: str) None

delete a version in a deployment

API reference: DELETE /organizations/<organization_id>/deployments/<deployment_id>/versions/<version_id>

Request syntax:
api_client.delete_deployment_version(
    organization_id='1111111111111',
    deployment_id='1111111111111',
    version_id='ver-abc3333333333333')
Params:
  • organization_id (str): ORGANIZATION_ID

  • deployment_id (str): deployment id

  • version_id (str): deployment version id

Return type:

dict

Returns:
Response syntax:
{
    "message": "ver-abc1111111111111 deleted"
}
Response Structure:
  • message (str) :

Raises:
  • NotFound: deployment version not found

  • Unauthorized: Authentication failed

  • InternalServerError

download_deployment_version(organization_id: str, deployment_id: str, version_id: str) dict

download a deployment code version

API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/versions/<version_id>/download

Request Syntax:
response = api_client.download_deployment_version(
    organization_id='1111111111111',
    deployment_id='1111111111111',
    version_id='ver-abc3333333333333')
Params:
  • organization_id (str): ORGANIZATION_ID

  • deployment_id (str): deployment id

  • version_id (str): deployment version id

Return type:

dict

Returns:
Response Syntax:
{
     "download_uri": "https://..."
}
Response Structure:
  • download_uri (str) : presigned download link of the deployment code version

Raises:
  • NotFound: deployment not found

  • Unauthorized: Authentication failed

  • InternalServerError

get_deployment(organization_id: str, deployment_id: str) dict

get a deployment

API reference: GET /organizations/<organization_id>/deployments/<deployment_id>

Request Syntax:
response = api_client.get_deployment(organization_id='1111111111111', deployment_id='1111111111111')
Params:
  • organization_id (str): organization_id

  • deployment_id (str): deployment_id of the requested model

Return type:

dict

Returns:
Response Syntax:
{
    "deployment_id": "1111111111111",
    "name": "deployment_name",
    "creator": {
        "display_name": null,
        "email": "platform-support@abeja.asia",
        "id": "1111111111111",
        "is_registered": true,
        "role": "admin",
        "created_at": "2017-05-29T07:48:55Z",
        "updated_at": "2017-11-29T10:21:24Z"
    },
    "default_environment": {},
    "runs": [],
    "services": [],
    "triggers": [],
    "created_at": "2018-06-05T08:52:02.428441Z",
    "modified_at": "2018-06-05T08:52:02.428587Z",
}
Raises:
  • NotFound: model not found

  • Unauthorized: Authentication failed

  • InternalServerError

get_deployment_version(organization_id: str, deployment_id: str, version_id: str) dict

get a version of a deployment

API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/versions/<version_id>

Request syntax:
response = api_client.get_deployment_version(organization_id='1111111111111',
                                        deployment_id='2222222222222',
                                        version_id='ver-abc3333333333333')
Params:
  • organization_id (str): ORGANIZATION_ID

  • deployment_id (str): deployment id

  • version_id (str): deployment version id

Return type:

dict

Returns:
Response syntax:
{
    "deployment_id": "1111111111111",
    "version_id": "ver-abc1111111111111",
    "version": "0.0.1",
    "handler": "main:handler",
    "image": "abeja-inc/all-cpu:18.10",
    "user_parameters": {},
    "created_at": "2018-04-26T01:12:05.771403Z",
    "modified_at": "2018-04-26T01:12:05.771533Z"
}
Response Structure:
  • deployment_id (str) : deployment id

  • version (str) : version

  • version_id (str) : version id

  • handler (str) : handler path

  • image (str) : runtime enviornment

  • user_parameters (dict): user defined parameters.

Raises:
  • NotFound: deployment version not found

  • Unauthorized: Authentication failed

  • InternalServerError

get_deployment_versions(organization_id: str, deployment_id: str) dict

get a deployment code versions

API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/versions

Request Syntax:
response = api_client.get_deployment_versions(organization_id='1111111111111', deployment_id='1111111111111')
Params:
  • organization_id (str): organization_id

  • deployment_id (str): deployment_id of the requested model

Return type:

dict

Returns:
Response Syntax:
{
    "entries": [
        {
            "deployment_id": "1111111111111",
            "creator": {
                "display_name": null,
                "email": "paltform-support@abeja.asia",
                "id": "1111111111111",
                "is_registered": true,
                "role": "admin",
                "created_at": "2017-05-29T07:48:55Z",
                "updated_at": "2017-11-29T10:21:24Z"
            },
            "version": "0.0.1",
            "version_id": "ver-abc1111111111111",
            "handler": "main:handler",
            "image": "abeja-inc/all-cpu:18.10",
            "user_parameters": {},
            "created_at": "2018-06-05T08:52:02.428441Z",
            "modified_at": "2018-06-05T08:52:02.428587Z"
        }
    ]
}
Raises:
  • NotFound: model not found

  • Unauthorized: Authentication failed

  • InternalServerError

get_deployments(organization_id: str) dict

Get deployments entries

API reference: GET /organizations/<organization_id>/deployments/

Request syntax:
response = api_client.get_deployments(organization_id='1102940376065')
Params:
  • organization_id (str): organization_id

Return type:

dict

Returns:
Return syntax:
{
    "entries": [
        {
            "deployment_id": "1111111111111",
            "name": "deployment_name",
            "creator": {
                "display_name": null,
                "email": "paltform-support@abeja.asia",
                "id": "1111111111111",
                "is_registered": true,
                "role": "admin",
                "created_at": "2017-05-29T07:48:55Z",
                "updated_at": "2017-11-29T10:21:24Z"
            },
            "default_environment": {},
            "runs": [],
            "services": [],
            "triggers": [],
            "created_at": "2018-06-05T08:52:02.428441Z",
            "modified_at": "2018-06-05T08:52:02.428587Z"
        }
    ]
}
Raises:
  • Unauthorized: Authentication failed

  • InternalServerError

patch_deployment(organization_id: str, deployment_id: str, name: str, default_environment: Dict[str, str] | None = None)

update a deployment

API reference: PATCH /organizations/<organization_id>/deployments/<deployment_id>

Request syntax:
organization_id = "1111111111111"
deployment_name = "deployment_name"
default_environment = {
    'SAMPLE_ENV': 'SAMPLE_VALUE'
}

response = api_client.create_deployment(organization_id, deployment_name, default_environment)
Params:
  • organization_id (str): organization identifier

  • deployment_id (str): deployment identifier

  • name (str): deploymnet name

  • default_environment (dict): default environment variables on the running environment

Return type:

dict

Returns:
Response Syntax:
{
    "deployment_id": "1111111111111",
    "name": "deployment_name",
    "default_environment": {},
    "runs": [],
    "services": [],
    "triggers": [],
    "created_at": "2018-06-05T08:52:02.428441Z",
    "modified_at": "2018-06-05T08:52:02.428587Z"
}
Raises:
  • BadRequest: the resource already exists or parameters is insufficient or invalid.

  • Unauthorized: Authentication failed

  • InternalServerError