Table Of Contents

Previous topic

Reference Documentation: Classes and Methods

Next topic

odesk.routers package

This Page

odesk package

Module contents

Main package of the python bindings for oDesk API.

For convenience some most commonly used functionalities are imported here, so you can use:

from odesk import Client
from odesk import raise_http_error
odesk.get_version()
class odesk.Client(public_key, secret_key, oauth_access_token=None, oauth_access_token_secret=None, fmt='json', finreport=True, hr=True, mc=True, offers=True, provider=True, task=True, team=True, timereport=True, job=True)

Bases: object

Main API client with oAuth v1 authorization.

Parameters:
public_key:Public API key
secret_key:API key secret
oauth_access_token:
 oAuth access token public key
oauth_access_token_secret:
 oAuth access token secret key
fmt:(optional, default json) API response format. Currently only 'json' is supported
finreport:(optional, default True) Whether to attach odesk.routers.finreport router
hr:(optional, default True) Whether to attach odesk.routers.hr router
mc:(optional, default True) Whether to attach odesk.routers.mc router
offers:(optional, default True) Whether to attach odesk.routers.offers router
provider:(optional, default True) Whether to attach odesk.routers.provider router
task:(optional, default True) Whether to attach odesk.routers.task router
team:(optional, default True) Whether to attach odesk.routers.team router
timereport:(optional, default True) Whether to attach odesk.routers.timereport router
job:(optional, default True) Whether to attach odesk.routers.job router
delete(url, data=None)
get(url, data=None)
post(url, data=None)
put(url, data=None)
read(url, data=None, method='GET', fmt='json')

Returns parsed Python object or raises an error.

Parameters:
url:

Target url

data:

Dictionary with parameters

method:

(optional, default GET) HTTP method, possible values:

  • GET
  • POST
  • PUT
  • DELETE
fmt:

(optional, default json) API response format. Currently only 'json' is supported

urlopen(url, data=None, method='GET', headers=None)

Perform oAuth v1 signed HTTP request.

Parameters:
url:

Target url

data:

Dictionary with parameters

method:

(optional, default GET) HTTP method, possible values:

  • GET
  • POST
  • PUT
  • DELETE
headers:

(optional, default {}) Dictionary with header values

odesk.raise_http_error(url, response)

Raise custom urllib2.HTTPError exception.

Parameters:
url:Url that caused an error
response:urllib3 response object

Submodules

odesk.client module

class odesk.client.Client(public_key, secret_key, oauth_access_token=None, oauth_access_token_secret=None, fmt='json', finreport=True, hr=True, mc=True, offers=True, provider=True, task=True, team=True, timereport=True, job=True)

Bases: object

Main API client with oAuth v1 authorization.

Parameters:
public_key:Public API key
secret_key:API key secret
oauth_access_token:
 oAuth access token public key
oauth_access_token_secret:
 oAuth access token secret key
fmt:(optional, default json) API response format. Currently only 'json' is supported
finreport:(optional, default True) Whether to attach odesk.routers.finreport router
hr:(optional, default True) Whether to attach odesk.routers.hr router
mc:(optional, default True) Whether to attach odesk.routers.mc router
offers:(optional, default True) Whether to attach odesk.routers.offers router
provider:(optional, default True) Whether to attach odesk.routers.provider router
task:(optional, default True) Whether to attach odesk.routers.task router
team:(optional, default True) Whether to attach odesk.routers.team router
timereport:(optional, default True) Whether to attach odesk.routers.timereport router
job:(optional, default True) Whether to attach odesk.routers.job router
delete(url, data=None)
get(url, data=None)
post(url, data=None)
put(url, data=None)
read(url, data=None, method='GET', fmt='json')

Returns parsed Python object or raises an error.

Parameters:
url:

Target url

data:

Dictionary with parameters

method:

(optional, default GET) HTTP method, possible values:

  • GET
  • POST
  • PUT
  • DELETE
fmt:

(optional, default json) API response format. Currently only 'json' is supported

urlopen(url, data=None, method='GET', headers=None)

Perform oAuth v1 signed HTTP request.

Parameters:
url:

Target url

data:

Dictionary with parameters

method:

(optional, default GET) HTTP method, possible values:

  • GET
  • POST
  • PUT
  • DELETE
headers:

(optional, default {}) Dictionary with header values

odesk.config module

Here we watch the PYTHON_ODESK_BASE_URL variable and if it is defined, use it as BASE_URL.

odesk.exceptions module

exception odesk.exceptions.APINotImplementedException(*args, **kwargs)

Bases: odesk.exceptions.BaseException

exception odesk.exceptions.ApiValueError(*args, **kwargs)

Bases: odesk.exceptions.BaseException

exception odesk.exceptions.AuthenticationError(*args, **kwargs)

