Skip to content

Operator

The blocking equivalent of AsyncOperator.

Operator is the entry point for all blocking APIs.

See Also

AsyncOperator

capability() #

Get all capabilities of this operator.

Returns:

Type Description
Capability

The capability of the operator.

check() #

Check if the operator is able to work correctly.

Raises:

Type Description
Exception

If the operator is not able to work correctly.

copy(source, target) #

Copy a file from one path to another.

Parameters:

Name Type Description Default
source str

The path to the source file.

required
target str

The path to the target file.

required

create_dir(path) #

Create a directory at the given path.

Notes

To indicate that a path is a directory, it must end with a /. This operation is always recursive, like mkdir -p.

Parameters:

Name Type Description Default
path str

The path to the directory.

required

delete(path) #

Delete a file at the given path.

Notes

This operation will not return an error if the path does not exist.

Parameters:

Name Type Description Default
path str

The path to the file.

required

exists(path) #

Check if a path exists.

Parameters:

Name Type Description Default
path str

The path to check.

required

Returns:

Type Description
bool

True if the path exists, False otherwise.

layer(layer) #

Add a new layer to this operator.

Parameters:

Name Type Description Default
layer Layer

The layer to add.

required

Returns:

Type Description
Operator

A new operator with the layer added.

list(path, *, limit=None, start_after=None, recursive=None, versions=None, deleted=None) #

List entries in the given directory.

Parameters:

Name Type Description Default
path str

The path to the directory.

required
limit int

The maximum number of entries to return.

None
start_after str

The entry to start after.

None
recursive bool

Whether to list recursively.

None
versions bool

Whether to list versions.

None
deleted bool

Whether to list deleted entries.

None

Returns:

Type Description
BlockingLister

An iterator over the entries in the directory.

open(path, mode, **kwargs) #

Open a file-like object for the given path.

The returning file-like object is a context manager.

Parameters:

Name Type Description Default
path str

The path to the file.

required
mode str

The mode to open the file in. Only "rb" and "wb" are supported.

required
**kwargs Any

Additional options for the underlying reader or writer.

{}

Returns:

Type Description
File

A file-like object.

read(path, *, version=None, concurrent=None, chunk=None, gap=None, offset=None, prefetch=None, size=None, if_match=None, if_none_match=None, if_modified_since=None, if_unmodified_since=None, content_type=None, cache_control=None, content_disposition=None) #

Read the entire contents of a file at the given path.

Parameters:

Name Type Description Default
path str

The path to the file.

required
version str

The version of the file.

None
concurrent int

The number of concurrent readers.

None
chunk int

The size of each chunk.

None
gap int

The gap between each chunk.

None
offset int

The offset of the file.

None
prefetch int

The number of bytes to prefetch.

None
size int

The size of the file.

None
if_match str

The ETag of the file.

None
if_none_match str

The ETag of the file.

None
if_modified_since str

The last modified time of the file.

None
if_unmodified_since str

The last modified time of the file.

None
content_type str

The content type of the file.

None
cache_control str

The cache control of the file.

None
content_disposition str

The content disposition of the file.

None

Returns:

Type Description
bytes

The contents of the file as bytes.

remove_all(path) #

Recursively remove all files and directories at the given path.

Parameters:

Name Type Description Default
path str

The path to remove.

required

rename(source, target) #

Rename (move) a file from one path to another.

Parameters:

Name Type Description Default
source str

The path to the source file.

required
target str

The path to the target file.

required

scan(path, *, limit=None, start_after=None, versions=None, deleted=None) #

Recursively list entries in the given directory.

Parameters:

Name Type Description Default
path str

The path to the directory.

required
limit int

The maximum number of entries to return.

None
start_after str

The entry to start after.

None
versions bool

Whether to list versions.

None
deleted bool

Whether to list deleted entries.

None

Returns:

Type Description
BlockingLister

An iterator over the entries in the directory.

stat(path, *, version=None, if_match=None, if_none_match=None, if_modified_since=None, if_unmodified_since=None, content_type=None, cache_control=None, content_disposition=None) #

Get the metadata of a file at the given path.

Parameters:

Name Type Description Default
path str

The path to the file.

required
version str

The version of the file.

None
if_match str

The ETag of the file.

None
if_none_match str

The ETag of the file.

None
if_modified_since datetime

The last modified time of the file.

None
if_unmodified_since datetime

The last modified time of the file.

None
content_type str

The content type of the file.

None
cache_control str

The cache control of the file.

None
content_disposition str

The content disposition of the file.

None

Returns:

Type Description
Metadata

The metadata of the file.

to_async_operator() #

Create a new AsyncOperator from this blocking operator.

Returns:

Type Description
AsyncOperator

The async operator.

write(path, bs, *, append=None, chunk=None, concurrent=None, cache_control=None, content_type=None, content_disposition=None, content_encoding=None, if_match=None, if_none_match=None, if_not_exists=None, user_metadata=None) #

Write bytes to a file at the given path.

This function will create a file if it does not exist, and will overwrite its contents if it does.

Parameters:

Name Type Description Default
path str

The path to the file.

required
bs bytes

The contents to write to the file.

required
append bool

Whether to append to the file instead of overwriting it.

None
chunk int

The chunk size to use when writing the file.

None
concurrent int

The number of concurrent requests to make when writing the file.

None
cache_control str

The cache control header to set on the file.

None
content_type str

The content type header to set on the file.

None
content_disposition str

The content disposition header to set on the file.

None
content_encoding str

The content encoding header to set on the file.

None
if_match str

The ETag to match when writing the file.

None
if_none_match str

The ETag to not match when writing the file.

None
if_not_exists bool

Whether to fail if the file already exists.

None
user_metadata dict

The user metadata to set on the file.

None