aioredis_fastapi


Nameaioredis_fastapi JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/wiseaidev/aioredis_fastapi
Summaryaioredis_fastapi is an asynchronous redis based session backend for FastAPI powered applications.
upload_time2023-12-22 17:51:25
maintainer
docs_urlNone
authorMahmoud Harmouch
requires_python>=3.9
licenseGNU General Public License v3.0
keywords python aioredis redis fastapi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ================
aioredis_fastapi
================

.. image:: https://dl.circleci.com/status-badge/img/gh/wiseaidev/aioredis_fastapi/tree/main.svg?style=svg
        :target: https://dl.circleci.com/status-badge/redirect/gh/wiseaidev/aioredis_fastapi/tree/main

.. image:: https://img.shields.io/badge/License-GPLv3-blue.svg
   :target: https://github.com/wiseaidev/aioredis_fastapi/blob/main/LICENSE
   :alt: License

.. image:: https://raw.githubusercontent.com/wiseaidev/aioredis_fastapi/main/assets/banner.jpeg
   :target: https://github.com/wiseaidev/aioredis_fastapi/
   :alt: Banner



**aioredis_fastapi** is an asynchronous `redis based session`_ backend for FastAPI powered applications.

🚸This repository is currently under testing, kind of production-ready.🚸


πŸ› οΈ Requirements
---------------

**aioredis_fastapi** requires Python 3.9 or above.

To install Python 3.9, I recommend using `pyenv`_. You can refer to `this section`_ of the readme file on how to install poetry and pyenv into your linux machine.

🚨 Installation
---------------

With :code:`pip`:

.. code-block:: console

   python3.9 -m pip install aioredis-fastapi

or by checking out the repo and installing it with `poetry`_:

.. code-block:: console

   git clone https://github.com/wiseaidev/aioredis_fastapi.git && cd aioredis_fastapi && poetry install


🚸 Usage
--------

.. code-block:: python3

   from typing import Any
   from fastapi import Depends, FastAPI, Request, Response
   from aioredis_fastapi import (
       get_session_storage,
       get_session,
       get_session_id,
       set_session,
       del_session,
       SessionStorage,
   )

   app = FastAPI(title=__name__)


   @app.post("/set-session")
   async def _set_session(
       request: Request,
       response: Response,
       session_storage: SessionStorage = Depends(get_session_storage),
   ):
       session_data = await request.json()
       await set_session(response, session_data, session_storage)


   @app.get("/get-session")
   async def _get_session(session: Any = Depends(get_session)):
       return session


   @app.post("/del-session")
   async def _delete_session(
       session_id: str = Depends(get_session_id),
       session_storage: SessionStorage = Depends(get_session_storage),
   ):
       await del_session(session_id, session_storage)
       return None


πŸ› οΈ Custom Config
----------------

.. code-block:: python3

   from aioredis_fastapi import settings
   from datetime import timedelta
   import random

   settings(
      redis_url="redis://localhost:6379",
      session_id_name="session-id",
      session_id_generator=lambda: str(random.randint(1000, 9999)),
      expire_time= timedelta(days=1)
   )


🌐 Interacting with the endpoints
---------------------------------

.. code-block:: python3

   from httpx import AsyncClient
   import asyncio
   from aioredis_fastapi.config import settings

   async def main():
       client = AsyncClient()
       r = await client.post("http://127.0.0.1:8000/set-session", json=dict(a=1, b="data", c=True))
       r = await client.get("http://127.0.0.1:8000/get-session", cookies={settings().session_id_name: "ssid"})
       print(r.text)
       return r.text

   loop = asyncio.new_event_loop()
   asyncio.set_event_loop(loop)
   try:
       loop.run_until_complete(main())
   finally:
       loop.close()
       asyncio.set_event_loop(None)


πŸŽ‰ Credits
----------

The following projects were used to build and test :code:`aioredis_fastapi`.

- `python`_
- `poetry`_
- `pytest`_
- `flake8`_
- `coverage`_
- `rstcheck`_
- `mypy`_
- `pytestcov`_
- `tox`_
- `isort`_
- `black`_
- `precommit`_


πŸ‘‹ Contribute
-------------

If you are looking for a way to contribute to the project, please refer to the `Guideline`_.


πŸ“ License
----------

This program and the accompanying materials are made available under the terms and conditions of the `GNU GENERAL PUBLIC LICENSE`_.

