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

Uploaded Source

Built Distribution

h2o_drive-4.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: h2o_drive-4.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for h2o_drive-4.0.0.tar.gz
Algorithm Hash digest
SHA256 dd3e4b3bc88bd4e5daeda3e7f4589a01a388d0c440a3a132f600860aa76e3e19
MD5 36930629f0e7a144d423a3d54b30050d
BLAKE2b-256 95d9c349834a10994b0d795bfb37b0871c4318580509868001a43cfa9a457d30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: h2o_drive-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for h2o_drive-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 248554d054f7542d2cc30bd5017dca585114b5a3cd653f6ab75ff619fb0c303b
MD5 62350dd74010105e83744cbd62d7ec0b
BLAKE2b-256 505d0134a147c0310af8d5cfb5ba2b21b290526e6c1d943199eaa788b9268380

See more details on using hashes here.

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