Plato SDK
Plato SDK is a Python library that provides a convenient way to interact with the Plato API. It simplifies data access and operations with Plato's services, offering a client for models, insights, and other platform features. The current version is 1.8.9, and it appears to follow a regular release cadence with recent updates.
Common errors
-
ValueError: PLATO_API_KEY environment variable not set
cause The `PLATO_API_KEY` environment variable was not configured, and no `api_key` was provided during client initialization.fixSet the `PLATO_API_KEY` environment variable in your shell (e.g., `export PLATO_API_KEY='your_key'`) or pass `api_key="your_api_key_string"` directly to `Plato(api_key=...)`. -
ERROR: Package 'plato-sdk' requires a different Python version: 3.9.x is not in '>=3.10'
cause The current Python interpreter version is older than 3.10, which is a minimum requirement for `plato-sdk`.fixUpgrade your Python environment to 3.10 or newer. You can use tools like `pyenv` or create a new virtual environment with a compatible Python version. -
AttributeError: module 'pydantic' has no attribute 'BaseModel'
cause This typically occurs when Pydantic v1 is installed in the environment, but `plato-sdk` expects Pydantic v2 or newer. The `BaseModel` structure and import paths changed between major versions.fixCreate a clean virtual environment and install `plato-sdk` to ensure Pydantic v2 is installed without conflicts. If other libraries require Pydantic v1, you may need to isolate environments or adjust those dependencies.
Warnings
- gotcha API key missing or incorrectly configured. The SDK relies on `PLATO_API_KEY` environment variable or direct `api_key` parameter.
- gotcha API calls can fail due to network issues, rate limits, or Plato API server errors. Implement robust error handling.
- gotcha Conflicts with other libraries requiring different Pydantic versions (e.g., Pydantic v1 vs v2). `plato-sdk` requires Pydantic 2.x.
- breaking `plato-sdk` requires Python 3.10 or newer. Installing with older Python versions will fail.
Install
-
pip install plato-sdk
Imports
- Plato
from plato_sdk import Plato
Quickstart
import os
from plato_sdk import Plato
# Initialize the Plato client with your API key
# Ensure PLATO_API_KEY is set in your environment or pass it directly.
api_key = os.environ.get("PLATO_API_KEY", "")
if not api_key:
print("Warning: PLATO_API_KEY environment variable not set. API calls may fail.")
# In a real app, you might raise an error here.
# For this example, we'll continue with an empty key if not set.
plato = Plato(api_key=api_key)
# Example: Fetch a list of available models
try:
# This call requires a valid API key and network connectivity
models = plato.models.list()
print("Available models:")
for model in models:
print(f"- {model.name} (ID: {model.model_id})")
except Exception as e:
print(f"Error fetching models: {e}")
print("Please check your API key and network connection.")