Skip to main content

H2O Drive Python Client

Project description

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 details
  • userdrive_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)

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-4.1.0.tar.gz (9.6 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-4.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: h2o_drive-4.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for h2o_drive-4.1.0.tar.gz
Algorithm Hash digest
SHA256 a0546b994e3cd806fdec5f6744b58eaa60986a7eef8d52d83aabc723e4e6d511
MD5 ad2c87a83243139f220a451a341ae2a3
BLAKE2b-256 66a6ae1097283d2ea229e9c1bcd00bdb1c0fb229e385593ac6e526d5567db1e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h2o_drive-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for h2o_drive-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 148b5816d3868778762e7e42368835885ad81751b575d5b9c5f19dc692481634
MD5 14eb560bfa1ec077b160268d39827d25
BLAKE2b-256 a1c0f90e0794b3bb9bdc748aa309922f1d4391c39d5823cc4f8307ddf6808cfd

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