{"id":16039538,"url":"https://github.com/glocktober/bottlesessions","last_synced_at":"2025-04-05T05:42:05.618Z","repository":{"id":62560376,"uuid":"392790344","full_name":"Glocktober/BottleSessions","owner":"Glocktober","description":"Session middleware for bottle micro web framework","archived":false,"fork":false,"pushed_at":"2021-09-21T21:00:28.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T05:42:01.958Z","etag":null,"topics":["bottle","framework","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Glocktober.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-04T18:25:50.000Z","updated_at":"2022-02-27T12:44:20.000Z","dependencies_parsed_at":"2022-11-03T14:30:28.068Z","dependency_job_id":null,"html_url":"https://github.com/Glocktober/BottleSessions","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2FBottleSessions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2FBottleSessions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2FBottleSessions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2FBottleSessions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Glocktober","download_url":"https://codeload.github.com/Glocktober/BottleSessions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294463,"owners_count":20915338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bottle","framework","python3"],"created_at":"2024-10-08T23:05:15.736Z","updated_at":"2025-04-05T05:42:05.602Z","avatar_url":"https://github.com/Glocktober.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## BottleSessions\n\n**BottleSessions** is middleware providing web _sessions_ for the **[Bottle](http://bottlepy.org/docs/dev/)** *micro web-framework*.  \n\nThe 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.  \n\n**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.\n##### Using the session\nAs an extension to `dict` the *session* is *pythonic* and is used like any other `dict`:\n```python\n    user = request.session.get('user','Anonymous)\n    ...\n    request.session.update({\n            'groups':['sysadmin','employee'], \n            'ip': request.ip\n        })\n    request.session['timestamp'] = time.now()\n```\nMore details on using the `BottleSessions.Session` class are [available.](docs/SESSIONS.md)\n#### Installation\n\nInstall from pypi:\n```bash\npip install BottleSessions\n```\n#### BottleSessions Example \n\n```python\n#app.py:\n\nfrom BottleSessions import BottleSessions\nfrom bottle import Bottle, request\n\napp = Bottle()\nbtl = BottleSessions(app)\n\n@app.route('/set/\u003ckey\u003e/\u003cval\u003e')\ndef set_sess(key,val=None):\n\n    request.session[key] = val\n    return {key: val}\n\n@app.route('/get/\u003ckey\u003e')\ndef get_sess(key=None):\n\n    return {key: request.session.get(key,'does not exist')}\n\n@app.route('/')\ndef hello():\n    return 'hello world'\n\nif __name__ == '__main__':\n    app.run()\n#app.py:\n\nfrom BottleSessions import BottleSessions\nfrom bottle import Bottle, request\n\napp = Bottle()\nbtl = BottleSessions(app)\n\n@app.route('/set/\u003ckey\u003e/\u003cval\u003e')\ndef set_sess(key,val=None):\n\n    request.session[key] = val\n    return {key: val}\n\n@app.route('/get/\u003ckey\u003e')\ndef get_sess(key=None):\n\n    return {key: request.session.get(key,'does not exist')}\n\n@app.route('/')\ndef hello():\n    return 'hello world'\n\nif __name__ == '__main__':\n    app.run()\n\n```\nAnother sample app is [available here](examples/sample_session_app.py)\n\n#### BottleSession Defaults and Tuning\n\n**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**.\n\nThese 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.  \n\n#### Backing Store\nThe backing store is provided by [Pallets Project *cachelib* library](https://pypi.org/project/cachelib/) and uses **SimpleCache** as the default.  \n\n*cachelib* **FileSystemCache**, **RedisCache**, and **Memcached** classes are also supported and can be configured with class specific options:\n\n```python\n# config.py - FileSystemCache configuration\ncache_config = {\n    'cache_type': 'FileSystem',\n    'cache_dir' : './sess_dir',\n    'threshold': 2000,\n    # Additional configuration parameters\n    # per cachelib docs\n    }\n```\n```python\n# app.py initialization\n    ...\nfrom config import cache_config\nbtl = BottleSessions(app, session_backing=cache_config,\nsession_cookie='appcookie')\n```\nFurther information is [available on configuring session backing store](docs/BACKING.md) for differing needs and differing cache types.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglocktober%2Fbottlesessions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglocktober%2Fbottlesessions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglocktober%2Fbottlesessions/lists"}