Skip to main content

Official Python SDK for the Ocular AI Foundry Platform

Project description

Ocular AI Python SDK

Official Python SDK for interacting with the Ocular AI Platform.

Installation

pip install ocular

Or install from source:

git clone https://github.com/ocular-ai/ocular-python.git
cd ocular-python
pip install -e .

Quick Start

from ocular import Ocular

# Initialize the SDK with your API key
ocular = Ocular(api_key="your_api_key_here")

# Access a workspace
workspace = ocular.workspace("your_workspace_id")

# Get a project from the workspace
project = workspace.project("your_project_id")

# Get a version from the project
version = project.version("your_version_id")

# Get an export from the version
export = version.export("your_export_id")

# Download the export dataset
dataset_path = export.download()
print(f"Downloaded export to: {dataset_path}")

Configuration

The SDK can be configured using the following parameters:

ocular = Ocular(
    api_key="your_api_key",  # Required unless OCULAR_API_KEY env var is set
    api_url="https://api.ocular.ai/v1",  # Optional custom API URL
    timeout=30,  # Request timeout in seconds
    max_retries=3,  # Maximum number of retries for failed requests
    backoff_factor=0.5,  # Backoff factor for retries
    debug=False,  # Enable debug logging
)

You can also configure the SDK using environment variables:

  • OCULAR_API_KEY: Your Ocular API key
  • OCULAR_API_URL: The base URL for the Ocular API
  • OCULAR_TIMEOUT: Default request timeout in seconds
  • OCULAR_MAX_RETRIES: Maximum number of retries for failed requests
  • OCULAR_BACKOFF_FACTOR: Backoff factor for retries
  • OCULAR_DEBUG: Enable debug mode (set to "true", "1", or "yes")
  • OCULAR_LOG_LEVEL: Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)

Error Handling

The SDK uses a structured error hierarchy for different types of errors:

from ocular.utils.errors import (
    OcularError,  # Base exception for all errors
    AuthenticationError,  # Authentication issues
    ValidationError,  # Invalid parameters
    ResourceNotFoundError,  # Resource not found
    RateLimitError,  # API rate limits exceeded
    ServerError,  # Server-side errors
    NetworkError,  # Network connectivity issues
    TimeoutError,  # Request timed out
)

try:
    workspace = ocular.workspace("invalid_id")
except ResourceNotFoundError as e:
    print(f"Workspace not found: {e}")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except OcularError as e:
    print(f"An error occurred: {e}")

Logging

The SDK uses Python's standard logging library. You can configure logging using:

from ocular.utils.logging import setup_logging

# Setup logging with custom settings
logger = setup_logging(
    level="DEBUG",
    log_file="ocular.log",  # Optional file to log to
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ocular_ai-0.0.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ocular_ai-0.0.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file ocular_ai-0.0.1.tar.gz.

File metadata

  • Download URL: ocular_ai-0.0.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ocular_ai-0.0.1.tar.gz
Algorithm Hash digest
SHA256 638280c27514ea388ea72c87a81a57c8e2ceb7d88958fc72b6a2ba86e477c94a
MD5 7d59d7d33dcf697ba01034a0cc034274
BLAKE2b-256 d182a8774eb8511c461aaaae89990adf7edc0ebfe1b413089c3b5cce0f77cd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocular_ai-0.0.1.tar.gz:

Publisher: publish.yml on OcularEngineering/ocular-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ocular_ai-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ocular_ai-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ocular_ai-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dca129072a485dd099f78d9ed5c4e5a18d2b2a2390667abebabd0e6b51c058c8
MD5 f3c16a39f87efb23ba07d92a27bf364d
BLAKE2b-256 f0bdf6d44d9d6efd568db8dd85aa1a514ddfd698be530412dae7a3b45f958f96

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocular_ai-0.0.1-py3-none-any.whl:

Publisher: publish.yml on OcularEngineering/ocular-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page