Official Python package for working with the Roboflow computer vision platform API
—
Authentication and initialization functionality for accessing the Roboflow platform. This includes API key validation, workspace configuration, and CLI-based login flows.
The main entry point for the Roboflow SDK that handles authentication and provides access to workspaces and projects.
class Roboflow:
def __init__(self, api_key=None, model_format="undefined", notebook="undefined"):
"""
Initialize Roboflow client with API credentials.
Parameters:
- api_key: str, optional - Your Roboflow API key. If not provided, loads from environment or config
- model_format: str - Model format preference for downloads (default: "undefined")
- notebook: str - Notebook environment identifier (default: "undefined")
"""
def workspace(self, the_workspace=None):
"""
Access a workspace.
Parameters:
- the_workspace: str, optional - Workspace name/ID. Uses default if not specified
Returns:
Workspace object for the specified workspace
"""
def project(self, project_name, the_workspace=None):
"""
Access a project directly without going through workspace.
Parameters:
- project_name: str - Name of the project or "workspace/project" format
- the_workspace: str, optional - Workspace name if not in project_name
Returns:
Project object for the specified project
"""Functions for authenticating via command line interface and configuring persistent access.
def login(workspace=None, force=False):
"""
Authenticate via CLI with interactive token entry.
Parameters:
- workspace: str, optional - Specific workspace to authenticate for
- force: bool - Force re-authentication even if already logged in
Returns:
None - Saves authentication to config file
"""Convenience function for initializing workspace access.
def initialize_roboflow(the_workspace=None):
"""
High-level function to initialize Roboflow workspace.
Parameters:
- the_workspace: str, optional - Workspace URL/name to initialize
Returns:
Workspace object for the initialized workspace
"""Internal function for validating API keys with the Roboflow server.
def check_key(api_key, model, notebook, num_retries=0):
"""
Validates API key with Roboflow server.
Parameters:
- api_key: str - The API key to validate
- model: str - Model format context
- notebook: str - Notebook environment context
- num_retries: int - Number of retry attempts on failure
Returns:
dict or str - Validation response or "onboarding" for demo keys
Raises:
RuntimeError - If API key is invalid or server validation fails
"""import roboflow
# Authenticate with API key
rf = roboflow.Roboflow(api_key="your_api_key_here")
# Or use environment variable/config file
rf = roboflow.Roboflow() # Loads from ROBOFLOW_API_KEY env var or configimport roboflow
# Interactive CLI login
roboflow.login()
# Force re-authentication
roboflow.login(force=True)
# Login for specific workspace
roboflow.login(workspace="my-workspace")# Access default workspace
workspace = rf.workspace()
# Access specific workspace
workspace = rf.workspace("my-workspace-name")
# Direct project access
project = rf.project("my-project")
# Project with specific workspace
project = rf.project("my-project", "my-workspace")The SDK supports multiple authentication methods:
Roboflow() constructorROBOFLOW_API_KEY environment variableroboflow.login() to save authentication tokenConfig files are stored at:
~/.config/roboflow/config.json%USERPROFILE%/roboflow/config.jsonAuthentication failures raise RuntimeError with descriptive messages. Common scenarios:
try:
rf = roboflow.Roboflow(api_key="invalid_key")
workspace = rf.workspace()
except RuntimeError as e:
print(f"Authentication failed: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-roboflow