ASGI-Sessions
#############
.. _description:
**asgi-sessions** -- Cookie-Based HTTP sessions for ASGI applications (Asyncio_ / Trio_, / Curio_)
.. _badges:
.. image:: https://github.com/klen/asgi-sessions/workflows/tests/badge.svg
:target: https://github.com/klen/asgi-sessions/actions
:alt: Tests Status
.. image:: https://img.shields.io/pypi/v/asgi-sessions
:target: https://pypi.org/project/asgi-sessions/
:alt: PYPI Version
.. image:: https://img.shields.io/pypi/pyversions/asgi-sessions
:target: https://pypi.org/project/asgi-sessions/
:alt: Python Versions
.. _contents:
.. contents::
Features
========
* Supports base64 sessions
* Supports ``JWT`` signed sessions
* Supports ``Fernet`` encrypted sessions
.. _requirements:
Requirements
=============
- python >= 3.9
.. _installation:
Installation
=============
**asgi-sessions** should be installed using pip: ::
pip install asgi-sessions
To install optional ``JWT``, ``Fernet`` support: ::
pip install asgi-sessions[jwt]
pip install asgi-sessions[fernet]
.. _usage:
Usage
=====
Common ASGI applications:
.. code:: python
from asgi_sessions import SessionMiddleware
async def my_app(scope, receive, send):
"""Read session and get the current user data from it or from request query."""
# The middleware puts a session into scope['session]
session = scope['session']
status, headers = 200, []
if scope['query_string']:
# Store any information inside the session
session['user'] = scope['query_string'].decode()
status, headers = 307, [(b"location", b"/")]
# Read a stored info from the session
user = (session.get('user') or 'anonymous').title().encode()
await send({"type": "http.response.start", "status": status, "headers": headers})
await send({"type": "http.response.body", "body": b"Hello %s" % user})
app = SessionMiddleware(my_app, session_type='jwt', secret_key="sessions-secret")
# http GET / -> Hello Anonymous
# http GET /?tom -> Hello Tom
# http GET / -> Hello Tom
As ASGI-Tools Internal middleware
.. code:: python
from asgi_tools import App
from asgi_sessions import SessionMiddleware
app = App()
app.middleware(SessionMiddleware.setup(session_type='jwt', secret_key='SESSION-SECRET'))
@app.route('/')
async def index(request):
user = request.session.get('user', 'Anonymous')
return 'Hello %s' % user.title()
@app.route('/login/{user}')
async def login(request):
request.session['user'] = request.path_params.get('user', 'Anonymous')
return 'Done'
@app.route('/logout')
async def logout(request, *args):
del request.session['user']
return 'Done'
# http GET / -> Hello Anonymous
# http GET /login/tom -> Done
# http GET / -> Hello Tom
# http GET /logout -> Done
# http GET / -> Hello Anonymous
Options
========
.. code:: python
from asgi_sessions import SessionMiddleware
app = SessionMiddleware(
# Your ASGI application
app,
# Session type (base64|jwt|fernet)
session_type="base64",
# Secret Key for the session (required for JWT/Fernet sessions)
secret_key=None,
# Cookie name to keep the session (optional)
cookie_name='session',
# Cookie max age (in seconds) (optional)
max_age=14 * 24 * 3600,
# Cookie samesite (optional) # Python 3.8+ only
samesite='lax',
# Cookie secure (https only) (optional)
secure=False,
)
.. _bugtracker:
Bug tracker
===========
If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/asgi-sessions/issues
.. _contributing:
Contributing
============
Development of the project happens at: https://github.com/klen/asgi-sessions
.. _license:
License
========
Licensed under a `MIT license`_.
.. _links:
.. _MIT license: http://opensource.org/licenses/MIT
.. _Asyncio: https://docs.python.org/3/library/asyncio.html
.. _klen: https://github.com/klen
.. _Trio: https://trio.readthedocs.io/en/stable/
.. _Curio: https://curio.readthedocs.io/en/latest/
Raw data
{
"_id": null,
"home_page": null,
"name": "asgi-sessions",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "asyncio, trio, asgi, asgi sessions, cookies",
"author": null,
"author_email": "Kirill Klenov <horneds@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/db/25/773f72b7b0c51593afb7ad787895cc3a6eb1a899beb6d3c5cfc07305f4c9/asgi_sessions-1.2.4.tar.gz",
"platform": null,
"description": "ASGI-Sessions\n#############\n\n.. _description:\n\n**asgi-sessions** -- Cookie-Based HTTP sessions for ASGI applications (Asyncio_ / Trio_, / Curio_)\n\n.. _badges:\n\n.. image:: https://github.com/klen/asgi-sessions/workflows/tests/badge.svg\n :target: https://github.com/klen/asgi-sessions/actions\n :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/asgi-sessions\n :target: https://pypi.org/project/asgi-sessions/\n :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/asgi-sessions\n :target: https://pypi.org/project/asgi-sessions/\n :alt: Python Versions\n\n.. _contents:\n\n.. contents::\n\nFeatures\n========\n\n* Supports base64 sessions\n* Supports ``JWT`` signed sessions\n* Supports ``Fernet`` encrypted sessions\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.9\n\n.. _installation:\n\nInstallation\n=============\n\n**asgi-sessions** should be installed using pip: ::\n\n pip install asgi-sessions\n\nTo install optional ``JWT``, ``Fernet`` support: ::\n\n pip install asgi-sessions[jwt]\n pip install asgi-sessions[fernet]\n\n.. _usage:\n\nUsage\n=====\n\nCommon ASGI applications:\n\n.. code:: python\n\n from asgi_sessions import SessionMiddleware\n\n\n async def my_app(scope, receive, send):\n \"\"\"Read session and get the current user data from it or from request query.\"\"\"\n # The middleware puts a session into scope['session]\n session = scope['session']\n\n status, headers = 200, []\n if scope['query_string']:\n # Store any information inside the session\n session['user'] = scope['query_string'].decode()\n status, headers = 307, [(b\"location\", b\"/\")]\n\n # Read a stored info from the session\n user = (session.get('user') or 'anonymous').title().encode()\n\n await send({\"type\": \"http.response.start\", \"status\": status, \"headers\": headers})\n await send({\"type\": \"http.response.body\", \"body\": b\"Hello %s\" % user})\n\n app = SessionMiddleware(my_app, session_type='jwt', secret_key=\"sessions-secret\")\n\n # http GET / -> Hello Anonymous\n # http GET /?tom -> Hello Tom\n # http GET / -> Hello Tom\n\n\nAs ASGI-Tools Internal middleware\n\n.. code:: python\n\n from asgi_tools import App\n from asgi_sessions import SessionMiddleware\n\n app = App()\n app.middleware(SessionMiddleware.setup(session_type='jwt', secret_key='SESSION-SECRET'))\n\n @app.route('/')\n async def index(request):\n user = request.session.get('user', 'Anonymous')\n return 'Hello %s' % user.title()\n\n @app.route('/login/{user}')\n async def login(request):\n request.session['user'] = request.path_params.get('user', 'Anonymous')\n return 'Done'\n\n @app.route('/logout')\n async def logout(request, *args):\n del request.session['user']\n return 'Done'\n\n # http GET / -> Hello Anonymous\n # http GET /login/tom -> Done\n # http GET / -> Hello Tom\n # http GET /logout -> Done\n # http GET / -> Hello Anonymous\n\n\nOptions\n========\n\n.. code:: python\n\n from asgi_sessions import SessionMiddleware\n\n app = SessionMiddleware(\n\n # Your ASGI application\n app,\n\n # Session type (base64|jwt|fernet)\n session_type=\"base64\",\n\n # Secret Key for the session (required for JWT/Fernet sessions)\n secret_key=None,\n\n # Cookie name to keep the session (optional)\n cookie_name='session',\n\n # Cookie max age (in seconds) (optional)\n max_age=14 * 24 * 3600,\n\n # Cookie samesite (optional) # Python 3.8+ only\n samesite='lax',\n\n # Cookie secure (https only) (optional)\n secure=False,\n\n )\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/asgi-sessions/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of the project happens at: https://github.com/klen/asgi-sessions\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n\n.. _links:\n\n.. _MIT license: http://opensource.org/licenses/MIT\n.. _Asyncio: https://docs.python.org/3/library/asyncio.html\n.. _klen: https://github.com/klen\n.. _Trio: https://trio.readthedocs.io/en/stable/\n.. _Curio: https://curio.readthedocs.io/en/latest/\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Signed Cookie-Based HTTP sessions for ASGI applications",
"version": "1.2.4",
"project_urls": {
"homepage": "https://github.com/klen/asgi-sessions",
"repository": "https://github.com/klen/asgi-sessions"
},
"split_keywords": [
"asyncio",
" trio",
" asgi",
" asgi sessions",
" cookies"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ffc5f6ac8db56e8b78680d54521668752843121be0916fe44727d1924f44d90c",
"md5": "9ac35e7a5db2a7de0a13e6146139e5d3",
"sha256": "cd57df5c58c897569754abeb10ad5e503c82985e3b52a7b6b693ff328eab157e"
},
"downloads": -1,
"filename": "asgi_sessions-1.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9ac35e7a5db2a7de0a13e6146139e5d3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6175,
"upload_time": "2024-07-31T13:36:13",
"upload_time_iso_8601": "2024-07-31T13:36:13.622055Z",
"url": "https://files.pythonhosted.org/packages/ff/c5/f6ac8db56e8b78680d54521668752843121be0916fe44727d1924f44d90c/asgi_sessions-1.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db25773f72b7b0c51593afb7ad787895cc3a6eb1a899beb6d3c5cfc07305f4c9",
"md5": "3daa79210eb986ab2aef6af291d8bf47",
"sha256": "04e92f1a98970a77126b9ab73d23e77df10584ef816e6cbfd03dd362d732bd63"
},
"downloads": -1,
"filename": "asgi_sessions-1.2.4.tar.gz",
"has_sig": false,
"md5_digest": "3daa79210eb986ab2aef6af291d8bf47",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6324,
"upload_time": "2024-07-31T13:36:17",
"upload_time_iso_8601": "2024-07-31T13:36:17.825713Z",
"url": "https://files.pythonhosted.org/packages/db/25/773f72b7b0c51593afb7ad787895cc3a6eb1a899beb6d3c5cfc07305f4c9/asgi_sessions-1.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-31 13:36:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "klen",
"github_project": "asgi-sessions",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asgi-sessions"
}