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': 'data.txt', 'size': 9}, {'is_file': True, 'last_modified': ..., 'name': 'hello.bin', 'size': 11}]
>>> b.delete("mybucket/hello.bin")
>>> b.exists("mybucket/hello.bin")
False
acls(path)
Retrieve the access control list (ACL) for a specific blob path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The blob path for which to retrieve the ACL. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ACL |
ACL
|
The ACL for the blob path. |
delete(name)
Delete a blob.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to delete. |
required |
exists(name)
Check if a blob exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the blob exists, False otherwise. |
get(name)
Get a blob object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Blob |
bytes
|
The blob object. |
get_file(name, path)
Copy a blob file to a local file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to retrieve. |
required |
path
|
str
|
The path to store the blob as a file. |
required |
ls(prefix, recursive=False)
List files in the specified prefix. If recursive is True, list files in subdirectories recursively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The prefix to list files from. |
required |
recursive
|
bool
|
Whether to list files in subdirectories recursively. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[str]
|
A list of file names in the specified path. If recursive is True, the list will contain files in subdirectories recursively. |
put(name, blob, acl=None)
Put a blob object into the blob storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to create. |
required |
blob
|
bytes | str
|
The blob object to store. |
required |
acl
|
ACL
|
The access control list for the blob. |
None
|
put_file(name, path, acl=None)
Copy a local file to a blob.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the blob to create. |
required |
path
|
str
|
The path of the local file to copy. |
required |
acl
|
ACL
|
The access control list for the blob. |
None
|
set_acls(path, acls)
Set the access control list (ACL) for a specific blob path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The blob path for which to set the ACL. |
required |
acls
|
ACL
|
The ACL to apply. |
required |