Skip to content

Commit 94bb51e

Browse files
committed
docs: add API design principles to contribution guidelines
- Update AGENTS.md with detailed API design principles for consistency. - Expand CONTRIBUTING.md to include a new "API Design Principles" section.
1 parent 0c67942 commit 94bb51e

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Please read and adhere to our [Code of Conduct](https://supervision.roboflow.com
1212

1313
- [Contribution Guidelines](#contribution-guidelines)
1414
- [Contributing Features](#contributing-features)
15+
- [API Design Principles](#api-design-principles)
1516
- [How to Contribute Changes](#how-to-contribute-changes)
1617
- [Installation for Contributors](#installation-for-contributors)
1718
- [Code Style and Quality](#code-style-and-quality)
@@ -41,6 +42,38 @@ For example, counting objects that cross a line anywhere on an image is a common
4142

4243
Before you contribute a new feature, consider submitting an Issue to discuss the feature so the community can weigh in and assist.
4344

45+
### API Design Principles
46+
47+
Supervision APIs should remain generic, composable, and predictable across model
48+
families. Before adding a new integration, annotator option, or data conversion
49+
method, check the existing `sv.Detections`, `sv.KeyPoints`, and annotator
50+
patterns and follow these principles:
51+
52+
1. **Model integrations normalize raw external outputs into existing Supervision
53+
containers.** Use `sv.Detections` for detection, segmentation, and other
54+
instance-level predictions that include boxes, masks, class ids, confidence
55+
scores, or extra per-instance fields. Use `sv.KeyPoints` for standalone
56+
keypoint or pose predictions.
57+
2. **Do not add a `from_<model>` method when the model already returns a
58+
Supervision object.** `from_*` methods are for converting raw outputs from
59+
external packages such as Ultralytics, Transformers, Inference, or MediaPipe.
60+
If a model's `predict()` method already returns `sv.Detections`, keep that
61+
result type and store additional structured payloads in `detections.data` or
62+
`detections.metadata` using documented keys.
63+
3. **Annotators render data; filtering and visibility are container state.**
64+
Filtering by confidence, class id, tracker id, geometry, or custom data should
65+
happen before annotation through the container slicing APIs, for example
66+
`detections[detections.confidence > 0.7]` or an equivalent `sv.KeyPoints`
67+
filter. Per-point presentation state, such as a `KeyPoints.visible` mask, may
68+
live on the container and be honored consistently by annotators.
69+
4. **Annotator constructor arguments should describe visual presentation, not
70+
model-quality gates.** Use constructor arguments for color, thickness,
71+
opacity, text, position, style, and generic visualization parameters such as
72+
sigma levels. Annotators may skip invalid geometry defensively, including
73+
missing points, zero-area boxes, non-finite coordinates, or points marked
74+
invisible on the container. They should not introduce confidence thresholds or
75+
model-specific quality gates as rendering options.
76+
4477
## How to Contribute Changes
4578

4679
First, fork this repository to your own GitHub account. Click "fork" in the top corner of the `supervision` repository to get started:

AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ All work must follow the conventions of the `supervision` library
4646
- Follow existing naming patterns.
4747
- Maintain backward compatibility unless explicitly allowed.
4848
- Prefer functional utilities over complex classes unless justified.
49+
- Treat [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md#api-design-principles)
50+
as the canonical API design reference.
51+
- Keep model integrations aligned with existing containers: models that already
52+
return `sv.Detections` should continue to do so, with extra payloads stored
53+
in `data` or `metadata` under documented keys.
54+
- Reserve `from_*` methods for converting raw outputs from external packages
55+
into Supervision containers; do not add one-off adapters for outputs that are
56+
already `sv.Detections` or `sv.KeyPoints`.
57+
- Annotators render already-selected data. Do filtering by confidence, class id,
58+
tracker id, geometry, or custom fields before annotation with container
59+
slicing APIs, not annotator constructor arguments. Container-level visibility
60+
masks may be honored by annotators when documented consistently.
4961

5062
### Performance
5163

0 commit comments

Comments
 (0)