Docs/api design principles contributing (#2292)

* fix: resolve ruff line-length and mypy union syntax errors in keypoints module

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: add API design principles to CONTRIBUTING.md

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Piotr Skalski
2026-06-04 18:09:09 -06:00
committed by jirka
co-authored by Cursor
parent 1e8a48559b
commit 5a8e211a04
2 changed files with 45 additions and 2 deletions
+37
View File
@@ -12,6 +12,7 @@ Please read and adhere to our [Code of Conduct](https://supervision.roboflow.com
- [Contribution Guidelines](#contribution-guidelines)
- [Contributing Features](#contributing-features)
- [API Design Principles](#api-design-principles)
- [How to Contribute Changes](#how-to-contribute-changes)
- [Installation for Contributors](#installation-for-contributors)
- [Code Style and Quality](#code-style-and-quality)
@@ -41,6 +42,42 @@ For example, counting objects that cross a line anywhere on an image is a common
Before you contribute a new feature, consider submitting an Issue to discuss the feature so the community can weigh in and assist.
### API Design Principles
Supervision APIs should remain generic, composable, and predictable across model
families. Before adding a new integration, annotator option, or data conversion
method, check the existing `sv.Detections`, `sv.KeyPoints`, and annotator
patterns and follow these principles:
1. **Model integrations normalize raw external outputs into existing Supervision
containers.** Use `sv.Detections` for detection, segmentation, and other
instance-level predictions that include boxes, masks, class ids, confidence
scores, or extra per-instance fields. Use `sv.KeyPoints` for standalone
keypoint or pose predictions when keypoints exist independently of detection
boxes (e.g. pure pose estimation, landmark detection on pre-cropped images).
Use `Detections.keypoints` when keypoints are always co-incident with boxes
from the same model — the field stores an `(n, K, 2)` or `(n, K, 3)` array
where the optional third channel is per-point confidence in `[0, 1]`.
2. **Do not add a `from_<model>` method when the model already returns a
Supervision object.** `from_*` methods are for converting raw outputs from
external packages such as Ultralytics, Transformers, Inference, or MediaPipe.
If a model's `predict()` method already returns `sv.Detections`, keep that
result type and store additional structured payloads in `detections.data` or
`detections.metadata` using documented keys.
3. **Annotators render data; filtering and visibility are container state.**
Filtering by confidence, class id, tracker id, geometry, or custom data should
happen before annotation through the container slicing APIs, for example
`detections[detections.confidence > 0.7]` or `key_points[key_points.confidence > 0.5]`.
Per-point presentation state, such as a `KeyPoints.visible` mask, may
live on the container and be honored consistently by annotators.
4. **Annotator constructor arguments should describe visual presentation, not
model-quality gates.** Use constructor arguments for color, thickness,
opacity, text, position, style, and generic visualization parameters such as
sigma levels. Annotators may skip invalid geometry defensively, including
missing points, zero-area boxes, non-finite coordinates, or points marked
invisible on the container. They should not introduce confidence thresholds or
model-specific quality gates as rendering options.
## How to Contribute Changes
First, fork this repository to your own GitHub account. Click "fork" in the top corner of the `supervision` repository to get started: