### Instantiate Encord Client and Get Project Info (Python) Source: https://docs.encord.com/sdk-documentation/sdk-references/client Demonstrates how to initialize the EncordClient with project ID and API key, and then retrieve basic project information. This is the starting point for interacting with Encord API resources. ```python from encord.client import EncordClient client = EncordClient.initialize('YourProjectID', 'YourAPIKey') client.get_project() ``` -------------------------------- ### Example: Submit Annotation Tasks with Specific User (Python) Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-workflows-stages This Python example demonstrates submitting annotation tasks using a specific SSH private key and assigning tasks to a particular email address. It includes setting up the Encord User Client and iterating through annotation tasks within a project's workflow. ```python from encord.user_client import EncordUserClient from encord.workflow.stages.annotation import AnnotationStage, AnnotationTaskStatus from encord.workflow.stages.consensus_annotation import ConsensusAnnotationStage from encord.workflow.stages.consensus_review import ConsensusReviewStage from encord.workflow.stages.review import ReviewStage SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt" PROJECT_ID="" user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( Path(SSH_PATH).read_text() ) project = user_client.get_project(PROJECT_ID) workflow = project.workflow annotation_stage = workflow.get_stage(name="Annotate 1", type_=AnnotationStage) BUNDLE_SIZE = 100 # You can adjust this value as needed, but keep it <= 1000 with project.create_bundle(bundle_size=BUNDLE_SIZE) as bundle: for annotation_task in annotation_stage.get_tasks(): print(annotation_task.data_title) # Submit as someone explicitly annotation_task.submit(assignee='chris@acme.com', bundle=bundle) ``` -------------------------------- ### Add Keypoint Annotations (Python) Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches This section describes examples of importing keypoint annotations using the Encord SDK. It covers importing a single keypoint to an image, multiple instances of a keypoint across video frames, and multiple keypoints to a single image. Specific examples are provided for 'Pedicel' keypoints on 'blueberry_003.png' and 'Blueberries_video.mp4'. The exact code for these operations is not provided in this snippet but is implied to be available through the SDK. -------------------------------- ### Example: Import Keypoint Annotation Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches This Python example demonstrates importing a keypoint annotation for 'Pedicel' to a specific data unit within a project. It uses a provided SSH key path and project ID, specifying the label branch and data unit title. The code then sets the keypoint coordinates and links it to the label row before saving. ```python # Import dependencies from pathlib import Path from encord import EncordUserClient, Project from encord.objects import Object, ObjectInstance from encord.objects.coordinates import PointCoordinate # Configuration SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt" PROJECT_ID = "7d4ead9c-4087-4832-a301-eb2545e7d43b" CONSENSUS_BRANCH_NAME = "my-label-branch-I" # Specify your label branch DATA_UNIT_TITLE = "blueberry_003.png" # Specific data unit title ONTOLOGY_OBJECT_TITLE = "Pedicel" # Name of the keypoint object in your ontology # Create user client using access key user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( Path(SSH_PATH).read_text() ) # Get project for which labels are to be added project: Project = user_client.get_project(PROJECT_ID) # Specify the data unit to label in the given branch label_row = project.list_label_rows_v2( branch_name=CONSENSUS_BRANCH_NAME, # Filter by label branch data_title_eq=DATA_UNIT_TITLE )[0] # Initialize labels for the label row label_row.initialise_labels() # Find a keypoint annotation object in the project ontology keypoint_ontology_object: Object = project.ontology_structure.get_child_by_title( title=ONTOLOGY_OBJECT_TITLE, type_=Object ) # Instantiate an object instance from the keypoint ontology node keypoint_object_instance: ObjectInstance = keypoint_ontology_object.create_instance() # The x,y coordinates of the keypoint are specified as follows keypoint_object_instance.set_for_frames( coordinates=PointCoordinate( x=.1, y=.1 ), # Add the keypoint to the specified frame number frames=, # Replace with the actual frame number # There are multiple additional fields that can be set optionally: manual_annotation=True, confidence=1.0, ) # Link the object instance to the label row ``` -------------------------------- ### Audio File Upload Structure Example Source: https://docs.encord.com/sdk-documentation/index-sdk/custom-metadata/sdk-import-custom-metadata This is a placeholder for an example JSON file structure used for uploading audio files to Encord. The actual structure would define metadata and file references necessary for audio asset management. ```json { "message": "This is an example JSON file for uploading two audio files to Encord." } ``` -------------------------------- ### Simple Custom Metadata Import Example - Encord SDK (Python) Source: https://docs.encord.com/sdk-documentation/index-sdk/custom-metadata/sdk-import-custom-metadata This Python code provides a simplified example of importing custom metadata using the Encord SDK. It demonstrates the basic authentication process and the structure for updating metadata for a single data item. This snippet is useful for understanding the fundamental steps before implementing more complex updates. ```python # Import dependencies from encord import EncordUserClient from encord.http.bundle import Bundle from encord.orm.storage import StorageFolder, StorageItem, StorageItemType, FoldersSortBy # Authentication SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt" # Authenticate with Encord using the path to your private key user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ``` -------------------------------- ### Create a New Dataset in Encord Source: https://docs.encord.com/sdk-documentation/getting-started-sdk/sdk-register-data-otc Initializes a new dataset within the Encord platform. This example demonstrates setting the dataset title and storage location type. ```python from encord import EncordUserClient from encord.orm.dataset import StorageLocation user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="" ) dataset = user_client.create_dataset( dataset_title="Houses", dataset_type=StorageLocation.OTC, create_backing_folder=False, ) print(dataset_response) print(f"Using storage location: OTC") ``` -------------------------------- ### Initializing Encord Project and Polygon Objects Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-annotations-visual Setup procedure for connecting to the Encord platform, retrieving project ontology structures, and preparing label rows for batch processing. ```python from encord import EncordUserClient, Project from encord.objects import Object user_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path=SSH_PATH) project = user_client.get_project(PROJECT_ID) ontology_structure = project.ontology_structure polygon_ontology_object = ontology_structure.get_child_by_title(title="Blueberries", type_=Object) with project.create_bundle(bundle_size=BUNDLE_SIZE) as bundle: rows = project.list_label_rows_v2(data_title_eq=IMAGE_TITLE) ``` -------------------------------- ### Get Storage Items Source: https://docs.encord.com/sdk-documentation/sdk-references/user_client Retrieves storage items by their UUIDs in bulk. This is useful for fetching multiple items at once, for example, when retrieving items pointed to by `encord.orm.dataset.DataRow.backing_item_uuid` for all data rows of a dataset. ```APIDOC ## GET /storage/items ### Description Retrieves storage items by their UUIDs in bulk. ### Method GET ### Endpoint /storage/items ### Parameters #### Query Parameters - **item_uuids** (list[str | UUID]) - Required - List of UUIDs of items to retrieve. - **sign_url** (bool) - Optional - If True, pre-fetch signed URLs for the items. Defaults to False. ### Response #### Success Response (200) - **StorageItem** (List[StorageItem]) - A list of storage items. Items will be in the same order as `item_uuids` in the request. #### Error Response (400) - **ValueError**: If any of the item UUIDs is a badly formed UUID. - **AuthorizationError**: If some of the items with the given UUIDs do not exist or the user does not have access to them. ``` -------------------------------- ### Create and Copy Project Source: https://docs.encord.com/sdk-documentation/general-sdk/sdk-quick-lookup Illustrates the creation of a new project with specified title, dataset hashes, and workflow template. Also shows how to copy an existing project, with options to include datasets and collaborators. ```python project = user_client.create_project(project_title="", dataset_hashes=["", ""], workflow_template_hash="") new_project_hash = project.copy_project( copy_datasets=True, copy_collaborators=True, copy_models=False, ) ``` -------------------------------- ### Get Cloud Synced Folder Synchronization Result Source: https://docs.encord.com/sdk-documentation/sdk-references/storage Polls for the results of a cloud-synced folder synchronization job previously started with `sync_private_data_with_cloud_synced_folder_start`. Uses long polling to efficiently wait for job completion. ```APIDOC ## GET /storage/folders/sync_private_data_with_cloud_synced_folder/result ### Description Polls for the results of a cloud-synced folder synchronization job. This method efficiently waits for the job to complete or until a specified timeout is reached. ### Method GET ### Endpoint /storage/folders/sync_private_data_with_cloud_synced_folder/result ### Parameters #### Query Parameters - **sync_job_uuid** (UUID) - Required - The UUID of the synchronization job to poll for results. - **timeout_seconds** (int) - Optional - Maximum time in seconds to wait for the job to complete. Defaults to 7 days. ### Request Example ```json { "sync_job_uuid": "f0e9d8c7-b6a5-4321-0fed-cba987654321" } ``` ### Response #### Success Response (200) - **result** (orm_storage.SyncPrivateDataWithCloudSyncedFolderGetResultResponse) - An object containing the results of the synchronization job. #### Response Example ```json { "result": { "status": "COMPLETED", "files_added": 10, "files_updated": 5, "files_deleted": 2 } } ``` #### Error Response - **InvalidArgumentsError** - If the synchronization job UUID does not exist or is not associated with this folder. ``` -------------------------------- ### Filter Tasks by Data Hash Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-workflows-stages This example demonstrates how to filter tasks within any workflow stage using their data hashes. It involves setting up the EncordUserClient with SSH credentials and retrieving a project. The filtering logic itself would be applied when fetching or processing tasks from a stage, though the provided snippet focuses on the setup. ```python # Import dependencies from encord import EncordUserClient, Project from encord.workflow import AnnotationStage, ReviewStage, ConsensusAnnotationStage, ConsensusReviewStage, FinalStage # Constants SSH_PATH = "" PROJECT_HASH = "" # Create user client user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH ) # Get project ``` -------------------------------- ### Initialize Encord Client and Access Label Rows Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-annotations-visual Shows the setup required to authenticate with the Encord platform using an SSH private key and retrieve label rows for a specific project. ```python from encord import EncordUserClient from encord.objects import LabelRowV2 user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="" ) project = user_client.get_project("") first_label_row: LabelRowV2 = project.list_label_rows_v2()[0] first_label_row.initialise_labels() ``` -------------------------------- ### Configure General Task Agent with Encord SDK Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-task-agents Demonstrates how to authenticate with the Encord SDK, retrieve a specific project, and iterate through tasks within an Agent stage. It includes a placeholder for custom logic and instructions for moving tasks to a subsequent workflow pathway. ```python from encord.user_client import EncordUserClient from encord.workflow import AgentStage # Authenticate using the path to your private key user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="" ) # Specify the Project that contains the Task agent. Replace with the hash of your Project project = user_client.get_project() # Specify the Task Agent agent_stage = project.workflow.get_stage(name="Agent 1", type_=AgentStage) for task in agent_stage.get_tasks(): # Now you have the agent task containing the data hash # Insert you custom logic here # When the custom logic is completed, the task can be moved forward to the selected pathway task.proceed(pathway_name="continue to Review") ``` -------------------------------- ### Create Project from CVAT (Get Result) Source: https://docs.encord.com/sdk-documentation/sdk-references/user_client Checks the status and retrieves the result of a CVAT import process. This function is the second step in a two-step import process, requiring the UUID from the initial start call. It polls the server for completion within a specified timeout. ```python def create_project_from_cvat_get_result( cvat_import_uuid: UUID, *, timeout_seconds: int = 1 * 24 * 60 * 60 ) -> Union[CvatImporterSuccess, CvatImporterError] ``` -------------------------------- ### Get Editor Logs in Python Source: https://docs.encord.com/sdk-documentation/sdk-references/project Retrieves actions taken within the Encord Editor UI. Requires start and end times, with an optional 30-day range limit. Can filter by action, user email, data unit ID, or workflow stage ID. ```python def get_editor_logs( start_time: datetime.datetime, end_time: datetime.datetime, action: Optional[str] = None, actor_user_email: Optional[str] = None, workflow_stage_id: Optional[UUID] = None, data_unit_id: Optional[UUID] = None) -> Iterator[EditorLog] ``` -------------------------------- ### Initialize Encord Project and Skeleton Objects Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches Sets up the Encord user client, retrieves a project, and initializes the label row for skeleton annotation. This process requires a valid SSH private key and project identifiers. ```python from pathlib import Path from encord import EncordUserClient, Project from encord.objects import Object user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( Path("/path/to/key.txt").read_text() ) project: Project = user_client.get_project("PROJECT_ID") label_row = project.list_label_rows_v2(branch_name="branch", data_title_eq="file.mp4")[0] label_row.initialise_labels() skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title("Strawberry", type_=Object) ``` -------------------------------- ### Authenticate and Initialize Encord Project Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches Sets up the Encord client using SSH authentication and retrieves a project instance. This serves as the entry point for all project-level operations. ```python from pathlib import Path from encord import EncordUserClient user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=Path(SSH_PATH).read_text() ) project = user_client.get_project(PROJECT_ID) ``` -------------------------------- ### Create Project from CVAT (Combined Import) Source: https://docs.encord.com/sdk-documentation/sdk-references/user_client Imports a new Encord project from a CVAT export by combining the start and get result steps into a single function call. It requires a CVAT export file (using 'CVAT for images 1.1' option) and optionally transforms bounding boxes to polygons. The function polls the server for completion within a specified timeout. ```python def create_project_from_cvat( import_method: ImportMethod, dataset_name: str, review_mode: ReviewMode = ReviewMode.LABELLED, *, transform_bounding_boxes_to_polygons=False, timeout_seconds: int = 1 * 24 * 60 * 60 ) -> Union[CvatImporterSuccess, CvatImporterError] ``` -------------------------------- ### Import and Configure Skeleton Annotations with Encord SDK Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches Demonstrates how to initialize an Encord client, retrieve project ontology structures, and apply skeleton templates to specific data units. It covers the creation of object instances and the assignment of coordinate data to frames. ```python # Import dependencies from pathlib import Path from encord import EncordUserClient, Project from encord.objects import Object, ObjectInstance from encord.objects.coordinates import SkeletonCoordinate, SkeletonCoordinates from encord.objects.skeleton_template import SkeletonTemplate # Configuration SSH_PATH = "" PROJECT_ID = "" CONSENSUS_BRANCH_NAME = "" DATA_UNIT_TITLE = "" ONTOLOGY_OBJECT_TITLE = "" SKELETON_TEMPLATE_NAME = "" # Create user client using access key user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( Path(SSH_PATH).read_text() ) # Get project for which labels are to be added project: Project = user_client.get_project(PROJECT_ID) # Specify the data unit to label in the given branch label_row = project.list_label_rows_v2( branch_name=CONSENSUS_BRANCH_NAME, data_title_eq=DATA_UNIT_TITLE )[0] # Initialize labels for the label row label_row.initialise_labels() # Find a skeleton annotation object in the project ontology skeleton_ontology_object: Object = project.ontology_structure.get_child_by_title( title=ONTOLOGY_OBJECT_TITLE, type_=Object ) skeleton_template: SkeletonTemplate = project.ontology_structure.skeleton_templates[SKELETON_TEMPLATE_NAME] # Instantiate an object instance from the skeleton ontology node skeleton_object_instance: ObjectInstance = skeleton_ontology_object.create_instance() skeleton_hashes = [coord.feature_hash for coord in skeleton_template.skeleton.values()] skeleton_coordinates: SkeletonCoordinates = SkeletonCoordinates(values=[ SkeletonCoordinate( x=0.x0, y=0.y0, name='point_0', color='#000000', value="point_0", feature_hash=skeleton_hashes[0] ), SkeletonCoordinate( x=0.x1, y=0.y1, name='point_1', color='#000000', value="point_1", feature_hash=skeleton_hashes[1] ), SkeletonCoordinate( x=0.x2, y=0.y2, name='point_2', color='#000000', value="point_2", feature_hash=skeleton_hashes[2] ) ], name="" ) # Set coordinates for specific frames skeleton_object_instance.set_for_frames( coordinates=skeleton_coordinates, frames=0, manual_annotation=True, confidence=1.0, ) # Link and save label_row.add_object_instance(skeleton_object_instance) label_row.save() print("Label row updated with skeleton instance.") ``` -------------------------------- ### Install Encord SDK Dependencies Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-converting-ontology-shapes Command to install the necessary Python packages required to run the polygon-to-bounding-box conversion script. ```bash python -m pip install tqdm typer encord ``` -------------------------------- ### Install Encord conversion dependencies Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-converting-ontology-shapes Command to install the necessary Python packages including Encord SDK, OpenCV, and Typer for the conversion script. ```bash python -m pip install tqdm typer opencv-python numpy encord ``` -------------------------------- ### Initialize Encord User Client and Project using SSH Key (Python) Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-annotations-visual This Python snippet shows how to initialize the Encord User Client using an SSH private key and connect to a specific project. It includes setting up the domain and retrieving the project object. Dependencies include the Encord SDK and a valid SSH key path and project ID. ```python # Import dependencies from pathlib import Path from encord import EncordUserClient, Project from encord.objects import ChecklistAttribute, Object, ObjectInstance, Option, RadioAttribute, TextAttribute from encord.objects.coordinates import PointCoordinate from encord.objects.attributes import NumericAttribute SSH_PATH = "/Users/chris-encord/ssh-private-key.txt" # SSH_PATH = get_ssh_key() # replace it with access key PROJECT_ID = "00000000-0000-0000-0000-000000000000" BUNDLE_SIZE = 100 # Create user client using access key user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH, # For US platform users use "https://api.us.encord.com" domain="https://api.encord.com", ) # Get project for which labels are to be added project: Project = user_client.get_project(PROJECT_ID) assert project is not None, "Project not found — check PROJECT_ID" ``` -------------------------------- ### Create a new Encord project Source: https://docs.encord.com/sdk-documentation/sdk-references/user_client Initializes a new project with specified datasets, optional ontology, and workflow settings. Returns the unique project hash upon successful creation. ```python def create_project(project_title: str, dataset_hashes: List[str], project_description: str = "", ontology_hash: str = "", workflow_settings: ProjectWorkflowSettings = ManualReviewWorkflowSettings(), workflow_template_hash: Optional[str] = None) -> str ``` -------------------------------- ### Import Image Sequence Data Example Source: https://docs.encord.com/sdk-documentation/getting-started-sdk/sdk-register-data-azure An example of a JSON payload for importing image sequences into Encord. Each entry in 'image_groups' represents a distinct image sequence with its own title and associated object URLs. ```json { "image_groups": [ { "title": "Image sequence 001", "createVideo": true, "objectUrl_0": "https://myaccount.blob.core.windows.net/encordcontainer/01.jpg", "objectUrl_1": "https://myaccount.blob.core.windows.net/encordcontainer/02.jpg", "objectUrl_2": "https://myaccount.blob.core.windows.net/encordcontainer/DALL%C2%B7E+2022-09-08+18.53.25+-+firefighter+extinguishing+flames+around+computer+in+software+office+overgrown+by+foliage.png" }, { "title": "Image sequence 002", "createVideo": true, "objectUrl_0": "https://myaccount.blob.core.windows.net/encordcontainer/thing-01.jpg", "objectUrl_1": " Dict[str, Any] ``` -------------------------------- ### Pre-Labeling Videos Using Mock Model with Encord SDK Source: https://docs.encord.com/sdk-documentation/projects-sdk/sdk-task-agents This guide explains how to use the Encord SDK to pre-label videos. It assumes you have a model that processes video frames to output bounding boxes and confidence scores. The script selects random classes, generates random bounding boxes and confidence scores, and applies them to video frames before advancing them to the annotation stage. Authentication is handled via environment variables `ENCORD_SSH_KEY` or `ENCORD_SSH_KEY_FILE`. ```python # This is a conceptual example and requires a full script implementation. # The following pseudocode illustrates the process described in the documentation. # Assume necessary imports and authentication setup are done: # from encord.sdk import EncordUserClient # import random # import base64 # import requests # user_client = EncordUserClient.create_with_ssh_private_key(...) # project = user_client.get_project("") # def get_mock_model_predictions(video_frame_content): # """Simulates a mock model that returns bounding boxes and confidence scores.""" # # In a real scenario, this function would process the video frame # # and return predictions from your actual model. # # For this mock, we'll generate random data. # num_objects = random.randint(0, 5) # predictions = [] # for _ in range(num_objects): # # Generate random bounding box coordinates (x, y, w, h) # x = random.uniform(0, 1) # y = random.uniform(0, 1) # w = random.uniform(0.05, 0.2) # h = random.uniform(0.05, 0.2) # confidence = random.uniform(0.5, 0.95) # # Select a random class from the ontology (requires ontology access) # # random_class = random.choice(ontology_classes) # random_class = "random_object_class" # Placeholder # predictions.append({ # "box": [x, y, w, h], # "confidence": confidence, # "class": random_class # }) # return predictions # # Iterate through tasks (videos) in a specific stage # pre_label_stage = project.workflow.get_stage(name="Pre-Labeling", type_=AgentStage) # Example stage name # for task in pre_label_stage.get_tasks(): # label_row = project.list_label_rows_v2(data_hashes=[task.data_hash])[0] # label_row.initialise_labels(include_signed_url=True) # # Assuming label_row.data_link provides access to video frames or a way to extract them # # This part would involve video processing logic to extract frames. # # For simplicity, let's assume we get a single frame's content: # # video_frame_content = get_video_frame(label_row.data_link, frame_number=0) # Hypothetical function # # media_content_base64 = base64.b64encode(video_frame_content).decode("utf-8") # # Mocking frame content for demonstration # mock_frame_content = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" # A 1x1 black pixel # # Get predictions from the mock model # # predictions = get_mock_model_predictions(mock_frame_content) # predictions = [ # {"box": [0.1, 0.1, 0.2, 0.2], "confidence": 0.8, "class": "mock_class_1"}, # {"box": [0.5, 0.5, 0.1, 0.1], "confidence": 0.7, "class": "mock_class_2"} # ] # Mock predictions # # Apply predictions to the label row # for pred in predictions: # # This part requires mapping the mock class names to actual ontology objects # # and creating bounding box annotations. # # Example: # # ontology_object = project.ontology_structure.get_child_by_title(pred["class"]) # # if ontology_object: # # label_row.add_bounding_box(ontology_object, pred["box"], score=pred["confidence"]) # pass # Placeholder for actual annotation logic # label_row.save() # # Proceed the task to the next stage (e.g., "Annotate 1") # # task.proceed(pathway_name="Annotate 1") ``` -------------------------------- ### Upload PDF Files to Encord (JSON) Source: https://docs.encord.com/sdk-documentation/getting-started-sdk/sdk-register-data-gcp Example JSON structures for uploading PDF files to Encord. Includes template and data examples with options for object URLs, titles, and metadata like file size and number of pages. ```json { "pdfs": [ { "objectUrl": "" }, { "objectUrl": "", "title": "my-document-02.pdf" }, { "objectUrl": "", "title": "my-document-03.pdf", "pdfMetadata": { "fileSize": 300, "numPages": 5 } } ], "skip_duplicate_urls": true } ``` ```json { "pdfs": [ { "objectUrl": "https://storage.cloud.google.com/encord-image-bucket/my-document-01.pdf" }, { "objectUrl": "https://storage.cloud.google.com/encord-image-bucket/my-document-02.pdf", "title": "my-document-02.pdf" }, { "objectUrl": "https://storage.cloud.google.com/encord-image-bucket/my-document-03.pdf", "title": "my-document-03.pdf", "pdfMetadata": { "fileSize": 300, "numPages": 5 } } ], "skip_duplicate_urls": true } ``` -------------------------------- ### Example JSON for Uploading Audio Files (JSON) Source: https://docs.encord.com/sdk-documentation/datasets-sdk/sdk-client-metadata This JSON structure is an example for uploading audio files to Encord. It outlines the necessary fields and format for submitting audio data, though the specific details of the audio file content are not shown. ```json { "files": [ { "name": "audio_file_1.wav", "type": "audio/wav" }, { "name": "audio_file_2.mp3", "type": "audio/mpeg" } ] } ``` -------------------------------- ### Initialize EncordUserClient Source: https://docs.encord.com/sdk-documentation/sdk-references/user_client The EncordUserClient is the main entry point for the SDK. It should be instantiated using factory methods like create_with_ssh_private_key or create_with_service_account rather than direct constructor calls. ```python class EncordUserClient() ``` -------------------------------- ### Create and Save Bounding Box Labels for Images (Python) Source: https://docs.encord.com/sdk-documentation/sdk-labels/sdk-import-labels-to-consensus-branches This example demonstrates authenticating with Encord, retrieving a project and specific label rows, and then applying multiple bounding box labels to images. It includes filtering label rows by data unit titles and saving the updated labels within a project bundle. Dependencies include `encord` and `pathlib`. ```python # Import dependencies from pathlib import Path from encord import EncordUserClient, Project from encord.objects import Object, ObjectInstance from encord.objects.coordinates import BoundingBoxCoordinates # Configuration SSH_PATH = "/Users/chris-encord/sdk-ssh-private-key.txt" PROJECT_ID = "7d4ead9c-4087-4832-a301-eb2545e7d43b" CONSENSUS_BRANCH_NAME = "my-label-branch-II" ONTOLOGY_OBJECT_TITLE = "Cherry" DATA_UNIT_TITLES = ["cherry_001.png"] # List of specific image data units # Authenticate with Encord using access key user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=Path(SSH_PATH).read_text() ) # Get the project and list label rows for the label branch project = user_client.get_project(PROJECT_ID) all_consensus_branch_rows = project.list_label_rows_v2(branch_name=CONSENSUS_BRANCH_NAME) # Filter label rows based on the specified data unit titles consensus_branch_rows = [ row for row in all_consensus_branch_rows if row.data_title in DATA_UNIT_TITLES ] if not consensus_branch_rows: print("No matching data units found in the specified branch.") else: print("Data units found:", [row.data_title for row in consensus_branch_rows]) # Retrieve the specified ontology object by title box_ontology_object = project.ontology_structure.get_child_by_title( title=ONTOLOGY_OBJECT_TITLE, type_=Object ) with project.create_bundle() as bundle: # Initialize labels for each selected label row in the label branch for label_row in consensus_branch_rows: label_row.initialise_labels(bundle=bundle) # Add bounding box labels to each filtered label row for label_row in consensus_branch_rows: # Define bounding box coordinates for each label bounding_boxes = [ BoundingBoxCoordinates(height=0.1, width=0.1, top_left_x=0.2, top_left_y=0.2), BoundingBoxCoordinates(height=0.1, width=0.1, top_left_x=0.3, top_left_y=0.3), BoundingBoxCoordinates(height=0.1, width=0.1, top_left_x=0.4, top_left_y=0.4), ] # Instantiate and set labels for each bounding box for coordinates in bounding_boxes: box_object_instance = box_ontology_object.create_instance() box_object_instance.set_for_frames( coordinates=coordinates, frames=0, # Image frame manual_annotation=False, # Mark as label confidence=1.0, ) # Add each object instance to the label row label_row.add_object_instance(box_object_instance) with project.create_bundle() as bundle: for label_row in consensus_branch_rows: # Save the label row with the updated labels within the bundle label_row.save(bundle=bundle) ```