Bases: odesk.exceptions.BaseException

exception odesk.exceptions.BaseException(*args, **kwargs)

Bases: exceptions.Exception

Base exception class.

Performs logging.

odesk_debug(*args, **kwargs)
exception odesk.exceptions.BaseHttpException(*args, **kwargs)

Bases: urllib2.HTTPError, odesk.exceptions.BaseException

exception odesk.exceptions.HTTP400BadRequestError(*args, **kwargs)

Bases: odesk.exceptions.BaseHttpException

exception odesk.exceptions.HTTP401UnauthorizedError(*args, **kwargs)

Bases: odesk.exceptions.BaseHttpException

exception odesk.exceptions.HTTP403ForbiddenError(*args, **kwargs)

Bases: odesk.exceptions.BaseHttpException

exception odesk.exceptions.HTTP404NotFoundError(*args, **kwargs)

Bases: odesk.exceptions.BaseHttpException

exception odesk.exceptions.IncorrectJsonResponseError(*args, **kwargs)

Bases: odesk.exceptions.BaseException

exception odesk.exceptions.InvalidConfiguredException(*args, **kwargs)

Bases: odesk.exceptions.BaseException

exception odesk.exceptions.NotAuthenticatedError(*args, **kwargs)

Bases: odesk.exceptions.BaseException

odesk.http module

odesk.http.raise_http_error(url, response)

Raise custom urllib2.HTTPError exception.

Parameters:
url:Url that caused an error
response:urllib3 response object

odesk.namespaces module

class odesk.namespaces.Namespace(client)

Bases: object

A special ‘proxy’ class to keep API methods organized.

Use this class for defining new routers.

api_url = None
base_url = 'https://www.odesk.com/api/'
delete(url, data=None)
full_url(url)

Gets relative URL of API method and returns a full URL

get(url, data=None)
post(url, data=None)
put(url, data=None)
version = 1
class odesk.namespaces.GdsNamespace(client)

Bases: odesk.namespaces.Namespace

Gds API only allows GET requests.

base_url = 'https://www.odesk.com/gds/'
delete(url, data=None)
post(url, data=None)
put(url, data=None)

odesk.oauth module

class odesk.oauth.OAuth(client)

Bases: odesk.namespaces.Namespace

Authorization router.

Has methods for retrieving access tokens and get_info() method for checking you’re authorized successfully and ready to work with API.

access_token_url = 'https://www.odesk.com/api/auth/v1/oauth/token/access'
api_url = 'auth/'
authorize_url = 'https://www.odesk.com/services/api/auth'
get_access_token(verifier)

Returns access token and access token secret.

get_authorize_url(callback_url=None)

Returns authentication URL to be used in a browser.

get_info()

Get a detailed info about current authnticated user and some data from his profile.

get_oauth_consumer()

Returns OAuth consumer object.

get_oauth_params(url, key, secret, data=None, method='GET', to_header=False, to_dict=False)

Converts a mapping object to signed url query.

Parameters:
url:Target url
key:Public API key
secret:Public API key secret
data:Dictionary with data parameters
method:Mehtod to be called, default is GET
to_header:If True, data will be encoded as auth headers
get_request_token()

Returns request token and request token secret.

request_token_url = 'https://www.odesk.com/api/auth/v1/oauth/token/request'
version = 1

odesk.utils module

class odesk.utils.Q(arg1, operator=None, arg2=None)

Bases: object

Simple GDS query constructor.

Used to costruct odesk.utils.Query.

arg_to_string(arg)
class odesk.utils.Query(select, where=None, order_by=None)

Bases: object

Simple GDS query.

Example::

client.timereport.get_provider_report('user1',
    odesk.utils.Query(select=odesk.utils.Query.DEFAULT_TIMEREPORT_FIELDS,
                      where=(odesk.utils.Q('worked_on') <= date.today()) &
                      (odesk.utils.Q('worked_on') > '2010-05-01')))
DEFAULT_FINREPORT_FIELDS = ['reference', 'date', 'buyer_company__id', 'buyer_company_name', 'buyer_team__id', 'buyer_team_name', 'provider_company__id', 'provider_company_name', 'provider_team__id', 'provider_team_name', 'provider__id', 'provider_name', 'type', 'subtype', 'amount']
DEFAULT_TIMEREPORT_FIELDS = ['worked_on', 'team_id', 'team_name', 'task', 'memo', 'hours']
class odesk.utils.Table(data)

Bases: object

A helper class to access cryptic GDS response as a list of dictionaries.

odesk.utils.assert_parameter(parameter_name, value, options_list)

Raise an exception if parameter’s value not in options list.

odesk.utils.decimal_default(obj)

JSON serialization of Decimal.

Usage:
json.dumps(data, default=decimal_default)

Converts decimal to string.