"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.
- 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):
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.
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")
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",
}
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 |
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
Hashes for django_dysession-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409fe4f1025566a43c32b7ebdc043386905502d1879388e9c2db3ac0398245a4 |
|
MD5 | 1eaf89b267514ef2419d05728b73aca5 |
|
BLAKE2b-256 | e357f3fa384ba6711fab6eedb5521a3b791302763ba4c7f54d15a5df945a023e |