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
Metadata
Release files for django-dysession 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-dysession-1.1.1.tar.gz | 17.2 kB | Without provenance | Details for django-dysession-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_dysession-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_dysession-1.1.1-py3-none-any.whl |
Total release size: 42.2 kB
Release files / django-dysession-1.1.1.tar.gz
| Download URL | django-dysession-1.1.1.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
958507ff86a9cac1977601b50aa63049a2bd492bba6891493a8ce965380bf5e5
|
|
BLAKE2b-256 checksum How to use checksums |
6ec1185d479a71ab3c4d6a1695bd72c95785693cbcc8876ead1ed782f1787133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.12
|
Release files / django_dysession-1.1.1-py3-none-any.whl
| Download URL | django_dysession-1.1.1-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
581eaa4245151859821c512fd9e1955f7679bd0b70e58110d189d575180e1ee5
|
|
BLAKE2b-256 checksum How to use checksums |
6aa8331bd025a00f590c4a666dfa3229025f20494d114b1ea4321da34804023a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.12
|
Security for django-dysession 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.