Skip to main content

MySQL integration for Bottle.

Project description

Bottle-MySQL is a plugin that integrates MySQL with your Bottle application. It automatically connects to a database at the beginning of a request, passes the database handle to the route callback and closes the connection afterwards.

To automatically detect routes that need a database connection, the plugin searches for route callbacks that require a db keyword argument (configurable) and skips routes that do not. This removes any overhead for routes that don’t need a database connection.

Results are returned as dictionaries.

Usage Example:

import bottle
import bottle_mysql

app = bottle.Bottle()
# dbhost is optional, default is localhost
plugin = bottle_mysql.Plugin(dbuser='user', dbpass='pass', dbname='db')
app.install(plugin)

@app.route('/show/:<tem>')
def show(item, db):
    db.execute('SELECT * from items where name="%s"', (item,))
    row = db.fetchone()
    if row:
        return template('showitem', page=row)
    return HTTPError(404, "Page not found")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bottle-mysql-0.2.0.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file bottle-mysql-0.2.0.tar.gz.

File metadata

  • Download URL: bottle-mysql-0.2.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bottle-mysql-0.2.0.tar.gz
Algorithm Hash digest
SHA256 381e02854e4a6b9e94145f9bddd1e23c2a6c56ec42fce9cdc2e16859af0b56a3
MD5 a224dcc4ba60c44e13fbf80d46c86432
BLAKE2b-256 f25a9192277f6e782c19d0fa3fe9def51dcef259862c5c1eb01fc8f9bce1e662

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page