PYTHON-OVH(1)

πŸ“¦
version 1.1.2 Β· 2 versions
, in fedora 43

🌸 PYTHON-OVH(1) β€” Python-OVH 🌸

okay bestie, welcome to the PYTHON-OVH(1) manual page, section one of the Python-OVH docs πŸ’– grab a strawberry drink, we're doing this. This is part 1, there's more coming, so don't go anywhere πŸ‘‘


✨ NAME ✨

python-ovh β€” Python-OVH Documentation

It's a thin wrapper around OVH's APIs. Like, it handles ALL the hard work for you, no cap: credential creation, requests signing, the whole entire vibe. You just vibe and call methods 🫢

import ovh

# Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
# to get your credentials
client = ovh.Client(
    endpoint='ovh-eu',
    application_key='<application key>',
    application_secret='<application secret>',
    consumer_key='<consumer key>',
)

# Print nice welcome message
print("Welcome", client.get('/me')['firstname'])

The easiest way to get the latest stable release is to grab it from pypi using pip. iconic behaviour tbh.

pip install ovh

Alternatively β€” and this is the main character route β€” you may get the latest development version directly from Git:

pip install -e git+https://github.com/ovh/python-ovh.git#egg=ovh

🧚 CLIENT MODULE 🧚

Constructor

__init__

High level helpers

request_consumerkey

Helpers to generate a consumer key, fr fr. See new_consumer_key_request below for a full working example, or ConsumerKeyRequest for the detailed implementation πŸ”

The basic idea of ConsumerKeyRequest is that it generates appropriate authorization requests out of human readable function calls. In short: use it! πŸ’…

get/post/put/delete

These are shortcuts around Client.call(). This is the recommended way to use the wrapper, periodt.

So for example, requesting the list of all bills would look like:

bills = client.get('/me/bills')

And in a similar fashion, enabling network burst on a specific server would look like:

client.put('/dedicated/server/%s/burst' % server_name, status='active')
  • param str target β€” Rest Method as shown in API's console.
  • param boolean need_auth β€” When False, it bypasses the signature process. This is interesting when you're calling an authentication related method. Defaults to True.
  • param dict kwargs β€” (Client.post() and Client.put() only) all the extra keyword arguments are passed as a data dict to the call. It's a syntaxic sugar so you can call API entrypoints using a regular method syntax πŸ“

Low level API

call

time_delta


πŸŽ€ CONFIG MODULE πŸŽ€

Methods

__init__

get

Globals


🌈 CLIENT MODULE 🌈

(yes bestie, we're back β€” the docs said so, I don't make the rules πŸ’€)

Constructor

__init__

Helpers

Generate rules

Trigger request


πŸ’œ EXCEPTIONS MODULE πŸ’œ


πŸ‘‘ USE THE API ON BEHALF OF A USER πŸ‘‘

1. Create an application

To interact with the APIs, the SDK needs to identify itself using an application_key and an application_secret. To get them, you need to register your application. Depending on which API you plan to use, visit:

  • OVH Europe
  • OVH North-America

Once it's created, you will obtain an application key (AK) and an application secret (AS). slay.

2. Configure your application

The easiest and safest way to use your application's credentials is to create an ovh.conf configuration file in the application's working directory. Here's how it looks:

[default]
; general configuration: default endpoint
endpoint=ovh-eu

[ovh-eu]
; configuration specific to 'ovh-eu' endpoint
application_key=my_app_key
application_secret=my_application_secret
; uncomment following line when writing a script application
; with a single consumer key.
;consumer_key=my_consumer_key

Depending on the API you want to use, you may set the endpoint to:

  • ovh-eu for OVH Europe API
  • ovh-ca for OVH North-America API

See Configuration for more informations on available configuration mechanisms.

NOTE: when you're using a versioning system, make sure to add ovh.conf to ignored files. It contains confidential/security-sensitive information! 🚨 like, seriously, do NOT commit that.

3. Authorize your application to access a customer account

To allow your application to access a customer account using the API on your behalf, you need a consumer key (CK).

try:
    input = raw_input
except NameError:
    pass

import ovh

# create a client using configuration
client = ovh.Client()

