Skip to content

Blob

Interface for Datatailr's binary large object (blob) storage.

Blob storage lets you persist and retrieve arbitrary files and binary data. Each blob is identified by a unique name (key/path).

Notes

This class wraps Datatailr blob operations (list/copy/read/write/delete). Large reads/writes use temporary files internally.

Examples:

Basic file copy to/from blob storage:

>>> from datatailr import Blob
>>> b = Blob()
>>> _ = open("/tmp/data.txt", "wb").write(b"qwerty123")
>>> b.put_file("mybucket/data.txt", "/tmp/data.txt")
>>> b.get_file("mybucket/data.txt", "/tmp/data_copy.txt")

Read/write blob contents as bytes:

>>> payload = b"hello world"
>>> b.put("mybucket/hello.bin", payload)
>>> data = b.get("mybucket/hello.bin")
>>> data == payload
True

List and delete:

>>> sorted(b.ls("mybucket/"), key=lambda x: x["name"])
[{'is_file': True, 'last_modified': ..., 'name': 'mybucket/data.txt', 'size': 9}, {'is_file': True, 'last_modified': ..., 'name': 'mybucket/hello.bin', 'size': 11}]
>>> b.delete("mybucket/hello.bin")
>>> b.exists("mybucket/hello.bin")
False

acls

Retrieve the access control list (ACL) for a specific blob path.

Parameters:

  • path

    (str) –

    The blob path for which to retrieve the ACL.

Returns:

  • ACL ( ACL ) –

    The ACL for the blob path.

delete

Delete a blob.

Parameters:

  • name

    (str) –

    The name of the blob to delete.

exists

Check if a blob exists.

Parameters:

  • name

    (str) –

    The name of the blob to check.

Returns:

  • bool ( bool ) –

    True if the blob exists, False otherwise.

get

Get a blob object.

Parameters:

  • name

    (str) –

    The name of the blob to retrieve.

Returns:

  • Blob ( bytes ) –

    The blob object.

get_file

Copy a blob file to a local file.

Parameters:

  • name

    (str) –

    The name of the blob to retrieve.

  • path

    (str) –

    The path to store the blob as a file.

ls

List files in the specified prefix. If recursive is True, list files in subdirectories recursively.

Parameters:

  • prefix

    (str) –

    The prefix to list files from.

  • recursive

    (bool, default: False ) –

    Whether to list files in subdirectories recursively.

  • filter_by

    (str, default: '' ) –

    The filter expression to apply to the list of files.

  • limit

    (int, default: -1 ) –

    The maximum number of files to return.

  • offset

    (int, default: 0 ) –

    The offset to start returning files from.

Returns:

  • list ( list[dict] ) –

    A list of file dictionaries in the specified path. If recursive is True, the list will contain files in subdirectories recursively.

  • list[dict]

    Each dictionary contains the following keys:

  • list[dict]
    • name: The name of the file.
  • list[dict]
    • size: The size of the file.
  • list[dict]
    • last_modified: The last modified time of the file.
  • list[dict]
    • is_file: Whether the file is a file.

put

Put a blob object into the blob storage.

Parameters:

  • name

    (str) –

    The name of the blob to create.

  • blob

    (bytes | str) –

    The blob object to store.

  • acl

    (ACL, default: None ) –

    The access control list for the blob.

put_file

Copy a local file to a blob.

Parameters:

  • name

    (str) –

    The name of the blob to create.

  • path

    (str) –

    The path of the local file to copy.

  • acl

    (ACL, default: None ) –

    The access control list for the blob.

set_acls

Set the access control list (ACL) for a specific blob path.

Parameters:

  • path

    (str) –

    The blob path for which to set the ACL.

  • acls

    (ACL) –

    The ACL to apply.