Python Client Guide
Installation
The H2O Drive python client is published on PyPI and can be installed using pip.
pip install h2o-drive
Using the client
Once installed, the package can be imported using import h2o_drive
.
import h2o_drive
drive = await h2o_drive.Drive()
Manage files with H2O Drive
- In the H2O AI Cloud environment, the running Notebook and JupyterLab environments operate on separate machines. This separation helps with cost control and improves operationalization when you’re ready to productionalize your notebooks.
- H2O Drive allows you to upload files from your local machine or other locations directly into your cloud environment. You can access H2O Drive from the H2O AI Cloud homepage.
- After you’ve uploaded your data, you can manage files in your H2O Drive storage directly from your Python environment. The following sections describe how to list files in your storage and download them to your local environment.
List files in your Storage
Use the following code to connect to H2O Drive and list all files in your storage:
import h2o_drive
# Connect to your storage
drive_client = await h2o_drive.Drive()
my_bucket = drive_client.my_bucket()
# View all files in your storage
all_objects = await my_bucket.list_objects()
print([o.key for o in all_objects])
This code connects to your H2O Drive instance and prints a list of file names in your storage.
Download a file from H2O Drive
To download a file from your H2O Drive storage to your local environment, use the following code:
# Download the file first to the notebook
await my_bucket.download_file(all_objects[0].key, "./downloaded-file.csv")
info
When this python client is used within the H2O AI Cloud environment or locally with the H2O AI Cloud CLI configured, no further configuration is needed.
To start using the H2O Drive python client with H2O AI Cloud, follow the instructions on this notebook.
Feedback
- Submit and view feedback for this page
- Send feedback about H2O Drive to cloud-feedback@h2o.ai