API Client represents a low level interface for Datalake API. All API operation can performed using this.
abeja.datalake.
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 Datalake API
from abeja.datalake import APIClient
api_client = APIClient()
archive_bucket
(organization_id: str, bucket_id: str)¶archive a bucket
API reference: POST /organizations/<organization_id>/buckets/<bucket_id>/archive
organization_id = "1234567890123"
bucket_id = "1230000000000"
response = api_client.archive_bucket(
organization_id, bucket_id)
Response Syntax:
{
"organization_id": "1234567890123",
"bucket": {
"updated_at": "2018-06-06T09:43:34Z",
"security_method": "organization",
"name": "example-bucket",
"display_name": "example-bucket",
"description": "this is sample bucket",
"created_at": "2018-05-30T10:44:28Z",
"bucket_id": "1234567890123",
"archived": true
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
archive_channel
(organization_id: str, channel_id: str)¶archive a channel
API reference: POST /organizations/<organization_id>/channels/<channel_id>/archive
organization_id = "1234567890123"
channel_id = "1230000000000"
response = api_client.archive_channel(
organization_id, channel_id)
Response Syntax:
{
"organization_id": "1234567890123",
"channel": {
"updated_at": "2018-06-06T09:43:34Z",
"storage_type": "datalake",
"security_method": "organization",
"name": "example-channel",
"display_name": "example-channel",
"description": "this is sample channel",
"created_at": "2018-05-30T10:44:28Z",
"channel_id": "1234567890123",
"archived": true
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
create_bucket
(organization_id: str, name: str, description: str) → dict¶create a bucket
API reference: POST /organizations/<organization_id>/buckets
organization_id = "1234567890123"
name = "sample bucket"
description = "sample bucket description"
response = api_client.create_bucket(organization_id, name, description)
Response Syntax:
{
"organization_id": "1234567890123",
"updated_at": "2017-09-12T10:11:46Z",
"organization_name": "abeja-inc",
"bucket": {
"updated_at": "2018-05-15T17:14:03Z",
"created_at": "2018-05-15T17:14:02Z",
"name": "test",
"description": "test",
"display_name": "test",
"bucket_id": "1230000000000"
},
"created_at": "2017-09-12T10:11:46Z"
}
create_channel
(organization_id: str, name: str, description: str, storage_type: str) → dict¶create a channel
API reference: POST /organizations/<organization_id>/channels/
organization_id = "1234567890123"
name = "sample channel"
description = "sample channel description"
storage_type = "datalake"
response = api_client.create_channel(
organization_id, name, description, storage_type)
Response Syntax:
{
"organization_id": "1234567890123",
"updated_at": "2017-09-12T10:11:46Z",
"organization_name": "abeja-inc",
"channel": {
"updated_at": "2018-05-15T17:14:03Z",
"created_at": "2018-05-15T17:14:02Z",
"storage_type": "datalake",
"name": "test",
"description": "test",
"display_name": "test",
"channel_id": "1230000000000"
},
"created_at": "2017-09-12T10:11:46Z"
}
delete_channel_datasource
(organization_id: str, channel_id: str, datasource_id: str)¶delete datasource of a channel
API reference: DELETE /organizations/<organization_id>/channels/<channel_id>/datasources/<datasource_id>
organization_id = "1234567890123"
channel_id = "1230000000000"
datasource_id = "1442132811920"
response = api_client.delete_channel_datasource(
organization_id, channel_id, datasource_id)
Response Syntax:
{
"organization_id": "1234567890123",
"datasource": {
"secret": "c78cc952d6aa021b1701c3a7e68205cc84c4eddd",
"created_at": "2018-05-15T10:33:00Z",
"display_name": "test",
"updated_at": "2018-05-15T10:33:00Z",
"datasource_id": "1442132811920"
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
delete_channel_file
(channel_id: str, file_id: str) → dict¶delete a file in a channel.
API reference: DELETE /channels/<channel_id>/<file_id>
channel_id = "1230000000000"
file_id = "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9"
response = api_client.delete_channel_file(channel_id, file_id)
Response Syntax:
{
"message": "deleted file (20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9)"
}
get_bucket
(organization_id: str, bucket_id: str) → dict¶get a bucket
API reference: GET /organizations/<organization_id>/buckets/<bucket_id>
organization_id = "1234567890123"
bucket_id = "1230000000000"
response = api_client.get_bucket(organization_id, bucket_id)
Response Syntax:
{
"updated_at": "2017-09-12T10:11:46Z",
"created_at": "2017-09-12T10:11:46Z",
"bucket": {
"created_at": "2018-05-15T17:14:02Z",
"name": "test",
"updated_at": "2018-05-15T17:14:03Z",
"bucket_id": "1230000000000",
"display_name": "test",
"description": "test"
},
"organization_id": "1234567890123",
"organization_name": "abeja-inc"
}
get_bucket_file
(organization_id: str, bucket_id: str, file_id: str) → dict¶get a file in a bucket.
API reference: GET /organizations/<organization_id>/buckets/<bucket_id>/files/<file_id>
organization_id = "1234567890123"
bucket_id = "1230000000000"
file_id = "aaa/bbb"
response = api_client.get_bucket_file(organization_id, bucket_id, file_id)
Response Syntax:
{
"size": 4,
"etag": "xxx",
"is_file": true,
"metadata": {
"x-abeja-meta-filename": "000000006197.jpg"
},
"last_modified": "2018-05-10T11:02:08+00:00",
"uploaded_at": "2018-05-10T11:02:08+00:00",
"url_expires_on": "2018-05-15T18:54:37+00:00",
"download_uri": "...",
"file_id": "/aaa/bbb/ddd"
}
get_channel
(organization_id: str, channel_id: str) → dict¶get a channel
API reference: GET /organizations/<organization_id>/channels/<channel_id>
organization_id = "1234567890123"
channel_id = "1230000000000"
response = api_client.get_channel(organization_id, channel_id)
Response Syntax:
{
"updated_at": "2017-09-12T10:11:46Z",
"created_at": "2017-09-12T10:11:46Z",
"channel": {
"created_at": "2018-05-15T17:14:02Z",
"name": "test",
"updated_at": "2018-05-15T17:14:03Z",
"channel_id": "1230000000000",
"storage_type": "datalake",
"display_name": "test",
"description": "test",
"archived": false
},
"organization_id": "1234567890123",
"organization_name": "abeja-inc"
}
get_channel_file_download
(channel_id: str, file_id: str) → dict¶get a file info in a channel.
API reference: GET /channels/<channel_id>/<file_id>
channel_id = "1230000000000"
file_id = "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9"
response = api_client.get_channel_file_download(channel_id, file_id)
Response Syntax:
{
"download_uri": "...",
"url_expires_on": "2018-05-15T18:57:03+00:00",
"metadata": {
"x-abeja-meta-filename": "000000009851.jpg"
},
"file_id": "20180510T110210-a2d3a218-5357-4919-8218-9090acaa147e",
"content_type": "image/jpeg",
"uploaded_at": "2018-05-10T11:02:10+00:00"
}
get_channel_file_upload
(channel_id: str, content_type: str, metadata: dict = None) → dict¶get upload info for a channel.
API reference: POST /channels/<channel_id>/
channel_id = "1230000000000"
content_type = "image/jpeg"
metadata = {
"x-abeja-meta-filename": "sample.jpg"
}
response = api_client.get_channel_file_upload(
channel_id, content_type, metadata)
Response Syntax:
{
"url_expires_on": "2018-05-15T19:06:05+00:00",
"upload_url": "...",
"uploaded_at": null,
"metadata": {},
"content_type": "image/jpeg",
"file_id": "20180515T180605-f4acc798-9afa-40a1-b500-ebce42a4fa3f"
}
list_bucket_files
(organization_id: str, bucket_id: str, target_dir: str = '/', items_per_page: int = None, last_file_id: str = None, query: str = None) → dict¶get files in a bucket.
API reference: GET /organizations/<organization_id>/buckets/<bucket_id>/files
organization_id = "1234567890123"
bucket_id = "1230000000000"
response = api_client.list_bucket_files(bucket_id)
Response Syntax:
{
"last_file_id": "/aaa/bbb/ccc",
"files": [
{
"size": 4,
"etag": "xxx",
"is_file": true,
"metadata": {
"x-abeja-meta-filename": "000000006197.jpg"
},
"last_modified": "2018-05-10T11:02:08+00:00",
"uploaded_at": "2018-05-10T11:02:08+00:00",
"url_expires_on": "2018-05-15T18:54:37+00:00",
"download_uri": "...",
"file_id": "/aaa/bbb/ddd"
},
]
}
list_buckets
(organization_id: str, limit: int = None, offset: int = None) → dict¶get buckets
API reference: GET /organizations/<organization_id>/buckets/
organization_id = "1234567890123"
response = api_client.list_buckets(organization_id)
Response Syntax:
{
"updated_at": "2017-09-12T10:11:46Z",
"buckets": [
{
"updated_at": "2018-05-15T17:14:03Z",
"display_name": "test",
"description": "test",
"name": "test",
"bucket_id": "1230000000000",
"created_at": "2018-05-15T17:14:02Z",
},
],
"limit": 50,
"has_next": true,
"organization_name": "abeja-inc",
"offset": 0,
"created_at": "2017-09-12T10:11:46Z",
"organization_id": "1234567890123"
}
list_channel_datasources
(organization_id: str, channel_id: str) → dict¶get datasources of a channel
API reference: GET /organizations/<organization_id>/channels/<channel_id>/datasources
organization_id = "1234567890123"
channel_id = "1230000000000"
response = api_client.list_channel_datasources(organization_id, channel_id)
Response Syntax:
{
"limit": 50,
"has_next": false,
"updated_at": "2017-09-12T10:11:46Z",
"datasources": [
{
"created_at": "2018-05-15T17:37:12Z",
"datasource_id": "1442132811920",
"secret": "c123aa2751dc123235156040ed160103877b9aaa",
"updated_at": "2018-05-15T17:37:12Z",
"display_name": "test_datasource"
}
],
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"offset": 0,
"organization_id": "1234567890123"
}
list_channel_files
(channel_id: str, start: str = None, end: str = None, timezone: str = None, items_per_page: int = None, sort: str = None, next_page_token: str = None, query: str = None) → dict¶get files in a channel.
API reference: GET /channels/<channel_id>/
channel_id = "1230000000000"
response = api_client.list_channel_files(channel_id)
Response Syntax:
{
"next_page_token": null,
"files": [
{
"content_type": "image/jpeg",
"metadata": {
"x-abeja-meta-filename": "000000006197.jpg"
},
"uploaded_at": "2018-05-10T11:02:08+00:00",
"url_expires_on": "2018-05-15T18:54:37+00:00",
"download_uri": "...",
"file_id": "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9"
},
]
}
list_channels
(organization_id: str, limit: typing.Union[int, NoneType] = None, offset: typing.Union[int, NoneType] = None, filter_archived: typing.Union[bool, NoneType] = None) → dict¶get channels
API reference: GET /organizations/<organization_id>/channels/
organization_id = "1234567890123"
response = api_client.list_channels(organization_id)
true
, include archived jobs, otherwise exclude archived jobs. (default: false
)Response Syntax:
{
"updated_at": "2017-09-12T10:11:46Z",
"channels": [
{
"updated_at": "2018-05-15T17:14:03Z",
"display_name": "test",
"description": "test",
"name": "test",
"channel_id": "1230000000000",
"created_at": "2018-05-15T17:14:02Z",
"storage_type": "datalake",
"archived": false
},
],
"limit": 50,
"has_next": true,
"organization_name": "abeja-inc",
"offset": 0,
"created_at": "2017-09-12T10:11:46Z",
"organization_id": "1234567890123"
}
patch_bucket
(organization_id: str, bucket_id: str, name: str = None, description: str = None) → dict¶edit a bucket
API reference: PATCH /organizations/<organization_id>/buckets/<bucket_id>
organization_id = "1234567890123"
bucket_id = "1230000000000"
name = 'updated_name'
description = 'updated_description'
response = api_client.patch_bucket(organization_id, bucket_id, name, description)
Response Syntax:
{
"bucket": {
"description": "updated_description",
"updated_at": "2018-05-15T17:30:21Z",
"created_at": "2018-05-15T17:14:02Z",
"display_name": "updated_description",
"bucket_id": "1230000000000",
"name": "updated_name"
},
"organization_name": "abeja-inc",
"updated_at": "2017-09-12T10:11:46Z",
"created_at": "2017-09-12T10:11:46Z",
"organization_id": "1234567890123"
}
patch_channel
(organization_id: str, channel_id: str, name: str = None, description: str = None) → dict¶edit a channel
API reference: PATCH /organizations/<organization_id>/channels/<channel_id>
organization_id = "1234567890123"
channel_id = "1230000000000"
name = 'updated_name'
description = 'updated_description'
response = api_client.patch_channel(organization_id, channel_id, name, description)
Response Syntax:
{
"channel": {
"storage_type": "datalake",
"description": "updated_description",
"updated_at": "2018-05-15T17:30:21Z",
"created_at": "2018-05-15T17:14:02Z",
"display_name": "updated_description",
"channel_id": "1230000000000",
"name": "updated_name"
},
"organization_name": "abeja-inc",
"updated_at": "2017-09-12T10:11:46Z",
"created_at": "2017-09-12T10:11:46Z",
"organization_id": "1234567890123"
}
post_channel_file_upload
(channel_id: str, file_obj: typing.IO, content_type: str, metadata: dict = None, lifetime: str = None, conflict_target: str = None) → dict¶upload a file to a channel.
API reference: POST /channels/<channel_id>/upload
channel_id = "1230000000000"
content_type = "image/jpeg"
metadata = {
"x-abeja-meta-filename": "sample.jpg"
}
with open('sample.jpg', 'rb') as f:
response = api_client.post_channel_file_upload(
channel_id, f, content_type, metadata=metadata)
Response Syntax:
{
"uploaded_at": null,
"metadata": {
"x-abeja-meta-filename": "sample.jpg"
},
"lifetime": "1day",
"content_type": "image/jpeg",
"file_id": "20180515T180605-f4acc798-9afa-40a1-b500-ebce42a4fa3f"
}
put_channel_datasource
(organization_id: str, channel_id: str, datasource_id: str) → dict¶connect a datasource with a channel
API reference: PUT /organizations/<organization_id>/channels/<channel_id>/datasources/<datasource_id>
organization_id = "1234567890123"
channel_id = "1230000000000"
datasource_id = "1442132811920"
response = api_client.put_channel_datasource(organization_id,
channel_id, datasource_id)
Response Syntax:
{
"organization_id": "1234567890123",
"datasource": {
"datasource_id": "1442132811920",
"created_at": "2018-05-15T10:33:00Z",
"display_name": "test",
"secret": "c78cc952d6aa021b1701c3a7e68205cc84c4eddd",
"updated_at": "2018-05-15T10:33:00Z"
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
put_channel_file_lifetime
(channel_id: str, file_id: str, lifetime: str) → dict¶update a file lifetime in a channel.
API reference: PUT /channels/<channel_id>/<file_id>/lifetime
channel_id = "1230000000000"
file_id = "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9"
lifetime = "1week"
response = api_client.put_channel_file_life(channel_id, file_id, life)
Response Syntax:
{
"channel_id": "1230000000000",
"file_id": "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9",
"lifetime": "1week"
}
put_channel_file_metadata
(channel_id: str, file_id: str, metadata: dict = None) → dict¶update a file metadata in a channel.
API reference: PUT /channels/<channel_id>/<file_id>/metadata
channel_id = "1230000000000"
file_id = "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9"
metadata = {
"x-abeja-meta-filename": "test.csv"
}
response = api_client.put_channel_file_metadata(channel_id, file_id, metadata)
Response Syntax:
{
"uploaded_at": "2018-05-10T11:02:10+00:00"
"download_uri": "...",
"url_expires_on": "2018-05-15T18:57:03+00:00",
"metadata": {
"x-abeja-sys-meta-organizationid": "1200123565071",
"x-abeja-meta-filename": "test.csv"
},
"file_id": "20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9",
"content_type": "text/csv",
}
unarchive_bucket
(organization_id: str, bucket_id: str)¶unarchive a bucket
API reference: POST /organizations/<organization_id>/buckets/<bucket_id>/unarchive
organization_id = "1234567890123"
bucket_id = "1230000000000"
response = api_client.unarchive_bucket(
organization_id, bucket_id)
Response Syntax:
{
"organization_id": "1234567890123",
"bucket": {
"updated_at": "2018-06-06T09:43:34Z",
"security_method": "organization",
"name": "example-bucket",
"display_name": "example-bucket",
"description": "this is sample bucket",
"created_at": "2018-05-30T10:44:28Z",
"bucket_id": "1234567890123",
"archived": false
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
unarchive_channel
(organization_id: str, channel_id: str)¶unarchive a channel
API reference: POST /organizations/<organization_id>/channels/<channel_id>/unarchive
organization_id = "1234567890123"
channel_id = "1230000000000"
response = api_client.unarchive_channel(
organization_id, channel_id)
Response Syntax:
{
"organization_id": "1234567890123",
"channel": {
"updated_at": "2018-06-06T09:43:34Z",
"storage_type": "datalake",
"security_method": "organization",
"name": "example-channel",
"display_name": "example-channel",
"description": "this is sample channel",
"created_at": "2018-05-30T10:44:28Z",
"channel_id": "1234567890123",
"archived": false
},
"organization_name": "abeja-inc",
"created_at": "2017-09-12T10:11:46Z",
"updated_at": "2017-09-12T10:11:46Z"
}
upload_bucket_file
(organization_id: str, bucket_id: str, file_obj: typing.IO, file_location: str, content_type: str, metadata: dict = None, lifetime: str = None) → dict¶upload a file to a bucket.
API reference: POST /organizations/<organization_id>/buckets/<bucket_id>/files
organization_id = "1234567890123"
bucket_id = "1230000000000"
file_location = "target/sample.jpg"
content_type = "image/jpeg"
metadata = {
"x-abeja-meta-filename": "target/sample.jpg"
}
with open('sample.jpg', 'rb') as f:
response = api_client.upload_bucket_file(
bucket_id, f, content_type, metadata=metadata)
Response Syntax:
{
"uploaded_at": null,
"metadata": {
"x-abeja-meta-filename": "sample.jpg"
},
"lifetime": "1day",
"content_type": "image/jpeg",
"file_id": "20180515T180605-f4acc798-9afa-40a1-b500-ebce42a4fa3f"
}
upload_bucket_files
(organization_id: str, bucket_id: str, target_dir: str, lifetime: str = None) → dict¶upload files on your specified directory to a bucket.
API reference: POST /organizations/<organization_id>/buckets/<bucket_id>/files
organization_id = "1234567890123"
bucket_id = "1230000000000"
target_dir = "./data"
response = api_client.upload_bucket_files(organization_id, bucket_id, target_dir)
Response Syntax:
{
"messages": [
{ "message": "Upload failed. file (20180510T110208-193d0d17-f0b1-4549-96df-651c02ccb8c9)" },
]
}