class cloudsync.oauth.apiserver.ApiServer(addr: str, port: int, headers=None, log_level=<ApiServerLogLevel.ARGS: 2>, allow_reuse=False)

from apiserver import ApiServer, ApiError, api_route

Create your handlers by inheriting from ApiServer and tagging them with @api_route(“/path”).

Alternately you can use the ApiServer() directly, and call add_handler(“path”, function)

Raise errors by raising ApiError(code, message, description=None)

Return responses by simply returning a dict() or str() object

Parameter to handlers is a dict()

Query arguments are shoved into the dict via urllib.parse_qs

add_route(path, meth, content_type='application/json')

Add a new route handler.


Get my ip address


Get my port


Start listening and responding.


Closes the server and joins all threads


Stops the current server, if started

uri(path='/', hostname=None)

Make a URI pointing at myself

class cloudsync.oauth.apiserver.ApiError(code, msg=None, desc=None, json=None)

User can raise an ApiError in order to abort processing and return something other than ‘200’ to the web client.


code: status code msg: message to show desc: description of the error json: json to return, instead of any error descriptions

classmethod from_json(error_json)

Decorator for handling specific urls.


path: the route to handle

If this ends in a ‘/’, it will handle all routes starting with that path.