{"id":28764960,"url":"https://github.com/klen/muffin-session","last_synced_at":"2025-10-05T15:23:12.489Z","repository":{"id":29607657,"uuid":"33147975","full_name":"klen/muffin-session","owner":"klen","description":"Session for Muffin Framework","archived":false,"fork":false,"pushed_at":"2024-09-04T00:35:52.000Z","size":273,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-05-16T15:45:35.989Z","etag":null,"topics":["asyncio","muffin","sessions","trio"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ansible/ansible","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klen.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/codeowners","security":".github/security.md","support":null}},"created_at":"2015-03-30T21:02:01.000Z","updated_at":"2024-07-31T14:17:24.000Z","dependencies_parsed_at":"2022-08-17T20:15:34.168Z","dependency_job_id":null,"html_url":"https://github.com/klen/muffin-session","commit_stats":null,"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"purl":"pkg:github/klen/muffin-session","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fmuffin-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fmuffin-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fmuffin-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fmuffin-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klen","download_url":"https://codeload.github.com/klen/muffin-session/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fmuffin-session/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260336372,"owners_count":22993742,"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":["asyncio","muffin","sessions","trio"],"created_at":"2025-06-17T10:13:07.622Z","updated_at":"2025-10-05T15:23:12.476Z","avatar_url":"https://github.com/klen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Muffin-Session\n##############\n\n**Muffin-Session** — Cookie-based HTTP sessions for the Muffin_ framework.\n\n.. image:: https://github.com/klen/muffin-session/workflows/tests/badge.svg\n    :target: https://github.com/klen/muffin-session/actions\n    :alt: Test Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-session\n    :target: https://pypi.org/project/muffin-session/\n    :alt: PyPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/muffin-session\n    :target: https://pypi.org/project/muffin-session/\n    :alt: Supported Python Versions\n\n.. contents::\n   :local:\n\nOverview\n========\n\n**Muffin-Session** provides a simple and flexible way to manage secure session data via cookies.\nIt integrates seamlessly into Muffin apps with support for JWT, Fernet, and plain base64-encoded sessions.\n\nFeatures\n--------\n\n- 🍪 Cookie-based session management\n- 🔐 Supports multiple session backends:\n  - Base64 (default)\n  - **JWT**-signed sessions\n  - **Fernet**-encrypted sessions\n- 🧠 User loader \u0026 login utilities\n- 🧩 Optional auto-managed middleware integration\n\nRequirements\n============\n\n- Python ≥ 3.10\n- Muffin ≥ 1.0\n- Optional: `cryptography` for Fernet sessions\n\nInstallation\n============\n\nInstall via pip:\n\n.. code-block:: bash\n\n    pip install muffin-session\n\nInstall with Fernet encryption support:\n\n.. code-block:: bash\n\n    pip install muffin-session[fernet]\n\nUsage\n=====\n\nManual integration\n------------------\n\n.. code-block:: python\n\n    from muffin import Application, ResponseHTML\n    from muffin_session import Plugin as Session\n\n    app = Application('example')\n\n    session = Session(app, secret_key='REALLY_SECRET_KEY')\n\n    @app.route('/update')\n    async def update(request):\n        ses = session.load_from_request(request)\n        ses['var'] = 'value'\n        response = ResponseHTML('Session updated.')\n        session.save_to_response(ses, response)\n        return response\n\n    @app.route('/load')\n    async def load(request):\n        ses = session.load_from_request(request)\n        return ses.get('var')\n\n\nAuto-managed sessions\n---------------------\n\n.. code-block:: python\n\n    from muffin import Application\n    from muffin_session import Plugin as Session\n\n    app = Application('example')\n\n    session = Session()\n    session = Session(app, secret_key='REALLY_SECRET_KEY', auto_manage=True)\n\n    @app.route('/update')\n    async def update(request):\n        request.session['var'] = 'value'\n        return 'Session updated.'\n\n    @app.route('/load')\n    async def load(request):\n        return request.session.get('var')\n\nConfiguration\n=============\n\nYou can pass options via `session.setup(...)` or set them in your application config using the `SESSION_` prefix:\n\n.. code-block:: python\n\n    SESSION_SECRET_KEY = 'REALLY_SECRET_KEY'\n    SESSION_COOKIE_NAME = 'muffin_session'\n\nAvailable Options\n-----------------\n\n=========================== =========================== ========================================================\nOption                      Default                     Description\n--------------------------- --------------------------- --------------------------------------------------------\n**session_type**            ``\"jwt\"``                   Backend type: ``\"base64\"``, ``\"jwt\"``, or ``\"fernet\"``\n**secret_key**              ``\"InsecureSecret\"``        Secret used to sign or encrypt sessions\n**auto_manage**             ``False``                   If enabled, session is auto-loaded into ``request.session``\n**cookie_name**             ``\"session\"``               Name of the session cookie\n**cookie_params**           see below                   Cookie options: path, max-age, samesite, secure\n**default_user_checker**    ``lambda x: True``          Function used to verify authenticated user\n**login_url**               ``\"/login\"``                Redirect URL or callable for unauthenticated users\n=========================== =========================== ========================================================\n\nExample\n=======\n\n.. code-block:: python\n\n    from muffin import Application\n    from muffin_session import Plugin as Session\n\n    app = Application('example')\n    session = Session(app, secret_key='REALLY_SECRET_KEY', auto_manage=True)\n\n    @session.user_loader\n    async def load_user(user_id):\n        return await db.get_user_by_id(user_id)\n\n    @app.route('/session')\n    async def get_session(request):\n        return dict(request.session)\n\n    @app.route('/admin')\n    @session.user_pass(lambda user: user.is_admin)\n    async def admin(request):\n        return 'Top secret admin page.'\n\n    @app.route('/login')\n    async def login(request):\n        user = await authenticate(request)\n        session.login(request, user.id)\n        return 'Logged in.'\n\n    @app.route('/logout')\n    async def logout(request):\n        session.logout(request)\n        return 'Logged out.'\n\n    @app.route('/clear')\n    async def clear(request):\n        request.session.clear()\n        return 'Session cleared.'\n\nBug Tracker\n===========\n\nFound a bug or want to propose a feature?\nPlease use the issue tracker at: https://github.com/klen/muffin-session/issues\n\nContributing\n============\n\nWant to contribute? PRs are welcome!\nDevelopment happens at: https://github.com/klen/muffin-session\n\nLicense\n=======\n\nThis project is licensed under the MIT license. See `MIT license`_ for details.\n\nAuthor\n======\n\n- Kirill Klenov (`klen`_) — https://github.com/klen\n\n.. _klen: https://github.com/klen\n.. _Muffin: https://github.com/klen/muffin\n.. _MIT license: http://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fmuffin-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklen%2Fmuffin-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fmuffin-session/lists"}