For the complete documentation index, see llms.txt. This page is also available as Markdown.

Upload an Annotation

If you already have existing annotations, along with your images, you can upload them to Roboflow.

Did you know? You can drag and drop (or select) the annotation files along with your images on the Upload page of the app without using the API.

Query Parameters

Parameter
Type
Required
Description

api_key

string

Yes

Your API key.

name

string

Yes

The annotation filename (ex: photo.xml).

overwrite

boolean

No

Whether to replace an existing annotation. Defaults to false. When false, the API returns 409 Conflict if the image already has an annotation.

You can attach annotation files when you upload images via the Python SDK. See more in the Python SDK reference

Example: Uploading a Local Annotation

import glob
from roboflow import Roboflow

# Initialize Roboflow client
rf = Roboflow(api_key="YOUR_PRIVATE_API_KEY")

# Directory path and file extension for images
dir_name = "PATH/TO/IMAGES"
file_extension_type = ".jpg"

# Annotation file path and format (e.g., .coco.json)
annotation_filename = "PATH/TO/_annotations.coco.json"

# Get the upload project from Roboflow workspace
project = rf.workspace().project("YOUR_PROJECT_NAME")

# Upload images
image_glob = glob.glob(dir_name + '/*' + file_extension_type)
for image_path in image_glob:
    print(project.single_upload(
        image_path=image_path,
        annotation_path=annotation_filename,
        # -- optional parameters: --
        # annotation_labelmap=labelmap_path,
        # split='train',
        # num_retry_uploads=0,
        # batch_name='batch_name',
        # tag_names=['tag1', 'tag2'],
        # is_prediction=False,
    ))

Last updated

Was this helpful?