skillfed

pycocotools

Official APIs for the MS-COCO dataset

pycocotools v2.0.11 5.7M downloads/30d#2,053 on PyPI171
License unclear FreeBSD Active released

What it is and what it does

pycocotools is a maintained fork of the official MS-COCO dataset API, providing Python bindings to load and manipulate COCO-format annotations for object detection, instance segmentation, and keypoint detection tasks. It wraps the original C++ implementation and depends only on numpy. The package includes utilities to parse JSON annotation files, query images and annotations, compute evaluation metrics, and encode/decode run-length encoded segmentation masks.

The fork addresses long-standing issues in the original cocoapi: it installs cleanly via pip on Windows and modern Python versions, avoids unnecessary matplotlib imports, fixes file handle leaks, and resolves segmentation faults in RLE decoding. It maintains API compatibility with the original to ensure existing code continues to work without modification.

Use it for:

  • Load COCO-format annotations and retrieve image metadata and ground-truth bounding boxes for training object detection models.
  • Evaluate detection and segmentation model predictions against COCO ground truth using standard metrics (AP, AR).
  • Decode and manipulate instance segmentation masks stored in run-length encoded format within COCO JSON files.
  • Query and filter annotations by category, image ID, or area to prepare dataset splits for training and validation.
  • Integrate COCO dataset loading into computer vision pipelines that require standard annotation formats.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides Python APIs for loading, parsing, and working with the MS-COCO dataset, including annotation access and evaluation metrics for object detection and segmentation tasks.

Yes, if you work with COCO-format datasets. The package is actively maintained, widely used (top 5000 on PyPI), has no known vulnerabilities, and the fork fixes real issues in the original. Verify the FreeBSD license terms for your use case before committing to a production dependency.

Install

pycocotools on PyPI

pip

pip install pycocotools

uv

uv add pycocotools

poetry

poetry add pycocotools

Installing pycocotools

Before you install

Medium install friction due to compiled components, but pre-built wheels are available for common platforms (macOS, Linux x86_64/aarch64, Windows). Last release was 242 days ago; repository is active with recent commits.

License in practice

License treatment is unclear; the raw license is listed as FreeBSD but SPDX mapping is absent. Verify the actual license terms before use in proprietary or restricted-license projects.

Quickstart

pip install pycocotools

from pycocotools.coco import COCO
import numpy as np

coco = COCO('annotations.json')
img_ids = coco.getImgIds()
img = coco.loadImgs(img_ids[0])[0]

Requires Python >= 3.9. Compiled extension; installation may require build tools on platforms without pre-built wheels.

Verify before relying

  • Exact scope of bug fixes and improvements over the original cocoapi—which specific use cases benefit most.
  • Whether the FreeBSD license is correctly mapped and what restrictions it imposes in commercial contexts.
  • Performance characteristics when working with very large annotation files or datasets.

Package facts

License FreeBSD (unclear)
Python support supports the current Python release (>=3.9)
Install friction medium — platform-specific wheel
Runtime dependencies 1 — numpy
Maintenance actively maintained — 242 days since the last release
Last repo commit
First released
Downloads 5,686,892/month — #2,053 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pycocotools-2.0.11-cp310-cp310-macosx_10_9_universal2.whl; pycocotools-2.0.11-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pycocotools-2.0.11-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; pycocotools-2.0.11-cp310-cp310-musllinux_1_2_aarch64.whl; pycocotools-2.0.11-cp310-cp310-musllinux_1_2_x86_64.whl; pycocotools-2.0.11-cp310-cp310-win_amd64.whl; pycocotools-2.0.11-cp310-cp310-win_arm64.whl; pycocotools-2.0.11-cp311-cp311-macosx_10_9_universal2.whl; pycocotools-2.0.11-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pycocotools-2.0.11-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; pycocotools-2.0.11-cp311-cp311-musllinux_1_2_aarch64.whl; pycocotools-2.0.11-cp311-cp311-musllinux_1_2_x86_64.whl; pycocotools-2.0.11-cp311-cp311-win_amd64.whl; pycocotools-2.0.11-cp311-cp311-win_arm64.whl; pycocotools-2.0.11-cp312-abi3-macosx_10_13_universal2.whl; pycocotools-2.0.11-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pycocotools-2.0.11-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; pycocotools-2.0.11-cp312-abi3-musllinux_1_2_aarch64.whl; pycocotools-2.0.11-cp312-abi3-musllinux_1_2_x86_64.whl; pycocotools-2.0.11-cp312-abi3-win_amd64.whl

Tags

coco dataset apiobject detection annotationsimage segmentation datasetcoco evaluation metricsdataset loading pythonannotation parsingcomputer vision dataset tools
dataset-toolscomputer-visioncoco-format

More Artificial Intelligence packages