{ "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 User\n=================\n\nUsing [django][] user with async frameworks like [aiohttp][], [starlette][] etc.\n\n pip install async-django-session async-django-user\n\ntl;dr\n-----\nTake a look at registration / authorization examples for\n[aiohttp + databases][aiohttp example]\nor [starlette + asyncpg][starlette example].\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_user.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_user.asyncpg.Backend(pool, SECRET_KEY)\n ```\n\n### User\n\nTo fetch an user from db by its id stored in [django session] there's\n`backend.get_user_from_session` method:\n```python\nuser = backend.get_user_from_session(session)\n```\nIt's lazy so the user data won't be actually fetched until you call its\n`load` method. It caches the result, so it's inexpensive to call it multiple\ntimes:\n```python\nawait user.load()\n```\n\nUser provides dict interface to it's data (eg `user[\"username\"]`) and a few\nmethods:\n- `await user.authenticate(username, password)` - checks credentials and populates\n the user from database if they're valid\n- `user.login()` - sets session variables logging the user in\n- `user.logout()` - clears the session data\n- `await user.set_password(password)` - sets a new password for the user\n- `await user.save([fields])` - saves the whole user or a particular set of its\n fields\n- `await register()` - saves a new user into db\n\nFrameworks integration\n----------------------\nThere's built-in middlewares for a few async frameworks to automatically load\nuser of the current request. Take a look at [examples][] folder for:\n- [aiohttp example][] with [databases backend][]\n- [starlette example][] with [asyncpg backend][]\n\n\nRunning examples\n----------------\nRunning the [examples][] you can see different frameworks using the same session\nand user data.\n\nInstall the 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\nCreate a user:\n\n python django_app.py createsuperuser\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 [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[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-user/tree/master/examples\n[django example]: https://github.com/imbolc/async-django-user/tree/master/examples/django_app.py\n[starlette example]: https://github.com/imbolc/async-django-user/tree/master/examples/starlette_app.py\n[aiohttp example]: https://github.com/imbolc/async-django-user/tree/master/examples/aiohttp_app.py\n[asyncpg backend]: https://github.com/imbolc/async-django-user/tree/master/async-django-user/asyncpg.py\n[databases backend]: https://github.com/imbolc/async-django-user/tree/master/async-django-user/databases.py\n[aiohttp middleware]: https://github.com/imbolc/async-django-user/tree/master/async-django-user/aiohttp.py\n[starlette middleware]: https://github.com/imbolc/async-django-user/tree/master/async-django-user/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-user", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "async-django-user", "package_url": "https://pypi.org/project/async-django-user/", "platform": "", "project_url": "https://pypi.org/project/async-django-user/", "project_urls": { "Homepage": "https://github.com/imbolc/async-django-user" }, "release_url": "https://pypi.org/project/async-django-user/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Django user for async frameworks", "version": "0.2.0", "yanked": false, "yanked_reason": null }, "last_serial": 6146050, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "a2a6d7aa67167e0a88946d84c23bed22", "sha256": "caff3115aa87594efb5fa476e038afabdf52ab9973bec544e0a4561f5a4af67e" }, "downloads": -1, "filename": "async_django_user-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a2a6d7aa67167e0a88946d84c23bed22", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11407, "upload_time": "2019-10-30T08:37:30", "upload_time_iso_8601": "2019-10-30T08:37:30.361818Z", "url": "https://files.pythonhosted.org/packages/20/1e/499514a2314176868782cb2b0ebab7476b7659527315ef5aa592ef270817/async_django_user-0.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "462bd9b5ef58f33fceff520bdf42ce11", "sha256": "bd7c9b63095c1814bfb1eab85ea0a29419676746e8dad971822160e59cd752e6" }, "downloads": -1, "filename": "async_django_user-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "462bd9b5ef58f33fceff520bdf42ce11", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11404, "upload_time": "2019-10-31T05:43:09", "upload_time_iso_8601": "2019-10-31T05:43:09.897932Z", "url": "https://files.pythonhosted.org/packages/6c/2e/1aee7baf820646446921004674c1d835d24062c31ac2d37c583c94e877a0/async_django_user-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8a21bd53c68151d339bcdda9df205326", "sha256": "149f1f189883044f4f0ed66ab2406d9f5515cc939faef9b9d84420b212561b72" }, "downloads": -1, "filename": "async_django_user-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8a21bd53c68151d339bcdda9df205326", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11506, "upload_time": "2019-11-16T06:01:55", "upload_time_iso_8601": "2019-11-16T06:01:55.981243Z", "url": "https://files.pythonhosted.org/packages/b4/29/9c598e3283e9c08e87852f471d9ca39a08a79093dcb500c9ba7220f4310c/async_django_user-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a21bd53c68151d339bcdda9df205326", "sha256": "149f1f189883044f4f0ed66ab2406d9f5515cc939faef9b9d84420b212561b72" }, "downloads": -1, "filename": "async_django_user-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8a21bd53c68151d339bcdda9df205326", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11506, "upload_time": "2019-11-16T06:01:55", "upload_time_iso_8601": "2019-11-16T06:01:55.981243Z", "url": "https://files.pythonhosted.org/packages/b4/29/9c598e3283e9c08e87852f471d9ca39a08a79093dcb500c9ba7220f4310c/async_django_user-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }