API Client

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

class abeja.services.APIClient(credential: typing.Union[dict, NoneType] = None, timeout: typing.Union[int, NoneType] = None)

A low-level client for Service API

from abeja.services import APIClient

api_client = APIClient()
create_service(organization_id: str, deployment_id: str, version_id: str, environment: typing.Union[typing.Dict[str, str], NoneType] = None, instance_type: str = 'cpu-0.25', instance_number: int = 1) → dict

create a service

API reference: POST /organizations/{organization_id}/deployments/{deployment_id}/services

Request Syntax:
organization_id = "1111111111111"
deployment_id = "2222222222222"
version_id = "ver-abc3333333333333"
environment = {
    "EXAMPLE_ENV": "abc"
}

response = api_client.create_service(organization_id, deployment_id, version_id, environment=environment)
Params:
  • organization_id (str): organization identifier
  • deployment_id (str): deployment identifier
  • version_id (str): version identifier of paired model
  • environment (dict): env variable of running environment
  • instance_type (str): instance type of running environment
  • instance_number (str): number of instance
Return type:
dict
Returns:
Response Syntax:
{
    "service_id": "ser-abc1111111111111",
    "deployment_id": "1111111111111",
    "model_version": "0.0.1",
    "model_version_id": "ver-abc1111111111111",
    "status": "IN_PROGRESS",
    "instance_number": 1,
    "instance_type": "cpu-0.25",
    "metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    "user_env_vars": {
        "EXAMPLE_ENV": "abc"
    },
    "created_at": "2018-06-05T13:07:49.602076Z",
    "modified_at": "2018-06-05T13:07:50.771671Z",
}
Raises:
  • BadRequest: the resource already exists or parameters is insufficient or invalid.
  • Unauthorized: Authentication failed
  • InternalServerError
delete_service(organization_id: str, deployment_id: str, service_id: str) → dict

delete a service

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

Request syntax:
response = api_client.delete_service(organization_id='1111111111111',
                                     deployment_id='1111111111111', service_id='ser-abc1111111111111')
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
  • service_id (str): service identifier
Return type:
dict
Responses:
Response syntax:
{
    "message": "ser-abc1111111111111 deleted"
}
Raises:
  • NotFound: service not found
  • Unauthorized: Authentication failed
  • InternalServerError
get_service(organization_id: str, deployment_id: str, service_id: str) → dict

get a service

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

Request Syntax:
response = api_client.get_service(organization_id='1111111111111', deployment_id='1111111111111',
                                  service_id='ser-abc1111111111111')
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
  • service_id (str): service identifier
Return type:
dict
Returns:
Response Syntax:
{
    "service_id": "ser-abc1111111111111",
    "deployment_id": "1111111111111",
    "model_version": "0.0.1",
    "model_version_id": "ver-abc1111111111111",
    "status": "READY",
    "instance_number": 1,
    "instance_type": "cpu-0.25",
    "metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    "user_env_vars": {
        "EXAMPLE_ENV": "abc"
    },
    "created_at": "2018-06-05T12:34:33.485329Z",
    "modified_at": "2018-06-05T12:34:34.568985Z"
}
Raises:
  • NotFound: service not found
  • Unauthorized: Authentication failed
  • InternalServerError
get_services(organization_id: str, deployment_id: str) → dict

Get services entries

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

Request syntax:
response = api_client.list_services(organization_id='1111111111111', deployment_id='1111111111111')
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
Return type:
dict
Returns:
Return syntax:
{
    "entries": [
        {
            "service_id": "ser-abc1111111111111",
            "deployment_id": "1111111111111",
            "model_version": "0.0.1",
            "model_version_id": "ver-abc1111111111111",
            "status": "READY",
            "instance_number": 1,
            "instance_type": "cpu-0.25",
            "metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            "user_env_vars": {
                "EXAMPLE_ENV": "abc"
            },
            "created_at": "2018-06-05T12:34:33.485329Z",
            "modified_at": "2018-06-05T12:34:34.568985Z"
        }
    ]
}
Raises:
  • Unauthorized: Authentication failed
  • InternalServerError
update_service(organization_id: str, deployment_id: str, service_id: str, payload: typing.Union[dict, NoneType] = None) → dict

update a service

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

Request Syntax:
payload = {
    "instance_number": 4,
    "min_instance_number": 2,
    "max_instance_number": 6,
    "enable_autoscale": 'true'
}
response = api_client.update_service(organization_id='1111111111111', deployment_id='1111111111111',
                                 service_id='ser-abc1111111111111', payload=payload)
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
  • service_id (str): service identifier
  • payload (dict): payload of service [optional]
Return type:
dict
Returns:
Response Syntax:
{
    "deployment_id": "1408443944117",
    "instance_number": 1,
    "instance_type": "cpu-1",
    "metrics_url": "https://p.datadoghq.com/sb/xxxxxxxxx-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
    "model_version": "1.0.0",
    "model_version_id": "ver-1cfab7455c8e43a7",
    "service_id": "ser-abc1111111111111",
    "status": "IN_PROGRESS",
    "record_channel_id": "5678901234567",
    "user_env_vars": {
        "EXAMPLE_ENV2": "exmaple2"
    },
    "merged_env_vars": {
        "EXAMPLE_ENV": "deployment_example",
        "EXAMPLE_ENV2": "exmaple2"
    },
    "service_process_type": "multi",
    "modified_at": "2018-01-01T00:00:00.102289Z",
    "created_at": "2018-01-01T00:00:00.102289Z"
}
Raises:
  • NotFound: service not found
  • Unauthorized: Authentication failed
  • InternalServerError