{ "info": { "author": "Imbolc", "author_email": "imbolc@imbolc.name", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Async Django Session\n====================\n\nIt gives you ability to share session between [django][] and an async framework\nlike [aiohttp][], [starlette][], [fastapi][] etc.\n\n pip install async-django-session\n\nAPI\n---\n\n### Backends\n\nThere's two ways of communicating to database available:\n\n- through [databases][] - which is compatible with most of major RDBMS:\n ```python\n database = databases.Database(DB_URI)\n await database.connect()\n backend = async_django_session.databases.Backend(database, SECRET_KEY)\n ```\n- or directly through [asyncpg][] (PostgreSQL only):\n ```python\n pool = await asyncpg.create_pool(DB_URI)\n backend = async_django_session.asyncpg.Backend(pool, SECRET_KEY)\n ```\n\n### Session\n\nTo fetch session from db by its key there's `backend.get_session` method. If\n`key` is `None` a new session will be created:\n```python\nsession = backend.get_session(key)\n```\nIt's lazy so the session data won't be actually fetched until you call its\n`load` method. In caches the result, so it's inexpensive to call it multiple\ntimes:\n```python\nawait session.load()\n```\nYou can combine them into a single line as the `load` method returns session\nitself:\n```python\nsession = await backend.get_session(key).load()\n```\nSession provides dict-interface to read / write data:\n```python\nsession[\"foo\"] = \"bar\"\nprint(session[\"foo\"])\n```\nTo sync session with database you should explicitly call its `save` method. It\nwon't make unnecessary db call if the session wasn't changed (the boolean value\nit returns is intend to indicate if it was the case).\n```python\nsaved = await session.save()\n```\nDuring saving of a new session a random key will be generated and available as\n`session.key` parameter afterwords.\n\nFrameworks integration\n----------------------\nThere's built-in middlewares for a few frameworks to automatically load (using\nsession id from cookies) and save sessions.\n\n### Aiohttp\nAfter adding of [session middleware][aiohttp middleware]:\n```python\nsession_middleware = async_django_session.aiohttp.middleware(\n async_django_session.databases.Backend(db, SECRET_KEY)\n)\napp = web.Application(middlewares=[session_middleware])\n```\nYou can get requests session as:\n```python\nsession = await request.get_session()\n```\nA full aiohttp example can be found [here][aiohttp example].\n\n### Starlette\nAfter adding of [session middleware][starlette middleware]:\n```python\nasync_django_session.starlette.middleware(\n app, async_django_session.databases.Backend(db, SECRET))\n)\n```\nSession of a current request is available as:\n```python\nsession = await request.state.get_session()\n```\n\nA working starlette example is [here][starlette example].\n\n### Fastapi\nPerform starlette app initialization from above as fastapi based on it.\nAfter that you can get session using dependency injection as:\n```python\nfrom async_django_session.fastapi import get_session\nfrom async_django_session.session import Session\n\nasync def index(session: Session = Depends(get_session)):\n ...\n```\n\nA working fastapi example is [here][fastapi example].\n\nRunning examples\n----------------\nRunning the [examples][] you can see different frameworks using the same session\ndata. To see session data open after running of each\nexample.\n\nInstall requirements:\n\n cd examples\n pip install -r requirements.txt\n\nCreate database and tables:\n\n createdb async_django_session\n python django_app.py migrate\n\nRun [aiohttp example][] which uses [databases backend][]:\n\n python aiohttp_app.py\n\nRun [starlette example][] which uses [asyncpg backend][]:\n\n python starlette_app.py\n\nRun [fastapi example][] which uses [asyncpg backend][]:\n\n python fastapi_app.py\n\nRun [django example][]:\n\n python django_app.py runserver\n\n[aiohttp]: https://github.com/aio-libs/aiohttp\n[starlette]: https://github.com/encode/starlette\n[fastapi]: https://github.com/tiangolo/fastapi\n[asyncpg]: https://github.com/MagicStack/asyncpg\n[databases]: https://github.com/encode/databases\n[django]: https://github.com/django/django\n[examples]: https://github.com/imbolc/async_django_session/tree/master/examples\n[django example]: https://github.com/imbolc/async_django_session/tree/master/examples/django_app.py\n[starlette example]: https://github.com/imbolc/async_django_session/tree/master/examples/starlette_app.py\n[fastapi example]: https://github.com/imbolc/async_django_session/tree/master/examples/fastapi_app.py\n[aiohttp example]: https://github.com/imbolc/async_django_session/tree/master/examples/aiohttp_app.py\n[asyncpg backend]: https://github.com/imbolc/async_django_session/tree/master/async_django_session/asyncpg.py\n[databases backend]: https://github.com/imbolc/async_django_session/tree/master/async_django_session/databases.py\n[aiohttp middleware]: https://github.com/imbolc/async_django_session/tree/master/async_django_session/aiohttp.py\n[starlette middleware]: https://github.com/imbolc/async_django_session/tree/master/async_django_session/starlette.py\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/imbolc/async_django_session", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "async-django-session", "package_url": "https://pypi.org/project/async-django-session/", "platform": "", "project_url": "https://pypi.org/project/async-django-session/", "project_urls": { "Homepage": "https://github.com/imbolc/async_django_session" }, "release_url": "https://pypi.org/project/async-django-session/0.3.1/", "requires_dist": null, "requires_python": "", "summary": "Django-compatible session for async frameworks", "version": "0.3.1", "yanked": false, "yanked_reason": null }, "last_serial": 6010645, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ea1046e0eec583099a687c77b7ac74c2", "sha256": "8eed48e55229dad92e1f41d3670829f39b7a7f9642b15517f82cfe616b1685cf" }, "downloads": -1, "filename": "async_django_session-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ea1046e0eec583099a687c77b7ac74c2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6594, "upload_time": "2019-10-15T14:38:39", "upload_time_iso_8601": "2019-10-15T14:38:39.346624Z", "url": "https://files.pythonhosted.org/packages/eb/f7/2a73044ac10fe915366feab4bc3653a19ad418586183ec69b3f286af7722/async_django_session-0.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "6dce22788f071b67ecf3683fde66f89e", "sha256": "a88d0dbf91abff7ea825f48b2cc9535457553d531a07947994aee9d04b192cad" }, "downloads": -1, "filename": "async_django_session-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6dce22788f071b67ecf3683fde66f89e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6612, "upload_time": "2019-10-15T14:55:16", "upload_time_iso_8601": "2019-10-15T14:55:16.529003Z", "url": "https://files.pythonhosted.org/packages/17/28/5aacb630433fd8a80306ab8337ad005c0251b42c2296c001affe1fbd4560/async_django_session-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "2ed0d33946fc80ab1a536eed9b31ad97", "sha256": "ab8dce40529a660f55312358c5089052a6ef321fa1939122633c9c83c941e454" }, "downloads": -1, "filename": "async_django_session-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2ed0d33946fc80ab1a536eed9b31ad97", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6620, "upload_time": "2019-10-15T14:58:37", "upload_time_iso_8601": "2019-10-15T14:58:37.850777Z", "url": "https://files.pythonhosted.org/packages/23/0f/5d749e306e28efa4f557352a229e5a1b2107a21aeffb519d17010e316225/async_django_session-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "fce9d6210cfcc836c38fce9bf6170d8b", "sha256": "5db83b69d95d7d6a21a62390f9610103fdf9de68d9db146900c9617080fc6066" }, "downloads": -1, "filename": "async_django_session-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fce9d6210cfcc836c38fce9bf6170d8b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6611, "upload_time": "2019-10-15T18:26:59", "upload_time_iso_8601": "2019-10-15T18:26:59.706114Z", "url": "https://files.pythonhosted.org/packages/cb/9b/a6cdcce31218c1b7a5180c363fde32463f1c4a1a2f624e8a2cb9aeb47cb8/async_django_session-0.2.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "6bc3f4e17b436e43ad109c203aa77f40", "sha256": "2987174b4f4299b9bb1d068447a2b5ae17b6a639d5be114bf89e00211d609058" }, "downloads": -1, "filename": "async_django_session-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "6bc3f4e17b436e43ad109c203aa77f40", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6616, "upload_time": "2019-10-16T06:30:17", "upload_time_iso_8601": "2019-10-16T06:30:17.866783Z", "url": "https://files.pythonhosted.org/packages/46/e9/014392870f0aa75909cb8e19ed282737625fd530b652e7d69c5dd4bf3e47/async_django_session-0.2.2-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "7022aa8522d511a6be32090cea84c799", "sha256": "81e9e22eb8050410d82f359867d16a45be9e8d308aa039eecf2910653132d4cb" }, "downloads": -1, "filename": "async_django_session-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7022aa8522d511a6be32090cea84c799", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7057, "upload_time": "2019-10-21T16:04:09", "upload_time_iso_8601": "2019-10-21T16:04:09.612268Z", "url": "https://files.pythonhosted.org/packages/0e/93/aa919b61ef96fe47e4a232317584826220cdd07fe84df6c4bb6c7a6eb9e1/async_django_session-0.3.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "315a0de92b9318b98cac3a3c8a9e1a6e", "sha256": "26c963c03a5f66eb1772c546043edf4baa3075bb5f358efec4e570d62cd071a0" }, "downloads": -1, "filename": "async_django_session-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "315a0de92b9318b98cac3a3c8a9e1a6e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7089, "upload_time": "2019-10-22T05:38:31", "upload_time_iso_8601": "2019-10-22T05:38:31.338966Z", "url": "https://files.pythonhosted.org/packages/be/27/52d62c1f9aa44071f8ee612bbf7e52ec4938e8ee09d54852bf9f8fbfd082/async_django_session-0.3.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "315a0de92b9318b98cac3a3c8a9e1a6e", "sha256": "26c963c03a5f66eb1772c546043edf4baa3075bb5f358efec4e570d62cd071a0" }, "downloads": -1, "filename": "async_django_session-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "315a0de92b9318b98cac3a3c8a9e1a6e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7089, "upload_time": "2019-10-22T05:38:31", "upload_time_iso_8601": "2019-10-22T05:38:31.338966Z", "url": "https://files.pythonhosted.org/packages/be/27/52d62c1f9aa44071f8ee612bbf7e52ec4938e8ee09d54852bf9f8fbfd082/async_django_session-0.3.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }