airflow.providers.alibaba.cloud.hooks.oss

Module Contents

Classes

OSSHook

Interact with Alibaba Cloud OSS, using the oss2 library.

Functions

provide_bucket_name(func)

Function decorator that unifies bucket name and key taken from the key

unify_bucket_name_and_key(func)

Function decorator that unifies bucket name and key taken from the key

Attributes

T

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

Function decorator that unifies bucket name and key taken from the key in case no bucket name and at least a key has been passed to the function.

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

Function decorator that unifies bucket name and key taken from the key in case no bucket name and at least a key has been passed to the function.

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(self)[source]

Returns connection for the hook.

static parse_oss_url(ossurl)[source]

Parses 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(self, key, bucket_name=None)[source]

Check if object exists.

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

  • bucket_name (Optional[str]) -- the name of the bucket

Returns

True if it exists and False if not.

Return type

bool

get_bucket(self, bucket_name=None)[source]

Returns a oss2.Bucket object

Parameters

bucket_name (Optional[str]) -- the name of the bucket

Returns

the bucket object to the bucket name.

Return type

oss2.api.Bucket

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

Loads a string to OSS

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

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

  • bucket_name (Optional[str]) -- the name of the bucket

upload_local_file(self, 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 (Optional[str]) -- the name of the bucket

download_file(self, 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 (Optional[str]) -- the name of the bucket

Returns

the file name.

Return type

str

delete_object(self, key, bucket_name=None)[source]

Delete object from OSS

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

  • bucket_name (Optional[str]) -- the name of the bucket

delete_objects(self, key, bucket_name=None)[source]

Delete objects from OSS

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

  • bucket_name (Optional[str]) -- the name of the bucket

delete_bucket(self, bucket_name=None)[source]

Delete bucket from OSS

Parameters

bucket_name (Optional[str]) -- the name of the bucket

create_bucket(self, bucket_name=None)[source]

Create bucket

Parameters

bucket_name (Optional[str]) -- the name of the bucket

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

Append string to a remote existing file

Parameters
  • bucket_name (Optional[str]) -- 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(self, bucket_name, key)[source]

Read oss remote object content with the specified key

Parameters
  • bucket_name (Optional[str]) -- the name of the bucket

  • key (str) -- oss bucket key

head_key(self, bucket_name, key)[source]

Get meta info of the specified remote object

Parameters
  • bucket_name (Optional[str]) -- the name of the bucket

  • key (str) -- oss bucket key

key_exist(self, bucket_name, key)[source]

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

Parameters
  • bucket_name (Optional[str]) -- the name of the bucket

  • key (str) -- oss bucket key

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

Was this entry helpful?