module documentation

Bottle is a fast and simple micro-framework for small web applications. It offers request dispatching (Routes) with url parameter support, templates, a built-in HTTP Server and adapters for many third party WSGI/HTTP-server and template engines - all in a single file and with no dependencies other than the Python Standard Library. Homepage and documentation: http://bottlepy.org/ Copyright (c) 2016, Marcel Hellkamp. License: MIT (see LICENSE for details)

Class AppEngineServer Adapter for Google App Engine.
Class AppStack A stack-like list. Calling it returns the head of the stack.
Class AutoServer Untested.
Class BaseRequest A wrapper for WSGI environment dictionaries that adds a lot of convenient access methods and properties. Most of them are read-only.
Class BaseResponse Storage class for a response body as well as headers and cookies.
Class BaseTemplate Base class and minimal API for template adapters
Class BjoernServer Fast server written in C: https://github.com/jonashaag/bjoern
Class Bottle Each Bottle object represents a single, distinct web application and consists of routes, callbacks, plugins, resources and configuration. Instances are callable WSGI applications.
Class cached_property A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property.
Class CGIServer Undocumented
Class CheetahTemplate Undocumented
Class CherootServer Undocumented
Class CherryPyServer Undocumented
Class ConfigDict A dict-like configuration storage with additional support for namespaces, validators, meta-data, on_change listeners and more.
Class DictProperty Property that maps to a key in a local dict-like attribute.
Class DieselServer Untested.
Class EventletServer Untested
Class FapwsServer Extremely fast webserver using libev. See https://github.com/william-os4y/fapws3
Class FileCheckerThread Interrupt main-thread as soon as a changed module file is detected, the lockfile gets deleted or gets to old.
Class FileUpload No class docstring; 1/1 property, 0/4 instance variable, 0/2 class variable, 3/4 methods documented
Class FlupFCGIServer Undocumented
Class FormsDict This :class:`MultiDict` subclass is used to store request form data. Additionally to the normal dict-like item access methods (which return unmodified data as native strings), this container also supports attribute-like access to its values...
Class GeventServer Untested. Options:
Class GeventSocketIOServer Undocumented
Class GunicornServer Untested. See http://gunicorn.org/configure.html for options.
Class HeaderDict A case-insensitive version of :class:`MultiDict` that defaults to replace the old value instead of appending it.
Class HeaderProperty Undocumented
Class Jinja2Template Undocumented
Class JSONPlugin Undocumented
Class lazy_attribute A property that caches itself to the class object.
Class LocalRequest A thread-local subclass of :class:`BaseRequest` with a different set of attributes for each thread. There is usually only one global instance of this class (:data:`request`). If accessed during a request/response cycle, this instance always refers to the *current* request (even on a multithreaded server)...
Class LocalResponse A thread-local subclass of :class:`BaseResponse` with a different set of attributes for each thread. There is usually only one global instance of this class (:data:`response`). Its attributes are used to build the HTTP response at the end of the request/response cycle.
Class MakoTemplate Undocumented
Class MeinheldServer Undocumented
Class MultiDict This dict stores multiple values per key, but behaves exactly like a normal dict in that it returns only the newest value for any given key. There are special methods available to access the full list of values.
Class NCTextIOWrapper Undocumented
Class PasteServer Undocumented
Class ResourceManager This class manages a list of search paths and helps to find and open application-bound resources (files).
Class RocketServer Untested.
Class Route This class wraps a route callback along with route specific metadata and configuration and applies Plugins on demand. It is also responsible for turing an URL path rule into a regular expression usable by the Router.
Class Router A Router is an ordered collection of route->target pairs. It is used to efficiently match WSGI requests against a number of routes and return the first target that satisfies the request. The target may be anything, usually a string, ID or callable object...
Class ServerAdapter Undocumented
Class SimpleTemplate No class docstring; 0/2 property, 0/4 instance variable, 1/5 method documented
Class StplParser Parser for stpl templates.
Class TemplatePlugin This plugin applies the :func:`view` decorator to all routes with a `template` config parameter. If the parameter is a tuple, the second element must be a dict with additional options (e.g. `template_engine`) or default variables for the template...
Class TornadoServer The super hyped asynchronous server by facebook. Untested.
Class TwistedServer Untested.
Class WaitressServer Undocumented
Class WSGIFileWrapper Undocumented
Class WSGIHeaderDict This dict-like class wraps a WSGI environ dict and provides convenient access to HTTP_* fields. Keys and values are native strings (2.x bytes or 3.x unicode) and keys are case-insensitive. If the WSGI environment contains non-native string values, these are de- or encoded using a lossless 'latin1' character set.
Class WSGIRefServer Undocumented
Exception BottleException A base class for exceptions used by bottle.
Exception HTTPError Undocumented
Exception HTTPResponse Undocumented
Exception PluginError Undocumented
Exception RouteBuildError The route could not be built.
Exception RouteError This is a base class for all routing related exceptions
Exception RouteReset If raised by a plugin or request handler, the route is reset and all plugins are re-applied.
Exception RouterUnknownModeError Undocumented
Exception RouteSyntaxError The route parser found something not supported by this router.
Exception StplSyntaxError Undocumented
Exception TemplateError Undocumented
Function abort Aborts execution and causes a HTTP error.
Function auth_basic Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter.
Function cookie_decode Verify and decode an encoded string. Return an object or None.
Function cookie_encode Encode and sign a pickle-able object. Return a (byte) string
Function cookie_is_encoded Return True if the argument looks like a encoded cookie.
Function debug Change the debug level. There is only one debug level supported at the moment.
Function depr Undocumented
Function getargspec Undocumented
Function html_escape Escape HTML special characters ``&<>`` and quotes ``'"``.
Function html_quote Escape and quote a string to be used as an HTTP attribute.
Function http_date Undocumented
Function load Import a module or fetch an object from a module.
Function load_app Load a bottle application from a module and make sure that the import does not affect the current default application, but returns a separate application object. See :func:`load` for the target parameter...
Function local_property Undocumented
Function make_default_app_wrapper Return a callable that relays calls to the current default app.
Function makelist Undocumented
Function parse_auth Parse rfc2617 HTTP authentication header string (basic) and return (user,pass) tuple or None
Function parse_date Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch.
Function parse_range_header Yield (start, end) ranges parsed from a HTTP Range header. Skip unsatisfiable ranges. The end index is non-inclusive.
Function path_shift Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa.
Function redirect Aborts execution and causes a 303 or 302 redirect, depending on the HTTP protocol version.
Function run Start a server instance. This method blocks until the server terminates.
Function static_file Open a file in a safe way and return :exc:`HTTPResponse` with status code 200, 305, 403 or 404. The ``Content-Type``, ``Content-Encoding``, ``Content-Length`` and ``Last-Modified`` headers are set if possible...
Function template Get a rendered template as a string iterator. You can use a name, a filename or a template string as first parameter. Template rendering arguments can be passed as dictionaries or directly (as keyword arguments).
Function tob Undocumented
Function touni Undocumented
Function update_wrapper Undocumented
Function view Decorator: renders a template for a handler. The handler can control its behavior like that:
Function yieldroutes Return a generator for routes that match the signature (name, args) of the func parameter. This may yield more than one route if the function takes optional keyword arguments. The output is best described by example::...
Constant DEBUG Undocumented
Constant ERROR_PAGE_TEMPLATE Undocumented
Constant NORUN Undocumented
Constant TEMPLATE_PATH Undocumented
Constant TEMPLATES Undocumented
Variable __author__ Undocumented
Variable __license__ Undocumented
Variable __version__ Undocumented
Variable app Undocumented
Variable callable Undocumented
Variable cheetah_template Undocumented
Variable cheetah_view Undocumented
Variable default_app Undocumented
Variable delete Undocumented
Variable error Undocumented
Variable ext Undocumented
Variable get Undocumented
Variable hook Undocumented
Variable install Undocumented
Variable jinja2_template Undocumented
Variable jinja2_view Undocumented
Variable json_loads Undocumented
Variable local Undocumented
Variable mako_template Undocumented
Variable mako_view Undocumented
Variable mount Undocumented
Variable post Undocumented
Variable put Undocumented
Variable py25 Undocumented
Variable py31 Undocumented
Variable py3k Undocumented
Variable request Undocumented
Variable response Undocumented
Variable route Undocumented
Variable server_names Undocumented
Variable tonat Undocumented
Variable uninstall Undocumented
Variable url Undocumented
Variable urlunquote Undocumented
Class _closeiter This only exists to be able to attach a .close method to iterators that do not support attribute assignment (most of itertools).
Class _ImportRedirect No class docstring; 0/3 instance variable, 1/3 method documented
Function _e Undocumented
Function _file_iter_range Yield chunks from a range in a file. No chunk is bigger than maxread.
Function _hkey Undocumented
Function _hval Undocumented
Function _lscmp Compares two strings in a cryptographically safe way: Runtime is not affected by length of common prefix.
Function _parse_qsl Undocumented
Function _raise Undocumented
Function _re_flatten Turn all capturing groups in a regular expression pattern into non-capturing groups.
Constant _HTTP_STATUS_LINES Undocumented
Variable _stderr Undocumented
Variable _stdout Undocumented
def abort(code=500, text='Unknown Error.'): (source)

