bottle-gui documentation

Welcome in the bottle-gui documentation. This package is used to visualize services used in bottle web framework.

User documentation

From the user’s point of view, only thing you need to do is install the package and import one function:

pip install bottle-gui

And the code:

import bottle_gui

gui = bottle_gui.gui()

Thats it! This will add the bottle gui service to your bottle namespace.

The gui() takes one optional parameter, which specifies where the GUI service should run. By default, it will run at /.

Now, all you have to do is to run your server and go to address of the service, where you should see something like:

_images/screen.png

Note, that this is only for test, in real scenario, there would be more URL’s and their comments would be meaningful.

API documentation

bottle_gui package

bottle_gui.bottle_gui.TEMPLATE_PATH = 'static/templates/'

Path to the template directory.

bottle_gui.bottle_gui.read_template(template_name)[source]

Read content of the template file.

Parameters:template_name (str) – Name of the file.
Returns:Content of template_name from TEMPLATE_PATH directory.
Return type:str
bottle_gui.bottle_gui.INDEX_TEMPLATE = '<HTML>\n<head>\n <title>API index</title>\n <link rel="stylesheet" type="text/css" href="bottle_gui_static/style.css">\n</head>\n\n<body>\n<h1>API list</h1>\n\n<p>\nNote, that you can also query this URL using\n<acronym title=\'curl -i -H "Accept: application/json" localhost:8888\'>\n <code>Accept: application/json</code>\n</acronym> header and you will get nested dictionaries.\n</p>\n\n$tables\n\n</body>\n</HTML>'

static/templates/index.html

bottle_gui.bottle_gui.TABLE_TEMPLATE = '\n<table class="api_table">\n <tr>\n <th colspan="2" class="api_name">\n <h2><a href="$name">$name</a></h2>\n </th>\n </tr>\n <tr>\n <td colspan="2" class="api_description">$description</td>\n </tr>\n$rows\n</table>\n'

static/templates/table.html

bottle_gui.bottle_gui.ROW_TEMPLATE = ' <tr style="border-top: 1px solid black;">\n <td class="request_type">$http_type</td>\n <td class="method_name">\n <b><a href="$name">$name</a></b> $args\n </td>\n </tr>\n$method_description'

static/templates/row.html

bottle_gui.bottle_gui.DESCR_TEMPLATE = '\n <tr>\n <td class="blank_td">&rarr;</td>\n <td class="method_description">$method_description</pre></td>\n </tr>\n'

static/templates/descr.html

class bottle_gui.bottle_gui.RouteInfo(method, path, args, docstring, mdocstring, module_name)[source]

Bases: object

Container for informations about route.

method

fn reference

Reference to undecorated function.

path

str

Path to the function in bottle.

args

list

Args of the function.

docstring

str

Docstring for the function.

mdocstring

str

Docstring for the module where the function is.

module_name

str

Name of the module where the function is.

Attributes method (fn reference): see Attributes section for details. path (str): see Attributes section for details. args (list): see Attributes section for details. docstring (str): see Attributes section for details. mdocstring (str): see Attributes section for details. module_name (str): see Attributes section for details.

to_html()[source]

Convert informations about this route to HTML.

Note

DESCR_TEMPLATE and ROW_TEMPLATE is used.

Returns:HTML representation of the route.
Return type:str
to_dict()[source]

Return dictionary representation of the class. This method is used for JSON output.

Returns:Dictionary following keys: method, path, args, docstring, mdocstring, module_name.
Return type:dict
class bottle_gui.bottle_gui.RouteGroup(routes=[])[source]

Bases: object

This object is used to group RouteInfo objects.

Parameters:routes (list, default []) – List with RouteInfo objects.
get_path()[source]

Return path for this group.

Returns:Path.
Return type:str
get_docstring()[source]

Return ‘module’ docstring.

Returns:Module docstring, if defined, or blank string.
Return type:str
to_html()[source]

Convert group and all contained paths to HTML.

Note

TABLE_TEMPLATE is used.

Returns:HTML.
Return type:str
to_dict()[source]

Convert group to dict. This method is used for JSON output.

Returns:{path: [routes]}
Return type:dict
bottle_gui.bottle_gui.list_routes()[source]

Get list of RouteInfo objects from bottle introspection.

Returns:RouteInfo objects.
Return type:list
bottle_gui.bottle_gui.group_routes(ungrouped_routes)[source]

Group list of RouteInfo objects in ungrouped_routes by their RouteInfo.path properties.

Parameters:ungrouped_routes (list) – List of RouteInfo objects.
Returns:RouteGroup objects.
Return type:list
bottle_gui.bottle_gui.to_html(grouped_routes)[source]

Convert list of RouteGroup objects in group_routes to HTML.

Parameters:grouped_routes (list) – Llist of RouteGroup objects.
Returns:HTML page with routes.
Return type:str
bottle_gui.bottle_gui.to_json(grouped_routes)[source]

Convert list of RouteGroup objects in grouped_routes to JSON.

Parameters:grouped_routes (list) – Llist of RouteGroup objects.
Returns:JSON representation of grouped_routes.
Return type:str
bottle_gui.bottle_gui.gui(path='/')[source]

Run bootle-gui at given path.

Parameters:path (str, default “/”) – Bottle path on which the application will be available.
Returns:fn reference: Function, which provides the bottle-gui functionality, mapped to bottle path.
bottle_gui.bottle_gui.get_static(fn)[source]

Serve static files.

Testing

This project uses pytest for testing. You can run the tests from the root of the package using following command:

$ py.test

Which will output something like:

============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.23 -- pytest-2.6.0
collected 2 items

tests/test_gui.py ..

=========================== 2 passed in 1.31 seconds ==========================

Indices and tables