Skip to main content

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

h2o_drive-2.0.1.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

h2o_drive-2.0.1-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page