Aborts execution and causes a HTTP error.

def auth_basic(check, realm='private', text='Access denied'): (source)

Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter.

def cookie_decode(data, key): (source)

Verify and decode an encoded string. Return an object or None.

def cookie_encode(data, key): (source)

Encode and sign a pickle-able object. Return a (byte) string

def cookie_is_encoded(data): (source)

Return True if the argument looks like a encoded cookie.

def debug(mode=True): (source)

Change the debug level. There is only one debug level supported at the moment.

def depr(message, hard=False): (source)

Undocumented

def getargspec(func): (source)

Undocumented

def html_escape(string): (source)

Escape HTML special characters ``&<>`` and quotes ``'"``.

def html_quote(string): (source)

Escape and quote a string to be used as an HTTP attribute.

def http_date(value): (source)

Undocumented

def load(target, **namespace): (source)

Import a module or fetch an object from a module. * ``package.module`` returns `module` as a module object. * ``pack.mod:name`` returns the module variable `name` from `pack.mod`. * ``pack.mod:func()`` calls `pack.mod.func()` and returns the result. The last form accepts not only function calls, but any type of expression. Keyword arguments passed to this function are available as local variables. Example: ``import_string('re:compile(x)', x='[a-z]')``

def load_app(target): (source)

Load a bottle application from a module and make sure that the import does not affect the current default application, but returns a separate application object. See :func:`load` for the target parameter.

