## BottleSessions
**BottleSessions** is middleware providing web _sessions_ for the **[Bottle](http://bottlepy.org/docs/dev/)** *micro web-framework*.
The goal of **BottleSessions** is to provide easy to use and flexible to configure sessions. The _defaults_ attempt to make sense for typical bottle web apps with little or no tuning.
**BottleSessions** is simple for the programmer to use in both *middleware* and route *views*. The ***Session*** is a superclass of a Python `dict`, accessible as an attribute added to the bottle **`request`** object as **`request.session`**. No special sauce is required to acquire or use the session.
##### Using the session
As an extension to `dict` the *session* is *pythonic* and is used like any other `dict`:
```python
user = request.session.get('user','Anonymous)
...
request.session.update({
'groups':['sysadmin','employee'],
'ip': request.ip
})
request.session['timestamp'] = time.now()
```
More details on using the `BottleSessions.Session` class are [available.](docs/SESSIONS.md)
#### Installation
Install from pypi:
```bash
pip install BottleSessions
```
#### BottleSessions Example
```python
#app.py:
from BottleSessions import BottleSessions
from bottle import Bottle, request
app = Bottle()
btl = BottleSessions(app)
@app.route('/set/<key>/<val>')
def set_sess(key,val=None):
request.session[key] = val
return {key: val}
@app.route('/get/<key>')
def get_sess(key=None):
return {key: request.session.get(key,'does not exist')}
@app.route('/')
def hello():
return 'hello world'
if __name__ == '__main__':
app.run()
#app.py:
from BottleSessions import BottleSessions
from bottle import Bottle, request
app = Bottle()
btl = BottleSessions(app)
@app.route('/set/<key>/<val>')
def set_sess(key,val=None):
request.session[key] = val
return {key: val}
@app.route('/get/<key>')
def get_sess(key=None):
return {key: request.session.get(key,'does not exist')}
@app.route('/')
def hello():
return 'hello world'
if __name__ == '__main__':
app.run()
```
Another sample app is [available here](examples/sample_session_app.py)
#### BottleSession Defaults and Tuning
**BottleSessions** default behavior provides a session/cookie life of 300 seconds after last update using a cookie named **bottlecookie** marked `Secure` and `http-only` with `path=/`. The sessions use the same lifetime and are stored in a memory based *cachelib* **SimpleCache**.
These defaults are useful for a range of micro-framework web apps Bottle is typically used for. However, different applications have differing session needs. Hence both cookies and sessions can be [easily customized](docs/OPTIONS.md) to suite a variety of uses.
#### Backing Store
The backing store is provided by [Pallets Project *cachelib* library](https://pypi.org/project/cachelib/) and uses **SimpleCache** as the default.
*cachelib* **FileSystemCache**, **RedisCache**, and **Memcached** classes are also supported and can be configured with class specific options:
```python
# config.py - FileSystemCache configuration
cache_config = {
'cache_type': 'FileSystem',
'cache_dir' : './sess_dir',
'threshold': 2000,
# Additional configuration parameters
# per cachelib docs
}
```
```python
# app.py initialization
...
from config import cache_config
btl = BottleSessions(app, session_backing=cache_config,
session_cookie='appcookie')
```
Further information is [available on configuring session backing store](docs/BACKING.md) for differing needs and differing cache types.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共20个文件
py:6个
txt:5个
md:4个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
资源分类:Python库 所属语言:Python 资源全名:BottleSessions-21.9.21.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源详情
资源评论
资源推荐
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 20 条
- 1
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar](https://profile-avatar.csdnimg.cn/277f6345dca0446498fbbc03843436aa_qq_38161040.jpg!1)
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0