Python SDK Configuration
Learn how to configure and instantiate the Edgee Python SDK.
The Edgee Python SDK provides flexible ways to instantiate a client. All methods support automatic fallback to environment variables if configuration is not fully provided.
Overview
The Edgee class constructor accepts multiple input types:
Noneor no arguments - reads from environment variablesstr- API key string (backward compatible)EdgeeConfig- Configuration dataclass (type-safe)dict- Plain dictionary (flexible)
Method 1: Environment Variables (Recommended for Production)
The simplest and most secure approach is to use environment variables.
The SDK automatically reads EDGEE_API_KEY (required) and optionally EDGEE_BASE_URL from your environment variables.
from edgee import Edgee
# Reads from EDGEE_API_KEY and EDGEE_BASE_URL environment variables
edgee = Edgee()
Method 2: String API Key (Quick Start)
For quick testing or simple scripts, pass the API key directly as a string:
from edgee import Edgee
# API key only (uses default base URL: https://edgee.io)
edgee = Edgee("your-api-key")
Note: The base URL can also come from EDGEE_BASE_URL; otherwise it defaults to https://edgee.io. To set a base URL explicitly, use the configuration object below.
Method 3: Configuration Object (Type-Safe)
For better type safety, IDE support, and code clarity, use the EdgeeConfig dataclass:
from edgee import Edgee, EdgeeConfig
# Full configuration
edgee = Edgee(EdgeeConfig(
api_key="your-api-key",
base_url="https://edgee.io" # optional, defaults to https://edgee.io
))
Configuration Priority
The SDK uses the following priority order when resolving configuration:
- Constructor argument (if provided)
- Environment variable (if constructor argument is missing)
- Default value (for
base_urlonly, defaults tohttps://edgee.io)
Complete Examples
Additional configuration recipes
Example 1: Production Setup
# .env file
# EDGEE_API_KEY=prod-api-key
# EDGEE_BASE_URL=https://edgee.io
from dotenv import load_dotenv
from edgee import Edgee
load_dotenv()
edgee = Edgee() # Reads from environment
Example 2: Multi-Environment Setup
import os
from edgee import Edgee, EdgeeConfig
ENV = os.getenv("ENVIRONMENT", "development")
if ENV == "production":
edgee = Edgee() # Use environment variables
elif ENV == "staging":
edgee = Edgee(EdgeeConfig(
api_key=os.getenv("EDGEE_API_KEY")
))
else:
edgee = Edgee(EdgeeConfig(
api_key="dev-api-key",
base_url="https://eu.edgee.io"
))
Troubleshooting
"EDGEE_API_KEY is not set" Error
Problem: The SDK can't find your API key.
Solutions:
-
Set the environment variable:
export EDGEE_API_KEY="your-api-key" -
Pass it directly:
edgee = Edgee("your-api-key") -
Use EdgeeConfig:
edgee = Edgee(EdgeeConfig(api_key="your-api-key"))
Custom Base URL Not Working
Problem: Your custom base URL isn't being used.
Check:
- Verify the base URL in your configuration
- Check whether an explicit constructor URL takes precedence over
EDGEE_BASE_URL - Ensure you're using the correct configuration method
# This will use the base_url from EdgeeConfig
edgee = Edgee(EdgeeConfig(
api_key="key",
base_url="https://custom.example.com"
))
# This will use EDGEE_BASE_URL env var if set, otherwise default
edgee = Edgee("key")