biothings.hub.api

class biothings.hub.api.EndpointDefinition[source]

Bases: dict

biothings.hub.api.create_handlers(shell, command_defs)[source]
biothings.hub.api.generate_api_routes(shell, commands)[source]
biothings.hub.api.generate_endpoint_for_callable(name, command, method, force_bodyargs)[source]
biothings.hub.api.generate_endpoint_for_composite_command(name, command, method)[source]
biothings.hub.api.generate_endpoint_for_display(name, command, method)[source]
biothings.hub.api.generate_handler(shell, name, command_defs)[source]
biothings.hub.api.start_api(app, port, check=True, wait=5, retry=5, settings=None)[source]

biothings.hub.api.managers

class biothings.hub.api.manager.APIManager(log_folder=None, *args, **kwargs)[source]

Bases: BaseManager

create_api(api_id, es_host, index, doc_type, port, description=None, **kwargs)[source]
delete_api(api_id)[source]
get_apis()[source]
register_status(api_id, status, **extra)[source]
restore_running_apis()[source]

If some APIs were running but the hub stopped, re-start APIs as hub restarts

setup()[source]
setup_log()[source]
start_api(api_id)[source]
stop_api(api_id)[source]
exception biothings.hub.api.manager.APIManagerException[source]

Bases: Exception

biothings.hub.api.handlers.base

class biothings.hub.api.handlers.base.BaseHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: DefaultHandler

initialize(managers, **kwargs)[source]
class biothings.hub.api.handlers.base.DefaultHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: RequestHandler

options(*args, **kwargs)[source]
set_default_headers()[source]

Override this to set HTTP headers at the beginning of the request.

For example, this is the place to set a custom Server header. Note that setting such headers in the normal flow of request processing may not do what you want, since headers may be reset during error handling.

write(result)[source]

Writes the given chunk to the output buffer.

To write the output to the network, use the flush() method below.

If the given chunk is a dictionary, we write it as JSON and set the Content-Type of the response to be application/json. (if you want to send JSON as a different Content-Type, call set_header after calling write()).

Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary. More details at http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and https://github.com/facebook/tornado/issues/1009

write_error(status_code, **kwargs)[source]

Override to implement custom error pages.

write_error may call write, render, set_header, etc to produce output as usual.

If this error was caused by an uncaught exception (including HTTPError), an exc_info triple will be available as kwargs["exc_info"]. Note that this exception may not be the “current” exception for purposes of methods like sys.exc_info() or traceback.format_exc.

class biothings.hub.api.handlers.base.GenericHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: DefaultHandler

delete(*args, **kwargs)[source]
get(*args, **kwargs)[source]
head(*args, **kwargs)[source]
initialize(shell, **kwargs)[source]
post(*args, **kwargs)[source]
put(*args, **kwargs)[source]
class biothings.hub.api.handlers.base.RootHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: DefaultHandler

async get()[source]
initialize(features, hub_name=None, **kwargs)[source]

biothings.hub.api.handlers.log

class biothings.hub.api.handlers.log.DefaultCORSHeaderMixin[source]

Bases: object

set_default_headers()[source]
class biothings.hub.api.handlers.log.HubLogDirHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: DefaultCORSHeaderMixin, RequestHandler

get(filename)[source]
initialize(path)[source]
class biothings.hub.api.handlers.log.HubLogFileHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: DefaultCORSHeaderMixin, StaticFileHandler

async get(path: str, include_body: bool = True) None[source]

If request path is a gz file, we will uncompress it first, then return get with the uncompress file path

options(*args, **kwargs)[source]
biothings.hub.api.handlers.log.get_log_content(file_path, **kwargs)[source]

biothings.hub.api.handlers.shell

class biothings.hub.api.handlers.shell.ShellHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: GenericHandler

initialize(shell, shellog, **kwargs)[source]
put()[source]

biothings.hub.api.handlers.upload

class biothings.hub.api.handlers.upload.UploadHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]

Bases: GenericHandler

data_received(chunk)[source]

Implement this method to handle streamed request data.

Requires the .stream_request_body decorator.

May be a coroutine for flow control.

initialize(upload_root, **kwargs)[source]
parse_head()[source]
post(src_name)[source]
prepare()[source]

Called at the beginning of a request before get/post/etc.

Override this method to perform common initialization regardless of the request method.

Asynchronous support: Use async def or decorate this method with .gen.coroutine to make it asynchronous. If this method returns an Awaitable execution will not proceed until the Awaitable is done.

New in version 3.1: Asynchronous support.

biothings.hub.api.handlers.ws

class biothings.hub.api.handlers.ws.HubDBListener[source]

Bases: ChangeListener

Get events from Hub DB and propagate them through the websocket instance

read(event)[source]
class biothings.hub.api.handlers.ws.LogListener(*args, **kwargs)[source]

Bases: ChangeListener

read(event)[source]
class biothings.hub.api.handlers.ws.ShellListener(*args, **kwargs)[source]

Bases: LogListener

class biothings.hub.api.handlers.ws.WebSocketConnection(session, listeners)[source]

Bases: SockJSConnection

Listen to Hub DB through a listener object, and publish events to any client connected

SockJSConnection.__init__() takes only a session as argument, and there’s no way to pass custom settings. In order to use that class, we need to use partial to partially init the instance with ‘listeners’ and let the rest use the ‘session’

parameter:

pconn = partial(WebSocketConnection,listeners=listeners) ws_router = sockjs.tornado.SockJSRouter(pconn,”/path”)

clients = {}
on_close()[source]

Default on_close handler.

on_message(message)[source]

Default on_message handler. Must be overridden in your application

on_open(info)[source]

Default on_open() handler.

Override when you need to do some initialization or request validation. If you return False, connection will be rejected.

You can also throw Tornado HTTPError to close connection.

request

ConnectionInfo object which contains caller IP address, query string parameters and cookies associated with this request (if any).

publish(message)[source]