"django-dysession is a django extension which integrated AWS DynamoDB as a session backend"
Project description
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.
DynamoDB is Fast, flexible NoSQL database service for single-digit millisecond performance at any scale.
Using DynamoDB for session storage alleviates issues that occur with session handling in a distributed web application by moving sessions off of the local file system and into a shared location. [[1]]
- Easy to use! All you need is add 2 lines of Code!
- Support TTL(Time to Live) 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.
- No more effort to maintain and autoscale your session database ( Taking advantage of AWS serverless service! )
- Provide beautiful, clearful and colorful error log
Requirements
django-dysession use boto3 to interact with AWS 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 ):
pip install -U 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.
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.
python manage.py dysession_init
Then, we can enjoy it now!
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!
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
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!
DYSESSION = {
"DYNAMODB_TABLENAME": "sessions",
"PARTITION_KEY_NAME": "PK",
"SORT_KEY_NAME": "SK",
"TTL_ATTRIBUTE_NAME": "ttl",
"CACHE_PERIOD": 3600,
"DYNAMODB_REGION": "ap-northeast-1",
"LOGGING": {
"TYPE": "CONSOLE",
},
}
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 |
LOGGING | Dict | Configuration of Logging |
LOGGING["TYPE"] | CONSOLE | Only accept two kinds of parameters: CONSOLE , FILE . If this set to CONSOLE , django-dysession will use StreamHandler to stream to the console. If this set to FILE , django-dysession will use FileHandler to stream to LOGGING["FILE_PATH"] . |
LOGGING["FILE_PATH"] | session.log | Optional. Only use this configuration when LOGGING["TYPE"] is set to FILE . The file path to save logs of session managements. |
Logging
Django-Dysession support three kinds of logging.
-
Colorful TTY-based Console Log
Support colorful and beautiful log when django-dysession interacting with AWS Dysession.
-
Default logging stream
Django-Dysession use python core library
logging.StreamHandler
-
Default File Stream
Django-Dysession use python core library
logging.FileHandler
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-dysession-1.1.1.tar.gz
.
File metadata
- Download URL: django-dysession-1.1.1.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958507ff86a9cac1977601b50aa63049a2bd492bba6891493a8ce965380bf5e5 |
|
MD5 | 2c0f4cfca948413fbfe1e3a062098f77 |
|
BLAKE2b-256 | 6ec1185d479a71ab3c4d6a1695bd72c95785693cbcc8876ead1ed782f1787133 |
File details
Details for the file django_dysession-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_dysession-1.1.1-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 581eaa4245151859821c512fd9e1955f7679bd0b70e58110d189d575180e1ee5 |
|
MD5 | 2c9f45cc8f6181c01a32d00c4245cd28 |
|
BLAKE2b-256 | 6aa8331bd025a00f590c4a666dfa3229025f20494d114b1ea4321da34804023a |