Tip
All actions for Storage folders and data unit can be found in the SDK references:
Create new folder
The following script creates a new folder in Storage. Ensure that you:
- Replace <private_key_path> with the path to your private key.
- Replace <folder_name> with the name you want to give your Storage folder.
- Replace
A folder to store my files
with a meaningful description for your folder. - Replace
my: folder_metadata
with any metadata you want to add to the folder. Remove the line if you do not want to add any metadata to the folder.
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
Upload data to an existing folder
The following scripts add data to a folder that already exists in Storage.
- For images and videos replace
User/path/to/my/file
with the path to your image or video file. - For DICOM series replace
User/path/to/dicom/file1
andUser/path/to/dicom/file2
with the paths to the DICOM files you want to create a series from. Add as many file paths as necessary. - For image groups and image sequences, replace
User/path/to/image/file1
andUser/path/to/image/file2
with the paths to the image files you want to create an image group or image sequence from. Add as many file paths as necessary.
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Upload an image to the folder. Substitute file path
file_path = "User/path/to/my/file"
client_metadata = {"client": "metadata"}
image_uuid = folder.upload_image(file_path, None, client_metadata=client_metadata)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Upload a video to the folder. Substitute file path
file_path = "User/path/to/my/file"
client_metadata = {"client": "metadata"}
video_uuid = folder.upload_video(file_path, None, client_metadata=client_metadata)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create an image group and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/image/file1", "User/path/to/image/file2"] # List of paths to image files
client_metadata = {"client": "metadata"}
group_uuid = folder.create_image_group(
file_paths,
file_title,
client_metadata=client_metadata,
)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create an image sequence and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/image/file1", "User/path/to/image/file2"]
client_metadata = {"client": "metadata"}
sequence_uuid = folder.create_image_group(
file_paths, # List of paths to image files
file_title,
client_metadata=client_metadata,
)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a DICOM series and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/dicom/file1", "User/path/to/dicom/file2"] # List of paths to DICOM files.
client_metadata = {"client": "metadata"}
series_uuid = folder.create_dicom_series(
file_paths
file_title,
client_metadata=client_metadata,
)
Upload data to a new folder
The following script creates a new folder in Storage and uploads image, video, DICOM, image group, or image sequence files to the newly created folder. A new folder is created each time the script is run.
In the following scripts, ensure that you:
- Replace <private_key_path> with the path to your private key.
- Replace <folder_name> with the name you want to give your Storage folder.
- Replace
A folder to store my files
with a meaningful description for your folder. - Replace
my: folder_metadata
with any metadata you want to add to the folder. Remove the line if you do not want to add any metadata to the folder. - For images and videos replace
User/path/to/my/file
with the path to your image or video file. - For DICOM series replace
User/path/to/dicom/file1
andUser/path/to/dicom/file2
with the paths to the DICOM files you want to create a series from. Add as many file paths as necessary. - For image groups and image sequences, replace
User/path/to/image/file1
andUser/path/to/image/file2
with the paths to the image files you want to create an image group or image sequence from. Add as many file paths as necessary.
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
# Upload an image to the folder. Substitute file path
file_path = "User/path/to/my/file"
client_metadata = {"client": "metadata"}
image_uuid = folder.upload_image(file_path, None, client_metadata=client_metadata)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
# Upload a video to the folder. Substitute file path
file_path = "User/path/to/my/file"
client_metadata = {"client": "metadata"}
video_uuid = folder.upload_video(file_path, None, client_metadata=client_metadata)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
# Create an image group and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/image/file1", "User/path/to/image/file2"] # List of paths to image files
client_metadata = {"client": "metadata"}
group_uuid = folder.create_image_group(
file_paths,
file_title,
client_metadata=client_metadata,
)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
# Create an image sequence and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/image/file1", "User/path/to/image/file2"]
client_metadata = {"client": "metadata"}
sequence_uuid = folder.create_image_group(
file_paths, # List of paths to image files
file_title,
client_metadata=client_metadata,
)
from encord import EncordUserClient
# Instantiate Encord client by substituting the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Create a Storage folder
folder_name = "<folder_name>"
folder_description = "A folder to store my files"
folder_metadata = {"my": "folder_metadata"}
folder = user_client.create_storage_folder(folder_name, folder_description,client_metadata=folder_metadata)
# Create a DICOM series and upload it to the folder. Substitute file paths
file_title = "<file_title>"
file_paths = ["User/path/to/dicom/file1", "User/path/to/dicom/file2"] # List of paths to DICOM files.
client_metadata = {"client": "metadata"}
series_uuid = folder.create_dicom_series(
file_paths
file_title,
client_metadata=client_metadata,
)
List data units in a folder
Listing the files in a folder can be used to verify that all data unit were successfully uploaded.
- Replace <private_key_path> with the path to your private key.
- Replace <folder_name> with the name you want to give your Storage folder.
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List all data units
items = list(storage_folder.list_items())
# Output the retrieved data units
for item in items:
print(f"UUID: {item.uuid}, Name: {item.name}, Type: {item.item_type}")
else:
print("Folder not found.")
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List images
images = list(storage_folder.list_items(item_types=[StorageItemType.IMAGE]))
# Output the retrieved images
for image in images:
print(f"UUID: {image.uuid}, Name: {image.name}")
else:
print("Folder not found.")
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List videos
videos = list(storage_folder.list_items(item_types=[StorageItemType.VIDEO]))
# Output the retrieved videos
for video in videos:
print(f"UUID: {video.uuid}, Name: {video.name}")
else:
print("Folder not found.")
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List image groups
image_groups = list(storage_folder.list_items(item_types=[StorageItemType.IMAGE_GROUP]))
# Output the retrieved image groups
for group in image_groups:
print(f"UUID: {group.uuid}, Name: {group.name}")
else:
print("Folder not found.")
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List image sequences
image_sequences = list(storage_folder.list_items(item_types=[StorageItemType.IMAGE_SEQUENCE]))
# Output the retrieved image sequences
for sequence in image_sequences:
print(f"UUID: {sequence.uuid}, Name: {sequence.name}")
else:
print("Folder not found.")
from encord import EncordUserClient
from encord.orm.storage import StorageItemType, FoldersSortBy
# Authentication
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
# Find the storage folder by name
folder_name = "<folder_name>" # Replace with your folder's name
folders = list(user_client.find_storage_folders(search=folder_name, page_size=1))
# Ensure the folder was found
if folders:
storage_folder = folders[0]
# List DICOM series
dicom_series = list(storage_folder.list_items(item_types=[StorageItemType.DICOM_SERIES]))
# Output the retrieved DICOM series
for dicom in dicom_series:
print(f"UUID: {dicom.uuid}, Name: {dicom.name}")
else:
print("Folder not found.")