Giter Site home page Giter Site logo

dreampylib's Introduction

DreamPyLib

Introduction

This is a Python library for interacting with DreamHost's API. It is based on the work of Laurens Simonis. Also included are some basic sample scripts which use the library.

Installation

To install, clone this repo and then run the setup.py installation script:

git clone https://github.com/EliRibble/dreampylib.git
cd dreampylib
python setup.py install

Alternatively, if you just want to install for the current user or don't have permissions to install in the site-packages or dist-packages directory, simply use

python setup.py install --user

instead.

Usage

The original author's manual still mostly applies, but some of the function names have changed to a more pythonic style (i.e. lower-case with underscore separators), and a user is no longer needed for API access. See the dreampylib/example.py file for a simple example. The basic usage is outlined here, as well.

Initialization

Either initialize the DreampyLib object with the API key to connect on construction:

import dreampylib

key = '6SHU5P2HLDAYECUM'
connection = dreampylib.DreampyLib(key)

or initialize without the key to postpone connection:

connection = dreampylib.DreampyLib()
connection.connect(key)

.

Inspecting the connection

To verify the connection was established and check the status of the previous API call:

if not connection.is_connected():
	print("Error connecting!")
	print(connection.status())
	return

Checking available commands

Each API key is given access to a specific set of API functions for that user. The following lists the available commands for the given API key:

print('Available commands:\n ')
commands = connection.available_commands()
command_names = [command[0] for command in commands]
print('\n'.join(command_names))

DreamHost API calls

The DreamHost API documentation gives an outline of the available API commands, expected parameters, and return values. Each category of API calls (e.g. dns) has an associated set of functions (e.g. list_records). These are of the form category-function (e.g. dns-list_records). To use these functions with DreampyLib, the connection is invoked using an attribute syntax: connection.category.function(**kwargs) (e.g. connection.dns.list_records()), where **kwargs are the named arguments for the API function call.

The return value of these API calls take the form of a tuple with three values:

success, msg, body = connection.category.function(**kwargs)

where success is a boolean, msg is a string containing either 'success' or the error message, and body is the actual content of the API function call return value. The default type of body is a list of dictionaries with keys being the names of the table columns. To view the results of a previous call as a list of lists instead, use connection.result_list(). Similarly, the functions connection.result_dict() and connection.result_keys() exist for obtaining the previous call's list of dictionaries and associated keys.

License

The work by Laurens Simonis originally carried this license:

Dreampylib is (c) 2009 by Laurens Simonis. Use it at your own risk, do with it whatever you like, but I am not responsible for whatever you do with it.

In the spirit of 'do with it whatever you like', it was put on github under an MIT license on May 7 2014.

dreampylib's People

Contributors

ender27182818 avatar mkrupcale avatar eliribble avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.