Bottle Web Framework
Bottle is a fast, lightweight, and simple WSGI micro-framework for small web-applications. It provides routing, templating, and basic utilities in a single file, making it ideal for prototyping and small services. The current stable version is 0.13.4, with releases occurring infrequently, often focusing on Python version compatibility and minor fixes rather than new features.
Warnings
- breaking Bottle 0.13 dropped support for Python 2.x and older Python 3.x versions (3.4, 3.5, 3.6). Projects upgrading to 0.13 or newer must use Python 3.7 or higher.
- breaking The default host for `bottle.run()` changed from `0.0.0.0` (all interfaces) to `127.0.0.1` (localhost only) in version 0.13 for security reasons. This affects how your development server is accessible.
- gotcha Bottle's `request` and `response` objects are thread-local proxies. Attempting to access them outside of an active request context (e.g., at module level) will result in a `RuntimeError`.
- gotcha The `bottle.run()` function is intended solely for development and testing. It uses a simple, single-threaded server and is not suitable for production deployments due to performance, reliability, and security concerns.
Install
-
pip install bottle
Imports
- route
from bottle import route
- run
from bottle import run
- request
from bottle import request
- response
from bottle import response
- template
from bottle import template
Quickstart
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
# For development, specify host explicitly due to 0.13 change
# For production, use a WSGI server like Gunicorn or uWSGI
if __name__ == '__main__':
run(host='127.0.0.1', port=8080)