H2O Drive Python Client
Project description
h2o-drive
H2O Drive Python Client.
Installation
pip install h2o-drive
Usage
Connecting to H2O Drive
import h2o_drive
drive = await h2o_drive.Drive()
When used within the H2O AI Cloud environment or locally with the H2O AI Cloud CLI configured, no further configuration is needed.
h2o_drive.Drive()
can be configured via its optional parameters:
token
: Token or token provider to use. If not specified, it's determined automatically.endpoint_url
: URL of the Drive endpoint. If not specified, it's determined automatically.sts_endpoint_url
: URL of the STS endpoint. If not specified, it's determined automatically.environment
: URL of the H2O.ai cloud environment. Used only when determining a missing token or URL.config_path
: Path to the H2O.ai CLI config. Used only when determining a missing token or URL.session_ttl_seconds
: The duration, in seconds, of the role session.read_timeout_seconds
: The time in seconds until a timeout exception is thrown when reading from Drive.
Object Operations
To perform object operations, first navigate to the user's personal drive bucket:
my_bucket = drive.my_bucket()
Continue operating at the root of the user's bucket (generally not needed) or navigate into a particular space (a.k.a. a directory path) with one of the following. The home
space is a good place to start.
my_home_space = my_bucket.home()
# or
my_other_space = my_bucket.workspace("my_other_space")
Once in a space within a user's bucket (or the root of the bucket), the following operations are possible:
-
upload_file
uploads a local file to the user's Drive. It takes two arguments:file_name
: The file to upload.object_name
: The name to give to the uploaded file once it becomes an object in our Drive bucket.
-
list_objects
lists objects in the user's drive. It takes one optional argument:prefix
: When set, only objects whose names start with the specified prefix are returned.
-
download_file
downloads an object as a local file. It takes two arguments:object_name
: The name of the object (including prefix) to download.file_name
: Path to where the object should be saved as a local file.
-
delete_object
Deletes an object from the user's drive. It takes a single argument:object_name
: The name of the object (including prefix) to delete.
-
generate_presigned_url
generates a presigned URL through which an object in the drive can be accessed. It takes two arguments:object_name
: The name of the object (including prefix) to generate a presigned URL for.ttl_seconds
: (Optional) How long, in seconds, the URL should be good for.
Examples
Example: Connect to the home
space of a user's drive bucket, write a local file, and then list the contents
import h2o_drive
drive = await h2o_drive.Drive()
my_home_space = drive.my_bucket().home()
with open("test-file.txt", "w") as f:
f.write("Hello, world!")
await my_home_space.upload_file("test-file.txt", "uploaded-object-name.txt")
objects = await my_home_space.list_objects()
print(objects)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for h2o_drive-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f2166ce900c855fd186e4198c2a133a8704fc1284577732e851d2f86b84ea3a |
|
MD5 | cbd3b8c96d02f5960d9762ce1d87e983 |
|
BLAKE2b-256 | d1c043d175f1d004acbaaece0eba2f96a0df01b76f9dcb28d3d8903f61920c5a |