def local_property(name=None): (source)

Undocumented

def make_default_app_wrapper(name): (source)

Return a callable that relays calls to the current default app.

def makelist(data): (source)

Undocumented

def parse_auth(header): (source)

Parse rfc2617 HTTP authentication header string (basic) and return (user,pass) tuple or None

def parse_date(ims): (source)

Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch.

def parse_range_header(header, maxlen=0): (source)

Yield (start, end) ranges parsed from a HTTP Range header. Skip unsatisfiable ranges. The end index is non-inclusive.

def path_shift(script_name, path_info, shift=1): (source)

Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa. :return: The modified paths. :param script_name: The SCRIPT_NAME path. :param script_name: The PATH_INFO path. :param shift: The number of path fragments to shift. May be negative to change the shift direction. (default: 1)

def redirect(url, code=None): (source)

Aborts execution and causes a 303 or 302 redirect, depending on the HTTP protocol version.

def run(app=None, server='wsgiref', host='127.0.0.1', port=8080, interval=1, reloader=False, quiet=False, plugins=None, debug=None, **kargs): (source)

Start a server instance. This method blocks until the server terminates. :param app: WSGI application or target string supported by :func:`load_app`. (default: :func:`default_app`) :param server: Server adapter to use. See :data:`server_names` keys for valid names or pass a :class:`ServerAdapter` subclass. (default: `wsgiref`) :param host: Server address to bind to. Pass ``0.0.0.0`` to listens on all interfaces including the external one. (default: 127.0.0.1) :param port: Server port to bind to. Values below 1024 require root privileges. (default: 8080) :param reloader: Start auto-reloading server? (default: False) :param interval: Auto-reloader interval in seconds (default: 1) :param quiet: Suppress output to stdout and stderr? (default: False) :param options: Options passed to the server adapter.

