Configuration
Configure the Ocular SDK for your environment
SDK Configuration
After installing the Ocular SDK, you’ll need to configure it with your API credentials. This guide covers all available configuration options.
Basic Configuration
All you need to get started is your API key. Everything else has sensible defaults.
Direct Initialization
This is the simplest way to get started with the SDK for testing and development.
You can also configure the SDK directly in your code:
Avoid hardcoding API keys in production code. Use environment variables instead.
Configuration Parameters
Understanding these parameters will help you optimize the SDK for your specific use case.
The SDK accepts the following parameters during initialization:
Parameter | Type | Default | Description |
---|---|---|---|
api_key | string | None | Your Ocular API key (required) |
api_url | string | ”https://api.useocular.com” | Base URL for the Ocular API |
timeout | integer | 300 | Request timeout in seconds |
max_retries | integer | 3 | Maximum number of retry attempts |
backoff_factor | float | 0.5 | Exponential backoff factor for retries |
debug | boolean | False | Enable detailed logging |
Most users will only need to set the API key. The default values work well for standard use cases.
Complete Example
Copy this example to quickly get started with a fully configured SDK instance.
Environment Variables
Using environment variables is the recommended approach for production deployments.
All configuration can be set using environment variables:
Variable | Description | Default |
---|---|---|
OCULAR_API_KEY | Your API key | Required |
OCULAR_API_URL | API base URL | ”https://api.useocular.com” |
OCULAR_TIMEOUT | Request timeout | 300 |
OCULAR_MAX_RETRIES | Max retry attempts | 3 |
OCULAR_BACKOFF_FACTOR | Retry backoff factor | 0.5 |
OCULAR_DEBUG | Debug mode | false |
Using environment variables is recommended for production environments to keep sensitive information out of your code.
Using With Python dotenv
This approach combines the security of environment variables with the convenience of a configuration file.
For development, you can use a .env
file with the python-dotenv package:
Then in your code:
Never commit your .env file to version control. Add it to your .gitignore file.