Back to Cvat

Project recipes

site/content/en/docs/api_sdk/sdk/examples/projects.md

2.74.04.7 KB
Original Source

Four recipes cover the project lifecycle: project_create_and_list.py for the common CRUD path, project_backup.py and project_restore.py for portable copies, and project_export_dataset.py for dataset export (local + cloud). For a CSV overview of a project's jobs, see job_list.py --project-id --csv in the job recipes.

Create, list, filter, retrieve, rename

Creates a project with labels, then lists all projects, filters by name, retrieves by id, and renames it. Pass --cleanup to delete it at the end.

FlagRequiredMeaning
--hostyesServer URL, e.g. 'https://app.cvat.ai'
--tokenyesPersonal Access Token
--namenoProject name (default 'Example project')
--labelsnoLabel names, space-separated (default car person)
--cleanupnoDelete the created project at the end
bash
python project_create_and_list.py --host 'https://app.cvat.ai' --token '<your token>' \
    --name 'My project' --labels car person

The script

{{< include-code "assets/sdk-examples/project_create_and_list.py" >}}

Back up a project

Downloads a full project backup zip — tasks, jobs, annotations, and settings. Pair with project_restore.py to migrate or clone.

FlagRequiredMeaning
--hostyesServer URL
--tokenyesPersonal Access Token
--project-idyesId of the project to back up
--outputnoDestination file (default project_<id>_backup.zip)
bash
python project_backup.py --host 'https://app.cvat.ai' --token '<your token>' \
    --project-id 42

The script

{{< include-code "assets/sdk-examples/project_backup.py" >}}

Restore a project

Restores a project from a backup zip as a brand-new project. Pass --cleanup to delete the restored copy afterwards — useful when validating a backup file.

FlagRequiredMeaning
--hostyesServer URL
--tokenyesPersonal Access Token
--backupyesPath to a project backup zip
--cleanupnoDelete the restored copy (never touches the backup file)
bash
python project_restore.py --host 'https://app.cvat.ai' --token '<your token>' \
    --backup './project_42_backup.zip'

The script

{{< include-code "assets/sdk-examples/project_restore.py" >}}

Export a project's tasks individually (local + cloud)

Exports each task in a project as its own dataset, both to a local zip and straight to a registered cloud storage. By default every task is exported; pass --task-id to export only a specific subset. Validates the format name against the server's list before starting.

FlagRequiredMeaning
--hostyesServer URL
--tokenyesPersonal Access Token
--project-idyesId of the project to export
--cloud-storage-idyesRegistered cloud storage id (see cloud_storage_register.py)
--export-formatnoExporter name (default 'COCO 1.0')
--task-idnoTask ids to export, space-separated (default: every task in the project)
bash
python project_export_dataset.py --host 'https://app.cvat.ai' --token '<your token>' \
    --project-id 42 --cloud-storage-id 7 --export-format 'COCO 1.0'

The script

{{< include-code "assets/sdk-examples/project_export_dataset.py" >}}

Other SDK options:

SDK method / parameterWhat it adds
Project.download_backup(..., lightweight=True)Produce a smaller backup that omits media.
client.projects.create_from_dataset(...)Create a project directly from a dataset archive.
Project.import_dataset(format_name, path)Import annotations/data into an existing project - the import counterpart of export_dataset.
Project.get_annotations()Fetch the project's labeled data.

Notes:

  • list() returns the whole collection; pagination is handled for you.
  • A project backup captures tasks, jobs, users, and settings in a single zip - but no raw media beyond what export_dataset would include.
  • For a CSV overview of a project's jobs (no annotation geometry), use job_list.py --project-id <id> --csv. For an actual dataset export, use project_export_dataset.py.
  • include_images=False exports annotations only and is much smaller.
  • Full recipes: project_create_and_list.py, project_backup.py, project_restore.py, project_export_dataset.py.