Manage the images in your DataGym.ai Datasets with our Python API
The Image objects in our Python API are not real images (in bytes) but hold the reference attributes (ID, name, etc.) from images in DataGym.ai. However, the Python API Client allows you to directly download these images from your DataGym.ai Projects.
1. Choose the Dataset you want to upload images to
dataset = client.get_dataset_by_name("Dataset_Name")
2.1 Upload a local image to DataGym.ai
uploaded_image = client.upload_image(dataset.id, "PATH_TO_LOCAL_IMAGE")
optionally you can manually set the image name
uploaded_image = client.upload_image(dataset.id, "PATH_TO_LOCAL_IMAGE", "name.jpg")
2.2 Upload from image urls
image_url_list = [image_url_1, image_url_2]
upload_results = client.create_images_from_urls(dataset.id, image_url_list)
1. Choose a Project (or Dataset)
dummy_project = client.get_project_by_name("Dummy_Project")
2. Choose an image
We simple take the first image of our Dummy Project for this example
dummy_images = dummy_project.get_images()
first_dummy_img = dummy_images
You can download and store the selected image as byte stream via the
download_image_bytesmethod of the API Client. The method requires the Image object you selected during the recent steps.
img_data = client.download_image_bytes(image_id=first_dummy_img)
download_image_bytesreturns the image as bytes in Python
Use-Case: Do you want to inspect the image you downloaded in your application? Let's use some additional packages to visualize our newly downloaded image
from PIL import Image
image = Image.open(io.BytesIO(image_data))
This little script will view the Image on your machine.
You can also directly download an image to your machine. Therefore, execute the
download_imagemethod which requires the Image object you want to download and the destination on your machine.
To delete an image from your DataGym.ai Dataset use the
delete_imagemethod of the Client class. The method only requires an Image Object.
delete_success = client.delete_image(image=first_dummy_img)
Trueif the image was successfully deleted
The Image object in the Python API is modeled after DataGym's Images.