This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
python -m unittest# Format code with ruff
make style
# Check code quality (includes ruff and mypy)
make check_code_quality
# Individual commands
ruff format roboflow
ruff check roboflow --fix
mypy roboflow# Install documentation dependencies
python -m pip install mkdocs mkdocs-material mkdocstrings mkdocstrings[python]
# Serve documentation locally
mkdocs serve# Create virtual environment
python3 -m venv env
source env/bin/activate
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pip install pre-commit
pre-commit installThe Roboflow Python SDK follows a hierarchical object model that mirrors the Roboflow platform structure:
-
Roboflow (
roboflow/__init__.py) - Entry point and authentication- Handles API key management and workspace initialization
- Provides
login()for CLI authentication - Creates workspace connections
-
Workspace (
roboflow/core/workspace.py) - Manages Roboflow workspaces- Lists and accesses projects
- Handles dataset uploads and model deployments
- Manages workspace-level operations
-
Project (
roboflow/core/project.py) - Represents a computer vision project- Manages project metadata and versions
- Handles image/annotation uploads
- Supports different project types (object-detection, classification, etc.)
-
Version (
roboflow/core/version.py) - Dataset version management- Downloads datasets in various formats
- Deploys models
- Provides access to trained models for inference
-
Model Classes (
roboflow/models/) - Type-specific inference modelsObjectDetectionModel- Bounding box predictionsClassificationModel- Image classificationInstanceSegmentationModel- Pixel-level segmentationSemanticSegmentationModel- Class-based segmentationKeypointDetectionModel- Keypoint predictions
- rfapi (
roboflow/adapters/rfapi.py) - Low-level API communication - deploymentapi (
roboflow/adapters/deploymentapi.py) - Model deployment operations
The CLI is a modular package with auto-discovered handler modules. roboflow/roboflowpy.py is a backwards-compatibility shim that delegates to roboflow.cli.main.
Package structure:
__init__.py— Root parser with global flags (--json,--workspace,--api-key,--quiet), auto-discovery viapkgutil.iter_modules, custom_CleanHelpFormatter, and_reorder_argvfor flexible flag positioning_output.py—output(args, data, text)for JSON/text output,output_error(args, msg, hint, exit_code)for structured errors,suppress_sdk_output()to silence SDK noise,stub()for unimplemented commands_table.py—format_table(rows, columns)for columnar list output_resolver.py—resolve_resource(shorthand)for parsingproject,ws/project,ws/project/3handlers/— One file per command group (auto-discovered)._aliases.pyregisters backwards-compat top-level commands (loaded last)
Adding a new command:
- Create
roboflow/cli/handlers/mycommand.py - Export
register(subparsers)— it will be auto-discovered - Use lazy imports for heavy dependencies (inside handler functions, not at module top level)
- Use
output()for all output,output_error()for all errors - Wrap SDK calls in
with suppress_sdk_output():to prevent "loading..." noise - Add tests in
tests/cli/test_mycommand_handler.py
Agent experience requirements for all CLI commands:
- Support
--jsonfor structured output (stable schema) - No interactive prompts when all required flags are provided
- Structured error output:
{"error": {"message": "...", "hint": "..."}}on stderr - Exit codes: 0 = success, 1 = error, 2 = auth error, 3 = not found
- Actionable error messages: always tell the user what went wrong AND what to do
Documentation policy: CLI-COMMANDS.md in this repo is a quickstart only. The full command reference lives in roboflow-product-docs (published to docs.roboflow.com). When adding commands, update both.
- Hierarchical Access: Always access objects through their parent (Workspace → Project → Version → Model)
- API Key Flow: API key is passed down through the object hierarchy
- Format Flexibility: Supports multiple dataset formats (YOLO, COCO, Pascal VOC, etc.)
- Batch Operations: Upload and download operations support concurrent processing
- CLI Noun-Verb Pattern: Commands follow
roboflow <noun> <verb>(e.g.roboflow project list). Common operations have top-level aliases (login,upload,download) - CLI Auto-Discovery: Handler modules in
roboflow/cli/handlers/are loaded automatically — no registration list to maintain - Backwards Compatibility: Legacy command names and flag signatures are preserved as hidden aliases
- Python Version: 3.8+
- Main Dependencies: See
requirements.txt - Entry Point:
roboflow=roboflow.roboflowpy:main(shim delegates toroboflow.cli.main) - Code Style: Enforced by ruff with Google docstring convention
- Type Checking: mypy configured for Python 3.8
- API keys are stored in
~/.config/roboflow/config.json(Unix) or~/roboflow/config.json(Windows) - The SDK supports both hosted inference (Roboflow platform) and local inference (via Roboflow Inference)
- Pre-commit hooks automatically run formatting and linting checks
- Test files intentionally excluded from linting:
tests/manual/debugme.py