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, max_retry_count: 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, instance_number: int = 1, min_instance_number: typing.Union[int, NoneType] = None, max_instance_number: typing.Union[int, NoneType] = None, enable_autoscale: typing.Union[bool, NoneType] = None, instance_type: str = 'cpu-0.25', environment: typing.Union[typing.Dict[str, str], NoneType] = None, model_id: typing.Union[str, NoneType] = None) → dict

create a service

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

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

response = api_client.create_service(
    organization_id, deployment_id, version_id,
    model_id=model_id, environment=environment)
Params:
  • organization_id (str): organization identifier
  • deployment_id (str): deployment identifier
  • version_id (str): version identifier of paired model
  • model_id (str): training model identifier
  • environment (dict): env variable of running environment
  • instance_type (str): instance type of running environment
  • instance_number (str): number of instance
  • min_instance_number (str): number of minimum instance
  • max_instance_number (str): number of maximum instance
  • enable_autoscale (str): enable auto scaling
Return type:
dict
Returns:
Response Syntax:
{
    "service_id": "ser-abc1111111111111",
    "deployment_id": "9999999999999",
    "models": {
        "alias": "3333333333333"
    },
    "model_version": "0.0.1",
    "model_version_id": "ver-abc1111111111111",
    "status": "IN_PROGRESS",
    "instance_number": 1,
    "min_instance_number": 1,
    "max_instance_number": 2,
    "enable_autoscale": true,
    "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='9999999999999', 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='9999999999999',
                                  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": "9999999999999",
    "models": {
        "alias": "3333333333333"
    },
    "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_service_recent_logs(organization_id: str, deployment_id: str, service_id: str, next_forward_token: typing.Union[str, NoneType] = None, next_backward_token: typing.Union[str, NoneType] = None, start_time: typing.Union[datetime.datetime, NoneType] = None, end_time: typing.Union[datetime.datetime, NoneType] = None) → dict

get recent logs of the service

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

Request Syntax:
organization_id = "1234567890123"
deployment_id = "1111111111111"
service_id = "ser-3333333333333333"
response = api_client.get_service_recent_logs(organization_id, deployment_id, service_id)
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
  • service_id (str): service identifier
  • next_forward_token (str): [optional] token for the next page of logs
  • next_backward_token (str): [optional] token for the next previous of logs
  • start_time (datetime): [optional] specifies the start utc datetime included in data series
  • end_time (datetime): [optional] specifies the end utc datetime included in data series
Return type:
dict
Returns:

Response Syntax:

{
    "events": [
        {
            "message": "...",
            "timestamp": "2018-01-01T00:00:00.000000Z"
        }
    ],
    "next_backward_token": "...",
    "next_forward_token": "..."
}

Response Structure:

  • events (list): list of messages emitted from the service. the messages are sorted in descending order.
  • next_backward_token (str): token for the previous page of logs. If no more logs, this key exists and returns empty list.
  • next_forward_token (str): token for the next page of logs. If no more logs, this key exists and returns empty list.
Raises:
  • Unauthorized: Authentication failed
  • NotFound:
  • Forbidden:
  • 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='9999999999999')
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
Return type:
dict
Returns:
Return syntax:
{
    "entries": [
        {
            "service_id": "ser-abc1111111111111",
            "deployment_id": "9999999999999",
            "models": {
                "alias": "3333333333333"
            },
            "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
request_service(organization_id: str, deployment_id: str, service_id: str, data: typing.Union[NoneType, str, bytes, typing.IO] = None, json: typing.Union[typing.Any, NoneType] = None, content_type: typing.Union[str, NoneType] = None) → requests.models.Response

post request to the service

API reference: POST https://<organization_id>.api.abeja.io/deployments/<deployment_id>/services/<service_id>

Request Syntax:
organization_id = "1234567890123"
deployment_id = "1111111111111"
service_id = "ser-3333333333333333"

# send json data
json_data = {
    "foo": "bar",
    "baz": "qux"
}
response = api_client.request_service(organization_id, deployment_id, service_id, json=json_data)

# send image data
with open('./foo.png', 'rb') as f:
    response = api_client.request_service(organization_id, deployment_id, service_id, data=f, content_type='image/png')
Params:
  • organization_id (str): organization_id
  • deployment_id (str): deployment identifier
  • service_id (str): service identifier
  • data (Union[str, bytes, typing.IO]): [optional] a request payload of something other than json
  • json (typing.Any): [optional] a request payload of json
  • content_type (str): [optional] MIME-Type. Specify if you want to send data using data to the service
Return type:
requests.Response
Raises:
  • Unauthorized: Authentication failed
  • NotFound:
  • Forbidden:
  • InternalServerError:
start_service(organization_id: str, deployment_id: str, service_id: str) → dict

start a service

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

Request syntax:
response = api_client.stop_service(organization_id='1111111111111',
                                  deployment_id='9999999999999', 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 started"
}
Raises:
  • BadRequest: service is already running
  • NotFound: service not found
  • Unauthorized: Authentication failed
  • InternalServerError
stop_service(organization_id: str, deployment_id: str, service_id: str) → dict

stop a service

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

Request syntax:
response = api_client.stop_service(organization_id='1111111111111',
                                  deployment_id='9999999999999', 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 stopped"
}
Raises:
  • BadRequest: service is not running
  • NotFound: service not found
  • 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='9999999999999',
                                 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",
    "models": {
        "alias": "3333333333333"
    },
    "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