def static_file(filename, root, mimetype='auto', download=False, charset='UTF-8'): (source)

Open a file in a safe way and return :exc:`HTTPResponse` with status code 200, 305, 403 or 404. The ``Content-Type``, ``Content-Encoding``, ``Content-Length`` and ``Last-Modified`` headers are set if possible. Special support for ``If-Modified-Since``, ``Range`` and ``HEAD`` requests. :param filename: Name or path of the file to send. :param root: Root path for file lookups. Should be an absolute directory path. :param mimetype: Defines the content-type header (default: guess from file extension) :param download: If True, ask the browser to open a `Save as...` dialog instead of opening the file with the associated program. You can specify a custom filename as a string. If not specified, the original filename is used (default: False). :param charset: The charset to use for files with a ``text/*`` mime-type. (default: UTF-8)

def template(*args, **kwargs): (source)

Get a rendered template as a string iterator. You can use a name, a filename or a template string as first parameter. Template rendering arguments can be passed as dictionaries or directly (as keyword arguments).

def tob(s, enc='utf8'): (source)

Undocumented

def touni(s, enc='utf8', err='strict'): (source)

Undocumented

def update_wrapper(wrapper, wrapped, *a, **ka): (source)

Undocumented

def view(tpl_name, **defaults): (source)

Decorator: renders a template for a handler. The handler can control its behavior like that: - return a dict of template vars to fill out the template - return something other than a dict and the view decorator will not process the template, but return the handler result as is. This includes returning a HTTPResponse(dict) to get, for instance, JSON with autojson or other castfilters.

def yieldroutes(func): (source)

Return a generator for routes that match the signature (name, args) of the func parameter. This may yield more than one route if the function takes optional keyword arguments. The output is best described by example:: a() -> '/a' b(x, y) -> '/b/<x>/<y>' c(x, y=5) -> '/c/<x>' and '/c/<x>/<y>' d(x=5, y=6) -> '/d' and '/d/<x>' and '/d/<x>/<y>'

Undocumented

Value
False
ERROR_PAGE_TEMPLATE = (source)

Undocumented

Value
'''
%%try:
    %%from %s import DEBUG, HTTP_CODES, request, touni
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
        <head>
            <title>Error: {{e.status}}</title>
...

Undocumented

Value
False
TEMPLATE_PATH: list[str] = (source)

Undocumented

Value
['./', './views/']
TEMPLATES: dict = (source)

Undocumented

Value
{}
__author__: str = (source)

Undocumented

__license__: str = (source)

Undocumented

__version__: str = (source)

Undocumented

Undocumented

callable = (source)

Undocumented

cheetah_template = (source)

Undocumented

cheetah_view = (source)

Undocumented

default_app = (source)

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

jinja2_template = (source)

Undocumented

jinja2_view = (source)

Undocumented

json_loads = (source)

Undocumented

Undocumented

mako_template = (source)

Undocumented

mako_view = (source)

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

response = (source)

Undocumented

Undocumented

server_names = (source)

Undocumented

Undocumented

uninstall = (source)

Undocumented

Undocumented

urlunquote = (source)

Undocumented

Undocumented

def _file_iter_range(fp, offset, bytes, maxread=1024*1024): (source)

Yield chunks from a range in a file. No chunk is bigger than maxread.

def _hkey(key): (source)

Undocumented

def _hval(value): (source)

Undocumented

def _lscmp(a, b): (source)

Compares two strings in a cryptographically safe way: Runtime is not affected by length of common prefix.

def _parse_qsl(qs): (source)

Undocumented

def _raise(*a): (source)

Undocumented

def _re_flatten(p): (source)

Turn all capturing groups in a regular expression pattern into non-capturing groups.

_HTTP_STATUS_LINES = (source)

Undocumented

Value
dict(((k, '%d %s' % (k, v)) for k, v in HTTP_CODES.items()))

Undocumented

Undocumented