# Request RO, /me API access
access_rules = [
    {'method': 'GET', 'path': '/me'},
]

# Request token
validation = client.request_consumerkey(access_rules)

print("Please visit %s to authenticate" % validation['validationUrl'])
input("and press Enter to continue...")

# Print nice welcome message
print("Welcome", client.get('/me')['firstname'])
print("Btw, your 'consumerKey' is '%s'" % validation['consumerKey'])

The returned consumerKey should then be kept, so you avoid re-authenticating your end-user on each and every use πŸ™ˆ

NOTE: to request full and unlimited access to the API, you may use wildcards: python access_rules = [ {'method': 'GET', 'path': '/*'}, {'method': 'POST', 'path': '/*'}, {'method': 'PUT', 'path': '/*'}, {'method': 'DELETE', 'path': '/*'} ]

πŸ’Œ INSTALL A NEW MAIL REDIRECTION πŸ’Œ

e-mail redirections may be freely configured on domains and DNS zones hosted by OVH to an arbitrary destination e-mail, using the API call POST /email/domain/{domain}/redirection.

For this call, the api specifies that the source address shall be given under the from keyword. Which is a whole problem, because that's ALSO a reserved Python keyword 😭 In this case, simply prefix it with a _, and the wrapper will automatically detect it as being a prefixed reserved keyword and will substitute it. Such aliasing is only supported with reserved keywords, iykyk.

import ovh

DOMAIN = "example.com"
SOURCE = "sales@example.com"
DESTINATION = "contact@example.com"

# create a client
client = ovh.Client()

# Create a new alias
client.post('/email/domain/%s/redirection' % DOMAIN,
        _from=SOURCE,
        to=DESTINATION
        localCopy=False
    )
print("Installed new mail redirection from %s to %s" % (SOURCE, DESTINATION))

🧾 GRAB BILL LIST 🧾

Let's say you want to integrate OVH bills into your own billing system β€” you could just script around the /me/bills endpoints, and even get the details of each bill line using /me/bill/{billId}/details/{billDetailId}.

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

import ovh

# create a client without a consumerKey
client = ovh.Client()

# Grab bill list
bills = client.get('/me/bill')
for bill in bills:
    details = client.get('/me/bill/%s' % bill)
    print("%12s (%s): %10s --> %s" % (
        bill,
        details['date'],
        details['priceWithTax']['text'],
        details['pdfUrl'],
    ))

πŸ”₯ ENABLE NETWORK BURST IN SBG1 πŸ”₯

'Network burst' is a free service, but it's opt-in. So what if you have, say, 10 servers in the SBG-1 datacenter? You certainly don't want to activate it manually for each server, bestie, that's not the vibe. You could take advantage of code like this:

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

import ovh

# create a client
client = ovh.Client()

# get list of all server names
servers = client.get('/dedicated/server/')

# find all servers in SBG-1 datacenter
for server in servers:
    details = client.get('/dedicated/server/%s' % server)
    if details['datacenter'] == 'sbg1':
        # enable burst on server
        client.put('/dedicated/server/%s/burst' % server, status='active')
        print("Enabled burst for %s server located in SBG-1" % server)

✨ LIST APPLICATION AUTHORIZED TO ACCESS YOUR ACCOUNT ✨

okay so bestie, the whole application key / consumer key thing? It's literally a way to finely track which apps have access to your data and revoke that access too. This example lists validated applications. You could lowkey adapt it to manage revocation as well. πŸ’…

This example assumes you already have a Configuration with a valid application_key, application_secret, and consumer_key. No cap.

import ovh
from tabulate import tabulate

# create a client
client = ovh.Client()

credentials = client.get('/me/api/credential', status='validated')

# pretty print credentials status
table = []
for credential_id in credentials:
    credential_method = '/me/api/credential/'+str(credential_id)
    credential = client.get(credential_method)
    application = client.get(credential_method+'/application')

    table.append([
        credential_id,
        '[%s] %s' % (application['status'], application['name']),
        application['description'],
        credential['creation'],
        credential['expiration'],
        credential['lastUse'],
    ])
print(tabulate(table, headers=['ID', 'App Name', 'Description',
                               'Token Creation', 'Token Expiration', 'Token Last Use']))

