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-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

h2o_drive-1.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file h2o_drive-1.0.0.tar.gz.

File metadata

  • Download URL: h2o_drive-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for h2o_drive-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8b844327e92e91fcbfb804208a55e8b8e46087734ca631365ca29f9c80591f93
MD5 8f0e013dbb8cbca4f9b702ecb894133d
BLAKE2b-256 31c8b6668ea6ffb036579179e2ab891cf620adfaedf4044086cc7fad32b2031e

See more details on using hashes here.

File details

Details for the file h2o_drive-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: h2o_drive-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for h2o_drive-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6077b2d212b2c47a43c5f6cf12a7723793c8b8fd7e07ea3cb9a87cc8424fc6d
MD5 b280fd242205d991f16da6d8b7693006
BLAKE2b-256 2a40f4d213449d0c686a3f9ceafcd2313ac4d9d1eae9f3ea0b7fa9ff4483a0db

See more details on using hashes here.

Supported by

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