Manual

This is a short overview of how to use the library.

Initialisation:

To start using the library, import it.

import dreampylib

To set up the a connection, do the following:

user = 'apitest@dreamhost.com'
key = '6SHU5P2HLDAYECUM'
connection = dreampylib.DreamPyLib(user, key)

Alternatively, the following is also possible:

user = 'apitest@dreamhost.com'
key = '6SHU5P2HLDAYECUM'
connection = dreampylib.DreamPyLib()
connection.Connect(user, key)

Both of these connecting-options can take an optional extra parameter, which is the URL to the API. You won’t need to specify this unless Dreamhost changes the API’s location.

Inspecting the connection:

To verify if the connection is working, the following is available:

if not connection.IsConnected():
    print "Not connected"
    return

Since some API keys don’t have access to all functions, it can be usefull to check which functions are available to this particulair user:

print 'Available commands:n ',
listOfCommands = connection.AvailableCommands()
print 'n '.join(listOfCommands)

Using the API

Dreamhost’s API calls, as can be found on their wiki, have the following form:

Category-Function

For instance:

api-list_accessible_cmds

Here, api is the category, and list_accessible_cmds is the function.

To call any of those functions using DreamPyLib, use the following syntax:

connection.category.function([parameters, if any])

For example:

commands = connection.api.list_accessible_cmds()

By default, calls to the API return lists of dictionaries.

If a function from the API takes parameters, like for instance dreamhost_ps.list_size_history; that takes a Private Server as a parameter. That works just as is to beexpected in python:

sizeHistory = connection.dreamhost_ps.list_size_history(ps = 'ps7093')

This works the same for all parameters.

For a complete & up to date list of all the possible functions which are usable, please refer to http://wiki.dreamhost.com/api

Again, due to the unique architecture of this library, it does NOT needs to be updated when Dreamhosts adds or alters the API; new or altered functions are immediately usable in the form described above.

Working with the results

As stated previously, by default the results are returned as a list of dictionaries. This allows for easy iterating over all the results, and accessing all members of a result by name. Sometimes, it’s more usefull to get lists of lists. To get this, set the following variable:

dreampylib.defaultReturnType = 'list'

By default, the setting is:

dreampylib.defaultReturnType = 'dict'

Calls to the API executed after setting this will return values with this new setting.

To get the results for a previous call in either of the two formats, the following calls are available:

connection.ResultList()
connection.ResultDict()

These return a list of lists and a list of dicts, respectively, for the last issued call to the API.

To see the keys for a result, in their original order, issue:

connection.ResultKeys()

This returns a list of all the keys for the last issued call to the API. These are exactly the same keys as can be found in the dictionaries.

Other

To get the status of the last API call, the following call is available:

status = connection.Status()