django-dysession


Namedjango-dysession JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/MissterHao/django-dysession/releases/latest/download/django-dysession.tar.gz
Summary"django-dysession is a django extension which integrated AWS DynamoDB as a session backend"
upload_time2023-02-03 19:03:16
maintainer"MissterHao"
docs_urlNone
author"Hao-Wei, Li"
requires_python>=3.8
licenseMIT
keywords "django session aws dynamodb"
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<h1>django-dysession</h1>
<p>django-dysession is a django extension by using AWS DynamoDB as a session backend</p>
<img src="asset/banner.png" alt="django-dysession" width="640" height="320" />
<!-- <img src="https://socialify.git.ci/MissterHao/django-dysession/image?description=1&font=Source%20Code%20Pro&language=1&name=1&owner=1&pattern=Plus&stargazers=1&theme=Light" alt="django-dysession" width="640" height="320" /> -->

<p align="center" >
<!-- First line -->
<a href="https://codecov.io/gh/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/codecov/c/gh/MissterHao/django-dysession?style=for-the-badge&token=M0U87NR9KI&logo=Codecov" alt="codecov" />
</a>
<a href="https://github.com/MissterHao/django-dysession">
<img src="https://img.shields.io/pypi/pyversions/django-dysession?style=for-the-badge&logo=Python" alt="Supported Python version badge" >
</a>
<br>
<!-- Second line -->
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/github/issues/MissterHao/django-dysession?style=for-the-badge" alt="Github Issue badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/github/license/MissterHao/django-dysession?style=for-the-badge" alt="Lience badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/pypi/dm/django-dysession?logo=python&style=for-the-badge" alt="Downloads badge" />
</a>
<br>
</p>
</div>


## What is a django-dysession?

Django-dysession is a simple and easy-to-use app which allow Django developers to take DyanmoDB as Session Backend Database.

+ Easy to use! All you need is add two lines of Code!
+ Support ttl attribute
  Django's default session won't delete expired session data.
  By using DynamoDB, we can take advantage of DynamoDB's ttl attrubute to auto delete expired session data.
+ Taking advantage of AWS serverless service! ( No more effort to maintain )


## Requirements
django-dysession use `boto3` to communicate with DynamoDB.
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like **DynamoDB**.

+ Django >= 3.2
+ boto3 >= 1.26.59

## Installation

Install from PyPI ( or manually download from PyPI):
```bash
pip install django-dysession
```

## Getting Started
First of all, add `dysession` into `INSTALLED_APPS` in settings.py.
Change `SESSION_ENGINE` to `dysession.backends.db` in order use our SessionStore.
```python
INSTALLED_APPS = [
    ...
    "dysession", # add dysession to installed apps
    # 'django.contrib.sessions', # remove this default session
    ...
]

SESSION_ENGINE = "dysession.backends.db"
```

Second, we need to create a DynamoDB to store session data which's name is `sessions` as default.
Run the commands bellow in cmd.
```bash
python manage.py dysession_init
```

Then, we can enjoy it now!
```python
from django.http import HttpResponse

def mainpage(request):
    request.session["is_admin"] = True
    request.session["bottle_of_milks"] = 20
    request.session["planet_have_been_to"] = ["Earth", "Jupiter", "Saturn"]

    return HttpResponse("Ayyy")
```

Enjoy!

![](asset/dynamodb-real-demo-image.png)


## Django Commands

django-dysession offer two commands for developers:
+ dysession_destory: Destory DynamoDB Table ( Will delete whole data of the table )
+ dysession_init: Create DyanmoDB Table

```bash
python manage.py --help

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[dysession]
    dysession_destory
    dysession_init
```

## Settings

This section outlines all the settings and configurations that you can put in Django's settings.py to adjust `dysession`'s behavior.

You can overwrite any value in `DYSESSION` or just ignore it to use the default value!
```python
DYSESSION = {
    "DYNAMODB_TABLENAME": "sessions",
    "PARTITION_KEY_NAME": "PK",
    "SORT_KEY_NAME": "SK",
    "TTL_ATTRIBUTE_NAME": "ttl",
    "CACHE_PERIOD": 3600,
    "DYNAMODB_REGION": "ap-northeast-1",
}
```


