OVHcloud API Client

1.2.0 · active · verified Thu Apr 16

The `ovh` Python library is the official module for interacting with OVHcloud APIs. It provides a thin wrapper that handles the complexities of credential creation and request signing. The library is currently at version 1.2.0 and is actively maintained, with new releases incorporating features and compatibility updates for modern Python versions. It is designed to simplify automation and management of OVHcloud services.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the OVHcloud API client using environment variables for credentials (recommended for security). It then makes a simple call to retrieve the current user's information. Replace placeholder keys with your actual OVHcloud Application Key, Application Secret, and Consumer Key. Remember to obtain your Consumer Key via the OVHcloud API console or the `request_consumerkey` helper after creating your application.

import os
import ovh

# Best practice: load credentials from environment variables or ovh.conf
# Alternatively, embed directly (less recommended for production)
endpoint = os.environ.get('OVH_ENDPOINT', 'ovh-eu') # e.g., 'ovh-eu', 'ovh-ca'
application_key = os.environ.get('OVH_APPLICATION_KEY', 'YOUR_APP_KEY')
application_secret = os.environ.get('OVH_APPLICATION_SECRET', 'YOUR_APP_SECRET')
consumer_key = os.environ.get('OVH_CONSUMER_KEY', 'YOUR_CONSUMER_KEY')

try:
    client = ovh.Client(
        endpoint=endpoint,
        application_key=application_key,
        application_secret=application_secret,
        consumer_key=consumer_key,
    )

    # Example: Get current user details
    me = client.get('/me')
    print(f"Hello, {me['firstname']} {me['lastname']}!")

    # Example: List your dedicated servers (requires appropriate rights)
    # servers = client.get('/dedicated/server')
    # print(f"Your dedicated servers: {servers}")

except ovh.exceptions.APIError as e:
    print(f"API Error: {e.code} - {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →