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:

Variable
Required
Description

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:

Option
Default
Description

timeout

30.0

Request timeout in seconds

retries

3

Number of retry attempts

backoff

exponential

Retry backoff strategy

headers

{}

Custom HTTP headers

Best Practices

  1. Use environment variables for credentials

  2. Enable debug mode during development

  3. Configure appropriate timeouts

  4. Handle client cleanup (Python/PHP)

  5. Set custom headers when needed

  6. Use typed inputs where available

  7. 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:

  1. Set appropriate timeouts

  2. Configure retry strategies

  3. Use secure credential storage

  4. Monitor API rate limits

  5. Handle cleanup properly

  6. Log errors appropriately

  7. Use separate API keys

Last updated