h2o-drive
Python Client for H2O Drive.
Installation
pip install h2o-drive
Usage
Connecting to H2O Drive
import h2o_drive
drive = h2o_drive.connect()
When used within the H2O AI Cloud environment or locally with the H2O AI Cloud CLI configured, no further configuration is needed.
h2o_drive.connect() can be configured via optional parameters:
discovery: The h2o_discovery.Discovery object through which to discover services for determining connection detailsuserdrive_url: URL to Drive's userdrive service.workspace_url: URL to Drive's workspacedrive service.sts_url: URL to the STS service.token_provider: A token provider generating authentication credentials.
Object Operations
To perform object operations, first open any Drive bucket. For example:
bucket = drive.user_bucket()
# or
bucket = drive.workspace_bucket("default")
Buckets have the following methods:
-
upload_file()uploads a local file, resulting in a new object at the specified key in the bucket. It takes two arguments:filename: The file to upload. The contents of this file will become an object in the Drive bucket.key: The key at which to store the resulting object. In other words, the name attached to the object.
-
list_objects()returns the list of objects in the bucket. It takes one optional argument:prefix: When specified, only objects at keys starting with the specified value are listed.
-
download_file()downloads the object at the specified key and writes it to the specified local file. It takes two arguments:key: The key of the object to download.filename: The file, on the local filesystem, the object is written to.
-
delete_object()deletes the object at the specified key. It takes a single argument:key: The key of the object to delete.
-
generate_presigned_url()generates a presigned URL for accessing the object at the specified key in the bucket. It takes two arguments:key: The key to generate a presigned URL for.duration_seconds: (Optional) The duration, in seconds, for which the URL should be valid. Defaults to 1 day.
-
with_prefix()returns a prefixed view of this bucket. All the keys in each of its object operations are automatically prefixed with the specified value. It takes a single argument:prefix: The key prefix to automatically apply to all object operations.
Examples
Example: Open the storage bucket for your personal H2O workspace, write a local file, and list its contents
import h2o_drive
# Prepare a local test file.
with open("test-file.txt", "w") as f:
f.write("Hello, world!")
drive = h2o_drive.connect()
bucket = drive.workspace_bucket("default")
await bucket.upload_file("test-file.txt", "drive-test/uploaded-test-object.txt")
objects = await bucket.list_objects()
print(objects)
Release files for h2o-drive 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| h2o_drive-4.1.0.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| h2o_drive-4.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.0 kB
Release files / h2o_drive-4.1.0.tar.gz
| Download URL | h2o_drive-4.1.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0546b994e3cd806fdec5f6744b58eaa60986a7eef8d52d83aabc723e4e6d511
|
|
BLAKE2b-256 checksum How to use checksums |
66a6ae1097283d2ea229e9c1bcd00bdb1c0fb229e385593ac6e526d5567db1e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / h2o_drive-4.1.0-py3-none-any.whl
| Download URL | h2o_drive-4.1.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
148b5816d3868778762e7e42368835885ad81751b575d5b9c5f19dc692481634
|
|
BLAKE2b-256 checksum How to use checksums |
a1c0f90e0794b3bb9bdc748aa309922f1d4391c39d5823cc4f8307ddf6808cfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|