# Import dependenciesfrom encord import EncordUserClient# Define constantsSSH_PATH ="file-path-to-ssh-private-key"# Preset ID to add to the collectionPRESET_ID ="unique-preset-filter-id"# Initialize the user client using the SSH private keyuser_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Delete the preset by IDuser_client.delete_preset(PRESET_ID)
List all Filter Presets in Index by name with their unique identifier.
# Import dependenciesfrom encord import EncordUserClientSSH_PATH ="file-path-to-ssh-private-key"user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Get Preset Filterspresets = user_client.list_presets()# List Preset Filters by name and UUIDfor preset in presets:print(preset.name, preset.uuid)
This code lists the filters that make up the filter preset into a JSON file format.
Filters are of the following types:
Global filters: Global filters can apply to the data in any top-level Folder. Examples: Data type, Storage Location, Quality Metrics.
Local filters: Local filters can apply ONLY to specific top-level Folders. Examples: Data title, File ID, Collection.
Returned results are a combination of Global and Local filters. While Global filters provide information about filter, Local filters provide a raw filter ID.
Adds all storage items that match the criteria specified by a filter preset to a Collection.
# Import dependenciesfrom encord import EncordUserClientfrom encord.orm.collection import Collectionfrom encord.orm.filter_preset import FilterPreset# Define constantsSSH_PATH ="file-path-to-ssh-private-key"COLLECTION_HASH ="unique-collection-id"# Preset ID to add to the collectionPRESET_ID ="unique-preset-filter-id"# Initialize the user client using the SSH private keyuser_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specific collection by hashcollection: Collection = user_client.get_collection(COLLECTION_HASH)# Add preset storage items to the collection by preset IDcollection.add_preset_items(PRESET_ID)print(f"Added preset {PRESET_ID} to collection {COLLECTION_HASH}.")
Removes all storage items that match the criteria specified by a filter preset from a Collection.
# Import dependenciesfrom encord import EncordUserClientfrom encord.orm.collection import Collectionfrom encord.orm.filter_preset import FilterPreset# Define constantsSSH_PATH ="file-path-to-key-private-key"COLLECTION_HASH ="collection-unique-id"# Preset ID to remove contents from the collectionPRESET_ID ="preset-filter-unique-id"# Initialize the user client using the SSH private keyuser_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specific collection by hashcollection: Collection = user_client.get_collection(COLLECTION_HASH)# Remove preset storage items from the collection by preset IDcollection.remove_preset_items(PRESET_ID)print(f"Removed preset {PRESET_ID} from collection {COLLECTION_HASH}.")
List all Collections in Index by name with their unique identifier.
# Import dependenciesfrom encord import EncordUserClientSSH_PATH ="file-path-to-your-ssh-private-key"user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Get Collectioncollections = user_client.list_collections()# Print out the names of the Collectionsfor collection in collections:print(collection.name, collection.uuid)
# Import dependenciesfrom encord import EncordUserClientfrom encord.orm.storage import StorageItemTypefrom encord.orm.collection import Collectionfrom encord.orm.filter_preset import FilterPreset# Define constantsSSH_PATH ="file-path-to-ssh-private-key"COLLECTION_HASH ="collection-unique-id"# Initialize the user client using the SSH private keyuser_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specific collection by hashcollection: Collection = user_client.get_collection(COLLECTION_HASH)# Initialize an empty list to store itemsitems =[]# Iterate over storage items and append them to the listfor item in collection.list_items(): items.append(item)print(f"UUID: {item.uuid}, Name: {item.name}, Type: {item.item_type}")