Before you run this, make sure you've installed the tabulate library. It's a pretty cool library for pretty-printing tabular data in a clean and easy way. ✨

>>> pip install tabulate

The straightforward way to use OVH's API keys is to just embed them directly in your application code. While that's very convenient, it's lowkey lacking in elegance and flexibility. πŸ™ˆ

Alternatively, you should use configuration files or environment variables so the same code can run seamlessly in multiple environmentsβ€”like production and development, for instance. Periodt. πŸ’…

This wrapper will first look for direct instantiation parameters, then the OVH_ENDPOINT, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET, and OVH_CONSUMER_KEY environment variables. If either of these parameters isn't provided, it'll look for a configuration file that looks like this:

[default]
; general configuration: default endpoint
endpoint=ovh-eu

[ovh-eu]
; configuration specific to 'ovh-eu' endpoint
application_key=my_app_key
application_secret=my_application_secret
consumer_key=my_consumer_key

The client will successively attempt to locate this configuration file in:

  1. Current working directory: ./ovh.conf
  2. Current user's home directory: ~/.ovh.conf
  3. System wide configuration: /etc/ovh.conf

This lookup mechanism makes it easy to overload credentials for a specific project or user. Slay. πŸ’…

You can call all the methods of the API with the necessary arguments. Easy.

If an API needs an argument that collides with a Python reserved keyword, you can prefix it with an underscore. For example, the from argument of POST /email/domain/{domain}/redirection may be replaced by _from. No cap.

With characters that are invalid in a Python argument nameβ€”like a dotβ€”you can do this:

import ovh

params = {}
params['date.from'] = '2014-01-01'
params['date.to'] = '2015-01-01'

# create a client
client = ovh.Client()

# pass parameters using **
client.post('/me/bills', **params)

πŸ”“ UN-AUTHENTICATED CALLS πŸ”“

If the user hasn't authenticated yet (i.e., there's no valid Consumer Key), you can force python-ovh to issue the call by passing _need_auth=True to the high-level get(), post(), put(), and delete() helpers, or need_auth=True to the low-level Client.call() and Client.raw_call() methods. πŸ’…

This is needed when calling POST /auth/credential and GET /auth/time, which are used internally for authentication and can optionally be done for most of the /order calls. Fr fr.


πŸ“¦ ACCESS THE RAW REQUESTS RESPONSE OBJECTS πŸ“¦

The high-level get(), post(), put(), and delete() helpers, as well as the lower-level call(), will return a parsed json response or raise an error.

In some rare scenarios or advanced setups, you may need to perform custom processing on the raw request response. It can be accessed via raw_call(). This is the lowest-level call in python-ovh. See the source for more information.

This wrapper uses standard Python tools, so you should feel right at home. Here's a quick outline of what it might look like. A good practice is to run this from a virtualenv. 🐍


🌱 GET THE SOURCES 🌱

git clone https://github.com/ovh/python-ovh.git
cd python-ovh
python setup.py develop

You've developed a new cool feature? Fixed an annoying bug? We'd be happy to hear from you! πŸ’–


πŸ§ͺ RUN THE TESTS πŸ§ͺ

Simply run nosetests. It'll automatically load its configuration from setup.cfg and output full coverage status. Since we all love quality, please note that we do not accept contributions with test coverage under 100%. 😀

pip install -e .[dev]
nosetests # 100% coverage is a hard minimum

πŸ“š BUILD THE DOCUMENTATION πŸ“š

Documentation is managed using the excellent Sphinx system. For example, to build HTML documentation:

cd python-ovh/docs
make html

πŸ‡ͺπŸ‡Ί OVH EUROPE πŸ‡ͺπŸ‡Ί

okay so bestie, here's where you go for the European stuff:


πŸ‡¨πŸ‡¦ OVH NORTH AMERICA πŸ‡¨πŸ‡¦

And for North America, here's the tea:


πŸ‘‘ AUTHOR πŸ‘‘

Jean-Tiare Le Bigot πŸ’…


2013-2014, OVH SAS


That's the whole vibe, bestie. This page is from version 0.3, dated Sep 19, 2025. Now go slay with your API calls! πŸ’–βœ¨

πŸ“¦ where this page comes from