| Argument           | Default        | Description                                                  |
| ------------------ | -------------- | ------------------------------------------------------------ |
| DYNAMODB_TABLENAME | sessions       | DynamoDB table name                                          |
| PARTITION_KEY_NAME | PK             | Partition key name                                           |
| TTL_ATTRIBUTE_NAME | ttl            | Time to live attribute name                                  |
| CACHE_PERIOD       | 3600           | Define how long should be the cache live in DynamoDB's table |
| DYNAMODB_REGION    | ap-northeast-1 | The region of the DynamoDB table                             |




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MissterHao/django-dysession/releases/latest/download/django-dysession.tar.gz",
    "name": "django-dysession",
    "maintainer": "\"MissterHao\"",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "\"henryliking@gmail.com\"",
    "keywords": "\"django,session,aws,dynamodb\"",
    "author": "\"Hao-Wei, Li\"",
    "author_email": "\"henryliking@gmail.com\"",
    "download_url": "https://files.pythonhosted.org/packages/4d/39/818d56b271b324882b76cc47ec36995beca66b1869186e333675503b3d59/django-dysession-1.0.3.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n<h1>django-dysession</h1>\r\n<p>django-dysession is a django extension by using AWS DynamoDB as a session backend</p>\r\n<img src=\"asset/banner.png\" alt=\"django-dysession\" width=\"640\" height=\"320\" />\r\n<!-- <img src=\"https://socialify.git.ci/MissterHao/django-dysession/image?description=1&font=Source%20Code%20Pro&language=1&name=1&owner=1&pattern=Plus&stargazers=1&theme=Light\" alt=\"django-dysession\" width=\"640\" height=\"320\" /> -->\r\n\r\n<p align=\"center\" >\r\n<!-- First line -->\r\n<a href=\"https://codecov.io/gh/MissterHao/django-dysession\" style=\"margin-right: 8px;\">\r\n<img src=\"https://img.shields.io/codecov/c/gh/MissterHao/django-dysession?style=for-the-badge&token=M0U87NR9KI&logo=Codecov\" alt=\"codecov\" />\r\n</a>\r\n<a href=\"https://github.com/MissterHao/django-dysession\">\r\n<img src=\"https://img.shields.io/pypi/pyversions/django-dysession?style=for-the-badge&logo=Python\" alt=\"Supported Python version badge\" >\r\n</a>\r\n<br>\r\n<!-- Second line -->\r\n<a href=\"https://github.com/MissterHao/django-dysession\" style=\"margin-right: 8px;\">\r\n<img src=\"https://img.shields.io/github/issues/MissterHao/django-dysession?style=for-the-badge\" alt=\"Github Issue badge\" />\r\n</a>\r\n<a href=\"https://github.com/MissterHao/django-dysession\" style=\"margin-right: 8px;\">\r\n<img src=\"https://img.shields.io/github/license/MissterHao/django-dysession?style=for-the-badge\" alt=\"Lience badge\" />\r\n</a>\r\n<a href=\"https://github.com/MissterHao/django-dysession\" style=\"margin-right: 8px;\">\r\n<img src=\"https://img.shields.io/pypi/dm/django-dysession?logo=python&style=for-the-badge\" alt=\"Downloads badge\" />\r\n</a>\r\n<br>\r\n</p>\r\n</div>\r\n\r\n\r\n## What is a django-dysession?\r\n\r\nDjango-dysession is a simple and easy-to-use app which allow Django developers to take DyanmoDB as Session Backend Database.\r\n\r\n+ Easy to use! All you need is add two lines of Code!\r\n+ Support ttl attribute\r\n  Django's default session won't delete expired session data.\r\n  By using DynamoDB, we can take advantage of DynamoDB's ttl attrubute to auto delete expired session data.\r\n+ Taking advantage of AWS serverless service! ( No more effort to maintain )\r\n\r\n\r\n## Requirements\r\ndjango-dysession use `boto3` to communicate with DynamoDB.\r\nBoto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like **DynamoDB**.\r\n\r\n+ Django >= 3.2\r\n+ boto3 >= 1.26.59\r\n\r\n## Installation\r\n\r\nInstall from PyPI ( or manually download from PyPI):\r\n```bash\r\npip install django-dysession\r\n```\r\n\r\n## Getting Started\r\nFirst of all, add `dysession` into `INSTALLED_APPS` in settings.py.\r\nChange `SESSION_ENGINE` to `dysession.backends.db` in order use our SessionStore.\r\n```python\r\nINSTALLED_APPS = [\r\n    ...\r\n    \"dysession\", # add dysession to installed apps\r\n    # 'django.contrib.sessions', # remove this default session\r\n    ...\r\n]\r\n\r\nSESSION_ENGINE = \"dysession.backends.db\"\r\n```\r\n\r\nSecond, we need to create a DynamoDB to store session data which's name is `sessions` as default.\r\nRun the commands bellow in cmd.\r\n```bash\r\npython manage.py dysession_init\r\n```\r\n\r\nThen, we can enjoy it now!\r\n```python\r\nfrom django.http import HttpResponse\r\n\r\ndef mainpage(request):\r\n    request.session[\"is_admin\"] = True\r\n    request.session[\"bottle_of_milks\"] = 20\r\n    request.session[\"planet_have_been_to\"] = [\"Earth\", \"Jupiter\", \"Saturn\"]\r\n\r\n    return HttpResponse(\"Ayyy\")\r\n```\r\n\r\nEnjoy!\r\n\r\n![](asset/dynamodb-real-demo-image.png)\r\n\r\n\r\n## Django Commands\r\n\r\ndjango-dysession offer two commands for developers:\r\n+ dysession_destory: Destory DynamoDB Table ( Will delete whole data of the table )\r\n+ dysession_init: Create DyanmoDB Table\r\n\r\n```bash\r\npython manage.py --help\r\n\r\nType 'manage.py help <subcommand>' for help on a specific subcommand.\r\n\r\nAvailable subcommands:\r\n\r\n[dysession]\r\n    dysession_destory\r\n    dysession_init\r\n```\r\n\r\n## Settings\r\n\r\nThis section outlines all the settings and configurations that you can put in Django's settings.py to adjust `dysession`'s behavior.\r\n\r\nYou can overwrite any value in `DYSESSION` or just ignore it to use the default value!\r\n```python\r\nDYSESSION = {\r\n    \"DYNAMODB_TABLENAME\": \"sessions\",\r\n    \"PARTITION_KEY_NAME\": \"PK\",\r\n    \"SORT_KEY_NAME\": \"SK\",\r\n    \"TTL_ATTRIBUTE_NAME\": \"ttl\",\r\n    \"CACHE_PERIOD\": 3600,\r\n    \"DYNAMODB_REGION\": \"ap-northeast-1\",\r\n}\r\n```\r\n\r\n\r\n| Argument           | Default        | Description                                                  |\r\n| ------------------ | -------------- | ------------------------------------------------------------ |\r\n| DYNAMODB_TABLENAME | sessions       | DynamoDB table name                                          |\r\n| PARTITION_KEY_NAME | PK             | Partition key name                                           |\r\n| TTL_ATTRIBUTE_NAME | ttl            | Time to live attribute name                                  |\r\n| CACHE_PERIOD       | 3600           | Define how long should be the cache live in DynamoDB's table |\r\n| DYNAMODB_REGION    | ap-northeast-1 | The region of the DynamoDB table                             |\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\"django-dysession is a django extension which integrated AWS DynamoDB as a session backend\"",
    "version": "1.0.3",
    "split_keywords": [
        "\"django",
        "session",
        "aws",
        "dynamodb\""
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7037a3308749ffb9758f4ab053461199e2f8ad50a5a40ebdebd2d3b0004e84f",
                "md5": "64ddf0c4a09387620a60820c59c1851f",
                "sha256": "25ead438c666e5279db821a67369c40aa6f9e7f84df83480545048ef4b437eef"
            },
            "downloads": -1,
            "filename": "django_dysession-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64ddf0c4a09387620a60820c59c1851f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 23532,
            "upload_time": "2023-02-03T19:03:14",
            "upload_time_iso_8601": "2023-02-03T19:03:14.592385Z",
            "url": "https://files.pythonhosted.org/packages/c7/03/7a3308749ffb9758f4ab053461199e2f8ad50a5a40ebdebd2d3b0004e84f/django_dysession-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d39818d56b271b324882b76cc47ec36995beca66b1869186e333675503b3d59",
                "md5": "8fc2d6ef1ca7bef38883ac54598ad39e",
                "sha256": "6fb968a1d82c7b325f9d050b065d43dc635ec36a42b0476ba41521a547b10eb1"
            },
            "downloads": -1,
            "filename": "django-dysession-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "8fc2d6ef1ca7bef38883ac54598ad39e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17010,
            "upload_time": "2023-02-03T19:03:16",
            "upload_time_iso_8601": "2023-02-03T19:03:16.458087Z",
            "url": "https://files.pythonhosted.org/packages/4d/39/818d56b271b324882b76cc47ec36995beca66b1869186e333675503b3d59/django-dysession-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-03 19:03:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "django-dysession"
}
        
Elapsed time: 0.10560s