Ocular AI Python SDK
Official Python SDK for interacting with the Ocular AI Platform.
Installation
pip install ocular
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 keyOCULAR_API_URL: The base URL for the Ocular APIOCULAR_TIMEOUT: Default request timeout in secondsOCULAR_MAX_RETRIES: Maximum number of retries for failed requestsOCULAR_BACKOFF_FACTOR: Backoff factor for retriesOCULAR_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
)
Metadata
Release files for ocular-ai 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ocular_ai-0.0.5.tar.gz | 15.2 kB | With provenance | Details for ocular_ai-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ocular_ai-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for ocular_ai-0.0.5-py3-none-any.whl |
Total release size: 35.9 kB
Release files / ocular_ai-0.0.5.tar.gz
| Download URL | ocular_ai-0.0.5.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc25b5a9ea6bf7badfad4d9b7f69bd62218df73d53300ead11ed1b1b08c65fc5
|
|
BLAKE2b-256 checksum How to use checksums |
64b896336531ca8ff0ea23d3f3e7473c83bdb14ac055837ee513814036a783ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 27, 2025.
Transparency logRelease files / ocular_ai-0.0.5-py3-none-any.whl
| Download URL | ocular_ai-0.0.5-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1745be177d7a321b2867eaaad1e2d1db1e9bab79a2e52980d53018d4db8a96a
|
|
BLAKE2b-256 checksum How to use checksums |
323031894fda7366d8fb876592c902ca951ba21f57b8df844a27d06ee19e5d8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 27, 2025.
Transparency logSecurity for ocular-ai 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for ocular_ai-0.0.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 27, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.