globalMOO Documentation
  • globalMOO API Documentation
  • core
    • Authentication
    • Core Concepts
    • Getting Started with globalMOO
    • Error Handling
    • Event Handling
    • SDK Initialization
    • Debugging & Logging
  • schemas
    • Account Schema
    • Model Schema
    • Project Schema
    • Trial Schema
    • Objective Schema
    • Result Schema
    • Inverse Schema
  • quickstart
    • Your First Optimization with globalMOO
  • endpoints
    • accounts
      • Account Endpoints
      • Register Account
    • inverse
      • Inverse Optimization Endpoints
      • Initialize Inverse Optimization
      • Load Inverse Output
      • Suggest Inverse Step
    • models
      • Create Model
      • Model Endpoints
      • List Models
    • objectives
      • Objective Endpoints
      • Load Objectives
    • outputs
      • Output Endpoints
      • Load Output Cases
      • Load Developed Outputs
    • projects
      • Create Project
      • Project Endpoints
    • trials
      • Trial Endpoints
      • Read Trial
Powered by GitBook
On this page
  • Client Initialization
  • Environment Variables
  • Debug Mode
  • HTTP Client Configuration
  • Best Practices
  • Client Lifecycle
  • Production Configuration
  1. core

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)
use GlobalMoo\Client;
use GlobalMoo\Credentials;

// Method 1: Environment Variables
$client = new Client();

// Method 2: Direct Credentials
$credentials = new Credentials(
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/"
);
$client = new Client($credentials);

// Method 3: Custom HTTP Client
use Symfony\Component\HttpClient\HttpClient;
$httpClient = HttpClient::create([
    'timeout' => 30.0,
    'headers' => ['Custom-Header' => 'value']
]);
$client = new Client($credentials, $httpClient);
const { Client } = require('globalmoo');

// Method 1: Environment Variables
const client = new Client();

// Method 2: Direct Configuration
const client = new Client({
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/"
});

// Method 3: Custom Configuration
const client = new Client({
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/",
    timeout: 30000,
    headers: { "Custom-Header": "value" }
});

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)
// Set debug flag in constructor
$client = new Client(debug: true);

// Configure logging
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('globalmoo');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
const client = new Client({
    debug: true,
    logger: console
});

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

PreviousEvent HandlingNextDebugging & Logging

Last updated 3 months ago