.. _GNU GENERAL PUBLIC LICENSE: http://www.gnu.org/licenses/
.. _redis based session: https://github.com/duyixian1234/fastapi-redis-session
.. _Guideline: https://github.com/wiseaidev/aioredis_fastapi/blob/main/CONTRIBUTING.rst
.. _this section: https://github.com/wiseaidev/frozndict#%EF%B8%8F-requirements
.. _pyenv: https://github.com/pyenv/pyenv
.. _poetry: https://github.com/python-poetry/poetry
.. _python: https://www.python.org/
.. _pytest: https://docs.pytest.org/en/7.1.x/
.. _flake8: https://flake8.pycqa.org/en/latest/
.. _coverage: https://coverage.readthedocs.io/en/6.3.2/
.. _rstcheck: https://pypi.org/project/rstcheck/
.. _mypy: https://mypy.readthedocs.io/en/stable/
.. _pytestcov: https://pytest-cov.readthedocs.io/en/latest/
.. _tox: https://tox.wiki/en/latest/
.. _isort: https://github.com/PyCQA/isort
.. _black: https://black.readthedocs.io/en/stable/
.. _precommit: https://pre-commit.com/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wiseaidev/aioredis_fastapi",
    "name": "aioredis_fastapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "python,aioredis,redis,fastapi",
    "author": "Mahmoud Harmouch",
    "author_email": "oss@wiseai.dev",
    "download_url": "https://files.pythonhosted.org/packages/34/2a/aad9ad02e1e31e1db7f1c8f3febd54fc2caf76a70108e10d1ab1f276e864/aioredis_fastapi-1.0.1.tar.gz",
    "platform": null,
    "description": "================\naioredis_fastapi\n================\n\n.. image:: https://dl.circleci.com/status-badge/img/gh/wiseaidev/aioredis_fastapi/tree/main.svg?style=svg\n        :target: https://dl.circleci.com/status-badge/redirect/gh/wiseaidev/aioredis_fastapi/tree/main\n\n.. image:: https://img.shields.io/badge/License-GPLv3-blue.svg\n   :target: https://github.com/wiseaidev/aioredis_fastapi/blob/main/LICENSE\n   :alt: License\n\n.. image:: https://raw.githubusercontent.com/wiseaidev/aioredis_fastapi/main/assets/banner.jpeg\n   :target: https://github.com/wiseaidev/aioredis_fastapi/\n   :alt: Banner\n\n\n\n**aioredis_fastapi** is an asynchronous `redis based session`_ backend for FastAPI powered applications.\n\n\ud83d\udeb8This repository is currently under testing, kind of production-ready.\ud83d\udeb8\n\n\n\ud83d\udee0\ufe0f Requirements\n---------------\n\n**aioredis_fastapi** requires Python 3.9 or above.\n\nTo install Python 3.9, I recommend using `pyenv`_. You can refer to `this section`_ of the readme file on how to install poetry and pyenv into your linux machine.\n\n\ud83d\udea8 Installation\n---------------\n\nWith :code:`pip`:\n\n.. code-block:: console\n\n   python3.9 -m pip install aioredis-fastapi\n\nor by checking out the repo and installing it with `poetry`_:\n\n.. code-block:: console\n\n   git clone https://github.com/wiseaidev/aioredis_fastapi.git && cd aioredis_fastapi && poetry install\n\n\n\ud83d\udeb8 Usage\n--------\n\n.. code-block:: python3\n\n   from typing import Any\n   from fastapi import Depends, FastAPI, Request, Response\n   from aioredis_fastapi import (\n       get_session_storage,\n       get_session,\n       get_session_id,\n       set_session,\n       del_session,\n       SessionStorage,\n   )\n\n   app = FastAPI(title=__name__)\n\n\n   @app.post(\"/set-session\")\n   async def _set_session(\n       request: Request,\n       response: Response,\n       session_storage: SessionStorage = Depends(get_session_storage),\n   ):\n       session_data = await request.json()\n       await set_session(response, session_data, session_storage)\n\n\n   @app.get(\"/get-session\")\n   async def _get_session(session: Any = Depends(get_session)):\n       return session\n\n\n   @app.post(\"/del-session\")\n   async def _delete_session(\n       session_id: str = Depends(get_session_id),\n       session_storage: SessionStorage = Depends(get_session_storage),\n   ):\n       await del_session(session_id, session_storage)\n       return None\n\n\n\ud83d\udee0\ufe0f Custom Config\n----------------\n\n.. code-block:: python3\n\n   from aioredis_fastapi import settings\n   from datetime import timedelta\n   import random\n\n   settings(\n      redis_url=\"redis://localhost:6379\",\n      session_id_name=\"session-id\",\n      session_id_generator=lambda: str(random.randint(1000, 9999)),\n      expire_time= timedelta(days=1)\n   )\n\n\n\ud83c\udf10 Interacting with the endpoints\n---------------------------------\n\n.. code-block:: python3\n\n   from httpx import AsyncClient\n   import asyncio\n   from aioredis_fastapi.config import settings\n\n   async def main():\n       client = AsyncClient()\n       r = await client.post(\"http://127.0.0.1:8000/set-session\", json=dict(a=1, b=\"data\", c=True))\n       r = await client.get(\"http://127.0.0.1:8000/get-session\", cookies={settings().session_id_name: \"ssid\"})\n       print(r.text)\n       return r.text\n\n   loop = asyncio.new_event_loop()\n   asyncio.set_event_loop(loop)\n   try:\n       loop.run_until_complete(main())\n   finally:\n       loop.close()\n       asyncio.set_event_loop(None)\n\n\n\ud83c\udf89 Credits\n----------\n\nThe following projects were used to build and test :code:`aioredis_fastapi`.\n\n- `python`_\n- `poetry`_\n- `pytest`_\n- `flake8`_\n- `coverage`_\n- `rstcheck`_\n- `mypy`_\n- `pytestcov`_\n- `tox`_\n- `isort`_\n- `black`_\n- `precommit`_\n\n\n\ud83d\udc4b Contribute\n-------------\n\nIf you are looking for a way to contribute to the project, please refer to the `Guideline`_.\n\n\n\ud83d\udcdd License\n----------\n\nThis program and the accompanying materials are made available under the terms and conditions of the `GNU GENERAL PUBLIC LICENSE`_.\n\n.. _GNU GENERAL PUBLIC LICENSE: http://www.gnu.org/licenses/\n.. _redis based session: https://github.com/duyixian1234/fastapi-redis-session\n.. _Guideline: https://github.com/wiseaidev/aioredis_fastapi/blob/main/CONTRIBUTING.rst\n.. _this section: https://github.com/wiseaidev/frozndict#%EF%B8%8F-requirements\n.. _pyenv: https://github.com/pyenv/pyenv\n.. _poetry: https://github.com/python-poetry/poetry\n.. _python: https://www.python.org/\n.. _pytest: https://docs.pytest.org/en/7.1.x/\n.. _flake8: https://flake8.pycqa.org/en/latest/\n.. _coverage: https://coverage.readthedocs.io/en/6.3.2/\n.. _rstcheck: https://pypi.org/project/rstcheck/\n.. _mypy: https://mypy.readthedocs.io/en/stable/\n.. _pytestcov: https://pytest-cov.readthedocs.io/en/latest/\n.. _tox: https://tox.wiki/en/latest/\n.. _isort: https://github.com/PyCQA/isort\n.. _black: https://black.readthedocs.io/en/stable/\n.. _precommit: https://pre-commit.com/\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "aioredis_fastapi is an asynchronous redis based session backend for FastAPI powered applications.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/wiseaidev/aioredis_fastapi",
        "Repository": "https://github.com/wiseaidev/aioredis_fastapi"
    },
    "split_keywords": [
        "python",
        "aioredis",
        "redis",
        "fastapi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9552370b98b60cdc533983fdf1dd05a9b20eb038db13766a57743cc283acb51d",
                "md5": "ff56d5f2ba1a34a54acc643fad9dfefc",
                "sha256": "0267bc67a0a86d0ba7919c12593cf19530e5d7429cb5292b36e3c0b4c2d28fa6"
            },
            "downloads": -1,
            "filename": "aioredis_fastapi-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ff56d5f2ba1a34a54acc643fad9dfefc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 32669,
            "upload_time": "2023-12-22T17:51:23",
            "upload_time_iso_8601": "2023-12-22T17:51:23.991646Z",
            "url": "https://files.pythonhosted.org/packages/95/52/370b98b60cdc533983fdf1dd05a9b20eb038db13766a57743cc283acb51d/aioredis_fastapi-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "342aaad9ad02e1e31e1db7f1c8f3febd54fc2caf76a70108e10d1ab1f276e864",
                "md5": "ce9031911a8b4d23eae911a6941dd568",
                "sha256": "4bf005394ea386fa0ac21029142cf126da93cf9b07585e880a0e1ca89a3b774a"
            },
            "downloads": -1,
            "filename": "aioredis_fastapi-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ce9031911a8b4d23eae911a6941dd568",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 16854,
            "upload_time": "2023-12-22T17:51:25",
            "upload_time_iso_8601": "2023-12-22T17:51:25.931249Z",
            "url": "https://files.pythonhosted.org/packages/34/2a/aad9ad02e1e31e1db7f1c8f3febd54fc2caf76a70108e10d1ab1f276e864/aioredis_fastapi-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-22 17:51:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wiseaidev",
    "github_project": "aioredis_fastapi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "tox": true,
    "lcname": "aioredis_fastapi"
}
        
Elapsed time: 0.16065s