Supervisely Python SDK
Supervisely SDK for Python (pypi-slug: supervisely) provides Python wrappers to programmatically interact with the Supervisely computer vision platform. It simplifies tasks like data management, annotation, model training, and deployment. The library is actively maintained with very frequent releases, often daily or weekly, reflecting continuous development and bug fixes.
Warnings
- breaking Supervisely SDK versions are tied to the Supervisely instance version. Using an incompatible SDK version with your platform instance can lead to unexpected errors or missing functionality.
- gotcha Directly embedding API tokens in your source code (`sly.Api(token='...')`) is highly discouraged for security reasons, especially in production environments. While convenient for quick tests, it exposes sensitive credentials.
- deprecated The `supervisely_lib` package was an earlier module structure. Direct imports from `supervisely_lib` are now deprecated and may cause `ModuleNotFoundError` or lead to outdated behavior in recent SDK versions.
- gotcha When developing scripts or applications that modify data, accidentally altering active projects is a common mistake. This can lead to data loss or corruption in production datasets.
- gotcha Users deploying Supervisely agents or applications with GPU acceleration might encounter 'Failed to initialize NVML' or 'CUDA Out Of Memory' errors, often related to NVIDIA driver issues or Docker configurations.
Install
-
pip install supervisely
Imports
- Api
import supervisely as sly api = sly.Api.from_env()
- Project, Dataset, ImageInfo
from supervisely.project.project import Project from supervisely.project.dataset import Dataset from supervisely.api.image_api import ImageInfo
Quickstart
import os
import supervisely as sly
# It is highly recommended to set SERVER_ADDRESS and API_TOKEN as environment variables.
# For Community Edition, SERVER_ADDRESS is typically 'https://app.supervisely.com'
# For Enterprise Edition, use your custom instance address.
SERVER_ADDRESS = os.environ.get('SERVER_ADDRESS', 'https://app.supervisely.com')
API_TOKEN = os.environ.get('API_TOKEN', 'YOUR_SUPERVISELY_API_TOKEN_HERE') # Replace with your actual token or ensure env var is set
# Initialize API client from environment variables (recommended)
# For local development, you might use a .env file loaded with dotenv.
# See: https://developer.supervisely.com/getting-started/basics-of-authentication
try:
api = sly.Api(server_address=SERVER_ADDRESS, token=API_TOKEN)
# Test authentication by fetching teams
my_teams = api.team.get_list()
print(f"Successfully connected to Supervisely. You are a member of {len(my_teams)} team(s).")
if my_teams:
team = my_teams[0]
print(f"First team: {team.name} (ID: {team.id})")
workspaces = api.workspace.get_list(team.id)
if workspaces:
print(f"First workspace in team '{team.name}': {workspaces[0].name} (ID: {workspaces[0].id})")
else:
print(f"No workspaces found in team '{team.name}'.")
else:
print("No teams found for the provided API token. Please check your credentials and permissions.")
except Exception as e:
print(f"Error connecting to Supervisely API: {e}")
print("Please ensure SERVER_ADDRESS and API_TOKEN environment variables are correctly set.")