Skip to content

Latest commit

 

History

History
153 lines (101 loc) · 3.94 KB

MIGRATION.rst

File metadata and controls

153 lines (101 loc) · 3.94 KB

Migrate from legacy wrappers

This guide specifically targets developers comming from the legacy wrappers previously distributed on https://api.ovh.com/g934.first_step_with_api. It highligts the main evolutions between these 2 major version as well as some tips to help with the migration. If you have any further questions, feel free to drop a mail on [email protected] ([email protected] to subscribe).

Installation

Legacy wrappers were distributed as zip files for direct integration into final projects. This new version is fully integrated with Python's standard distribution channels.

Recommended way to add python-ovh to a project: add ovh to a requirements.txt file ate the root of the project.

# file: requirements.txt
ovh # add '==0.2.0' to force 0.2.0 version

To refresh the dependencies, just run:

pip install -r requirements.txt

Usage

Import and the client class

Legacy method:

from OvhApi import Api, OVH_API_EU, OVH_API_CA

New method:

from ovh import Client

Instanciate a new client

Legacy method:

client = Api(OVH_API_EU, 'app key', 'app secret', 'consumer key')

New method (compatibility):

client = Client('ovh-eu', 'app key', 'app secret', 'consumer key')

Similarly, OVH_API_CA has been replaced by 'ovh-ca'.

New method (compatibility):

To avoid embedding credentials in a project, this new version introduced a new configuration mechanism using either environment variables or configuration files.

In a Nutshell, you may put your credentials in a file like /etc/ovh.conf or ~/.ovh.conf like this one:

[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

And then simply create a client instance:

from ovh import Client
client = Client()

With no additional boilerplate!

For more informations on available configuration mechanism, please see https://github.com/ovh/python-ovh/blob/master/README.rst#configuration

Use the client

Legacy method:

# API helpers
data = client.get('/my/method?filter_1=value_1&filter_2=value_2')
data = client.post('/my/method', {'param_1': 'value_1', 'param_2': 'value_2'})
data = client.put('/my/method', {'param_1': 'value_1', 'param_2': 'value_2'})
data = client.delete('/my/method')

# Advanced, low level call
data = client.rawCall('GET', '/my/method?my_filter=my_value', content=None)

New method (compatibility):

# API helpers
data = client.get('/my/method?filter_1=value_1&filter_2=value_2')
data = client.post('/my/method', **{'param_1': 'value_1', 'param_2': 'value_2'})
data = client.put('/my/method', **{'param_1': 'value_1', 'param_2': 'value_2'})
data = client.delete('/my/method')

# Advanced, low level call
data = client.rawCall('GET', '/my/method?my_filter=my_value', data=None)

New method (recommended):

# API helpers
data = client.get('/my/method', filter_1='value_1', filter_2='value_2')
data = client.post('/my/method', param_1='value_1', param_2='value_2')
data = client.put('/my/method', param_1='value_1', param_2='value_2')
data = client.delete('/my/method')

# Advanced, low level call
data = client.rawCall('GET', '/my/method?my_filter=my_value', data=None)