Roboflow Python SDK

1.3.1 · active · verified Thu Apr 09

The Roboflow Python package (version 1.3.1) is the official SDK for interacting with the Roboflow API, enabling programmatic access for tasks such as dataset management, image upload, model training, and inference. It is actively developed, with recent updates including a comprehensive rewrite of the command-line interface and enhanced capabilities for workspace-level asset management.

Warnings

Install

Imports

Quickstart

Initializes the Roboflow client and demonstrates connecting to a workspace. It's recommended to store your API key in an environment variable for security.

import os
from roboflow import Roboflow

# Ensure your Roboflow API key is set as an environment variable (recommended)
# os.environ["ROBOFLOW_API_KEY"] = "YOUR_API_KEY"

# Initialize Roboflow with your API key
# Replace 'YOUR_ROBOFLOW_API_KEY' with os.environ.get("ROBOFLOW_API_KEY", "") for production
rf = Roboflow(api_key=os.environ.get("ROBOFLOW_API_KEY", ""))

# Example: Get a workspace (replace 'your-workspace-id' with your actual workspace ID)
# You can often omit the ID if you only have one workspace associated with your API key
try:
    workspace = rf.workspace("your-workspace-id") 
    print(f"Connected to workspace: {workspace.name}")
except Exception as e:
    print(f"Could not connect to workspace: {e}. Check your API key and workspace ID.")

# Example: List projects in the workspace
# if 'workspace' in locals():
#     projects = workspace.projects()
#     print(f"Projects in workspace: {[p.name for p in projects]}")

view raw JSON →