airflow.providers.alibaba.cloud.hooks.oss

Module Contents

Classes

OSSHook

Interact with Alibaba Cloud OSS, using the oss2 library.

Functions

provide_bucket_name(func)

Unify bucket name and key if a key is provided but not a bucket name.

unify_bucket_name_and_key(func)

Unify bucket name and key if a key is provided but not a bucket name.

Attributes

T

airflow.providers.alibaba.cloud.hooks.oss.T[source]
airflow.providers.alibaba.cloud.hooks.oss.provide_bucket_name(func)[source]

Unify bucket name and key if a key is provided but not a bucket name.

airflow.providers.alibaba.cloud.hooks.oss.unify_bucket_name_and_key(func)[source]

Unify bucket name and key if a key is provided but not a bucket name.

class airflow.providers.alibaba.cloud.hooks.oss.OSSHook(region=None, oss_conn_id='oss_default', *args, **kwargs)[source]

Bases: airflow.hooks.base.BaseHook

Interact with Alibaba Cloud OSS, using the oss2 library.

conn_name_attr = 'alibabacloud_conn_id'[source]
default_conn_name = 'oss_default'[source]
conn_type = 'oss'[source]
hook_name = 'OSS'[source]
get_conn()[source]

Return connection for the hook.

static parse_oss_url(ossurl)[source]

Parse the OSS Url into a bucket name and key.

Parameters

ossurl (str) – The OSS Url to parse.

Returns

the parsed bucket name and key

Return type

tuple

object_exists(key, bucket_name=None)[source]

Check if object exists.

Parameters
  • key (str) – the path of the object

  • bucket_name (str | None) – the name of the bucket

Returns

True if it exists and False if not.

Return type

bool

get_bucket(bucket_name=None)[source]

Return a oss2.Bucket object.

Parameters

bucket_name (str | None) – the name of the bucket

Returns

the bucket object to the bucket name.

Return type

oss2.api.Bucket

load_string(key, content, bucket_name=None)[source]

Load a string to OSS.

Parameters
  • key (str) – the path of the object

  • content (str) – str to set as content for the key.

  • bucket_name (str | None) – the name of the bucket

upload_local_file(key, file, bucket_name=None)[source]

Upload a local file to OSS.

Parameters
  • key (str) – the OSS path of the object

  • file (str) – local file to upload.

  • bucket_name (str | None) – the name of the bucket

download_file(key, local_file, bucket_name=None)[source]

Download file from OSS.

Parameters
  • key (str) – key of the file-like object to download.

  • local_file (str) – local path + file name to save.

  • bucket_name (str | None) – the name of the bucket

Returns

the file name.

Return type

str | None

delete_object(key, bucket_name=None)[source]

Delete object from OSS.

Parameters
  • key (str) – key of the object to delete.

  • bucket_name (str | None) – the name of the bucket

delete_objects(key, bucket_name=None)[source]

Delete objects from OSS.

Parameters
  • key (list) – keys list of the objects to delete.

  • bucket_name (str | None) – the name of the bucket

delete_bucket(bucket_name=None)[source]

Delete bucket from OSS.

Parameters

bucket_name (str | None) – the name of the bucket

create_bucket(bucket_name=None)[source]

Create bucket.

Parameters

bucket_name (str | None) – the name of the bucket

append_string(bucket_name, content, key, pos)[source]

Append string to a remote existing file.

Parameters
  • bucket_name (str | None) – the name of the bucket

  • content (str) – content to be appended

  • key (str) – oss bucket key

  • pos (int) – position of the existing file where the content will be appended

read_key(bucket_name, key)[source]

Read oss remote object content with the specified key.

Parameters
  • bucket_name (str | None) – the name of the bucket

  • key (str) – oss bucket key

head_key(bucket_name, key)[source]

Get meta info of the specified remote object.

Parameters
  • bucket_name (str | None) – the name of the bucket

  • key (str) – oss bucket key

key_exist(bucket_name, key)[source]

Find out whether the specified key exists in the oss remote storage.

Parameters
  • bucket_name (str | None) – the name of the bucket

  • key (str) – oss bucket key

get_credential()[source]
get_default_region()[source]

Was this entry helpful?