bottle-sqlite3
This is a fork of Bottle-SQLite.
SQLite is a self-contained SQL database engine that runs locally and does not require any additional server software or setup. The sqlite3 module is part of the Python standard library and already installed on most systems. It it very useful for prototyping database-driven applications that are later ported to larger databases such as PostgreSQL or MySQL.
This plugin simplifies the use of sqlite databases in your Bottle applications.
Once installed, all you have to do is to add a db keyword argument
(configurable) to route callbacks that need a database connection.
Installation
Install with one of the following commands:
$ pip install bottle-sqlite3
$ easy_install bottle-sqlite3
or install the latest version directly from github:
$ pip install git+https://github.com/hamukazu/bottle-sqlite3
Usage
Once installed to an application, the plugin passes an open
sqlite3.Connection instance to all routes that require a db keyword
argument:
import bottle
from bottle_sqlite3 import SQLitePlugin
app = bottle.Bottle()
plugin = SQLitePlugin(dbfile='/tmp/test.db')
app.install(plugin)
@app.route('/show/:item')
def show(item, db):
row = db.execute('SELECT * from items where name=?', item).fetchone()
if row:
return template('showitem', page=row)
return HTTPError(404, "Page not found")
Routes that do not expect a db keyword argument are not affected.
The connection handle is configured so that sqlite3.Row objects can be
accessed both by index (like tuples) and case-insensitively by name. At the end of
the request cycle, outstanding transactions are committed and the connection is
closed automatically. If an error occurs, any changes to the database since the
last commit are rolled back to keep the database in a consistent state.
Configuration
The following configuration options exist for the plugin class:
- dbfile: Database filename (default: in-memory database).
- keyword: The keyword argument name that triggers the plugin (default: 'db').
- autocommit: Whether or not to commit outstanding transactions at the end of the request cycle (default: True).
- dictrows: Whether or not to support dict-like access to row objects (default: True).
- text_factory: The text_factory for the connection (default: unicode).
- functions: Add user-defined functions for use in SQL, should be a dict like
{'name': (num_params, func)}(default: None). - aggregates: Add user-defined aggregate functions, should be a dict like
{'name': (num_params, aggregate_class)}(default: None). - collations: Add user-defined collations, should be a dict like
{'name': callable}(default: None). - extensions: Load extensions on connect. Should be a list of extension names. (default: None).
You can override each of these values on a per-route basis:
@app.route('/cache/:item', sqlite={'dbfile': ':memory:'})
def cache(item, db):
...
or install two plugins with different keyword settings to the same application:
app = bottle.Bottle()
test_db = SQLitePlugin(dbfile='/tmp/test.db')
cache_db = SQLitePlugin(dbfile=':memory:', keyword='cache')
app.install(test_db)
app.install(cache_db)
@app.route('/show/:item')
def show(item, db):
...
@app.route('/cache/:item')
def cache(item, cache):
...
Changelog
- 0.2 2020-10-03
- Fixed
text_factoryparameter. - Added
functions,aggregates,collationsandextensionsparameters. - Stopped testing for dead Python versions.
- Fixed
Metadata
Release files for bottle-sqlite3 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bottle_sqlite3-0.1.0.tar.gz | 4.0 kB | Without provenance | Details for bottle_sqlite3-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bottle_sqlite3-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bottle_sqlite3-0.1.0-py3-none-any.whl |
Total release size: 9.3 kB
Release files / bottle_sqlite3-0.1.0.tar.gz
| Download URL | bottle_sqlite3-0.1.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
627dcb2d90919ff6ae2f99fe143b06353057f45cd7a894d5cb834d4942b5f26d
|
|
BLAKE2b-256 checksum How to use checksums |
c2b14621e0eca33202d585325bc9ca7e0ac0be4861431f054865269441d3581b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Release files / bottle_sqlite3-0.1.0-py3-none-any.whl
| Download URL | bottle_sqlite3-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6af10f7e46bd35b8aa9e67ea546256e9bc9a145b537c37264dd0cc2581c7b3c
|
|
BLAKE2b-256 checksum How to use checksums |
58b8aaea2180a1cbe2df44d7cfaf160fd458c62964c811cc485179c952c69578
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Security for bottle-sqlite3 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.