All Projects → aio-libs → Aiohttp Session

aio-libs / Aiohttp Session

Licence: other
Web sessions for aiohttp.web

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Aiohttp Session

Aioinflux
Asynchronous Python client for InfluxDB
Stars: ✭ 142 (-16.96%)
Mutual labels:  asyncio, aiohttp
Gain
Web crawling framework based on asyncio.
Stars: ✭ 2,002 (+1070.76%)
Mutual labels:  asyncio, aiohttp
Aioauth
Asynchronous OAuth 2.0 framework and provider for Python 3
Stars: ✭ 102 (-40.35%)
Mutual labels:  asyncio, aiohttp
Python Simple Rest Client
Simple REST client for python 3.6+
Stars: ✭ 143 (-16.37%)
Mutual labels:  asyncio, aiohttp
Aiohttp
Asynchronous HTTP client/server framework for asyncio and Python
Stars: ✭ 11,972 (+6901.17%)
Mutual labels:  asyncio, aiohttp
Rororo
Implement aiohttp.web OpenAPI 3 server applications with schema first approach.
Stars: ✭ 95 (-44.44%)
Mutual labels:  asyncio, aiohttp
Tgfilestream
A Telegram bot that can stream Telegram files to users over HTTP.
Stars: ✭ 113 (-33.92%)
Mutual labels:  asyncio, aiohttp
Rocketgram
Modern and powerful asynchronous telegram bot framework.
Stars: ✭ 37 (-78.36%)
Mutual labels:  asyncio, aiohttp
Backendschool2019
Приложение для практического руководства по разработке бекенд-сервисов на Python (на основе вступительного испытания в Школу бэкенд‑разработки Яндекса)
Stars: ✭ 129 (-24.56%)
Mutual labels:  asyncio, aiohttp
Aioelasticsearch
aioelasticsearch-py wrapper for asyncio
Stars: ✭ 127 (-25.73%)
Mutual labels:  asyncio, aiohttp
Raven Aiohttp
An aiohttp transport for raven-python
Stars: ✭ 92 (-46.2%)
Mutual labels:  asyncio, aiohttp
Aiozipkin
Distributed tracing instrumentation for asyncio with zipkin
Stars: ✭ 161 (-5.85%)
Mutual labels:  asyncio, aiohttp
Python Dependency Injector
Dependency injection framework for Python
Stars: ✭ 1,203 (+603.51%)
Mutual labels:  asyncio, aiohttp
Ruia
Async Python 3.6+ web scraping micro-framework based on asyncio
Stars: ✭ 1,366 (+698.83%)
Mutual labels:  asyncio, aiohttp
Pyfailsafe
Simple failure handling. Failsafe implementation in Python
Stars: ✭ 70 (-59.06%)
Mutual labels:  asyncio, aiohttp
Sockjs
SockJS Server
Stars: ✭ 105 (-38.6%)
Mutual labels:  asyncio, aiohttp
V3n0m Scanner
Popular Pentesting scanner in Python3.6 for SQLi/XSS/LFI/RFI and other Vulns
Stars: ✭ 847 (+395.32%)
Mutual labels:  asyncio, aiohttp
Heroku Aiohttp Web
A project starter template for deploying an aiohttp app to Heroku
Stars: ✭ 14 (-91.81%)
Mutual labels:  asyncio, aiohttp
Aiohttp Sse
Server-sent events support for aiohttp
Stars: ✭ 125 (-26.9%)
Mutual labels:  asyncio, aiohttp
Pymxget
mxget的Python实现
Stars: ✭ 136 (-20.47%)
Mutual labels:  asyncio, aiohttp

aiohttp_session

.. image:: https://travis-ci.com/aio-libs/aiohttp-session.svg?branch=master :target: https://travis-ci.com/aio-libs/aiohttp-session .. image:: https://codecov.io/github/aio-libs/aiohttp-session/coverage.svg?branch=master :target: https://codecov.io/github/aio-libs/aiohttp-session .. image:: https://readthedocs.org/projects/aiohttp-session/badge/?version=latest :target: https://aiohttp-session.readthedocs.io/ .. image:: https://img.shields.io/pypi/v/aiohttp-session.svg :target: https://pypi.python.org/pypi/aiohttp-session

The library provides sessions for aiohttp.web__.

.. _aiohttp_web: https://aiohttp.readthedocs.io/en/latest/web.html

__ aiohttp_web_

Usage

The library allows us to store user-specific data into a session object.

The session object has a dict-like interface (operations like session[key] = value, value = session[key] etc. are present).

Before processing the session in a web-handler, you have to register the session middleware in aiohttp.web.Application.

A trivial usage example:

.. code:: python

import time
import base64
from cryptography import fernet
from aiohttp import web
from aiohttp_session import setup, get_session
from aiohttp_session.cookie_storage import EncryptedCookieStorage


async def handler(request):
    session = await get_session(request)
    last_visit = session['last_visit'] if 'last_visit' in session else None
    session['last_visit'] = time.time()
    text = 'Last visited: {}'.format(last_visit)
    return web.Response(text=text)


def make_app():
    app = web.Application()
    # secret_key must be 32 url-safe base64-encoded bytes
    fernet_key = fernet.Fernet.generate_key()
    secret_key = base64.urlsafe_b64decode(fernet_key)
    setup(app, EncryptedCookieStorage(secret_key))
    app.router.add_get('/', handler)
    return app


web.run_app(make_app())

All storages use an HTTP Cookie named AIOHTTP_SESSION for storing data. This can be modified by passing the keyword argument cookie_name to the storage class of your choice.

Available session storages are:

  • aiohttp_session.SimpleCookieStorage() -- keeps session data as a plain JSON string in the cookie body. Use the storage only for testing purposes, it's very non-secure.

  • aiohttp_session.cookie_storage.EncryptedCookieStorage(secret_key) -- stores the session data into a cookie as SimpleCookieStorage but encodes it via AES cipher. secrect_key is a bytes key for AES encryption/decryption, the length should be 32 bytes.

    Requires cryptography library::

    $ pip install aiohttp_session[secure]
    
  • aiohttp_session.redis_storage.RedisStorage(redis_pool) -- stores JSON encoded data in redis, keeping only the redis key (a random UUID) in the cookie. redis_pool is a aioredis pool object, created by await aioredis.create_redis_pool(...) call.

    Requires aioredis library (only versions 1.0+ are supported)::

    $ pip install aiohttp_session[aioredis]
    

Developing

Install for local development::

$ pip install -r requirements-dev.txt

Run tests with::

$ pytest -sv tests/

Third party extensions

  • aiohttp_session_mongo <https://github.com/alexpantyukhin/aiohttp-session-mongo>_

  • aiohttp_session_dynamodb <https://github.com/alexpantyukhin/aiohttp-session-dynamodb>_

License

aiohttp_session is offered under the Apache 2 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].