SDK Initialization
This guide covers how to properly initialize and configure the globalMOO SDKs.
Client Initialization
Each SDK provides a Client class for API interaction:
from globalmoo.client import Client
from globalmoo.credentials import Credentials
# Method 1: Environment Variables
client = Client() # Uses GMOO_API_KEY and GMOO_API_URI
# Method 2: Direct Credentials
credentials = Credentials(
api_key="your-api-key",
base_uri="https://app.globalmoo.com/api/"
)
client = Client(credentials=credentials)
# Method 3: Custom HTTP Client
import httpx
http_client = httpx.Client(
timeout=30.0,
headers={"Custom-Header": "value"}
)
client = Client(credentials=credentials, http_client=http_client)
Environment Variables
The SDKs support these environment variables:
GMOO_API_KEY
Yes
Your API key for authentication
GMOO_API_URI
No
API base URI (defaults to https://app.globalmoo.com/api/)
Debug Mode
Enable debug mode for detailed logging:
import logging
logging.basicConfig(level=logging.DEBUG)
client = Client(debug=True)
HTTP Client Configuration
The SDKs use different HTTP clients:
Python: httpx
PHP: Symfony HttpClient
Node.js: node-fetch
Custom configuration options:
timeout
30.0
Request timeout in seconds
retries
3
Number of retry attempts
backoff
exponential
Retry backoff strategy
headers
{}
Custom HTTP headers
Best Practices
Use environment variables for credentials
Enable debug mode during development
Configure appropriate timeouts
Handle client cleanup (Python/PHP)
Set custom headers when needed
Use typed inputs where available
Configure logging appropriately
Client Lifecycle
# Python example
with Client() as client:
# Client automatically closes
result = client.create_model(...)
# Manual cleanup
client = Client()
try:
result = client.create_model(...)
finally:
client.http_client.close()
Production Configuration
For production environments:
Set appropriate timeouts
Configure retry strategies
Use secure credential storage
Monitor API rate limits
Handle cleanup properly
Log errors appropriately
Use separate API keys
Last updated