Package: django-dysession
django-dysessiondjango-dysession is a django extension by using AWS DynamoDB as a session backendWhat 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 add2 linesof Code!SupportTTL(Time to Live) attributeDjango'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 logRequirementsdjango-dysessionuseboto3to 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 likeDynamoDB.Django >= 3.2boto3 >= 1.26.59InstallationInstall from PyPI ( or manually download fromPyPI):pipinstall-Udjango-dysessionGetting StartedFirst of all, adddysessionintoINSTALLED_APPSin settings.py.
ChangeSESSION_ENGINEtodysession.backends.dbin 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 issessionsas default.
Run the commands bellow in cmd.pythonmanage.pydysession_initThen, we can enjoy it now!fromdjango.httpimportHttpResponsedefmainpage(request):request.session["is_admin"]=Truerequest.session["bottle_of_milks"]=20request.session["planet_have_been_to"]=["Earth","Jupiter","Saturn"]returnHttpResponse("Ayyy")Enjoy!Django Commandsdjango-dysession offer two commands for developers:dysession_destory: Destory DynamoDB Table ( Will delete whole data of the table )dysession_init: Create DyanmoDB Tablepythonmanage.py--help

Type'manage.py help <subcommand>'forhelponaspecificsubcommand.

Availablesubcommands:[dysession]dysession_destorydysession_initSettingsThis section outlines all the settings and configurations that you can put in Django's settings.py to adjustdysession's behavior.You can overwrite any value inDYSESSIONor 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",},}ArgumentDefaultDescriptionDYNAMODB_TABLENAMEsessionsDynamoDB table namePARTITION_KEY_NAMEPKPartition key nameTTL_ATTRIBUTE_NAMEttlTime to live attribute nameCACHE_PERIOD3600Define how long should be the cache live in DynamoDB's tableDYNAMODB_REGIONap-northeast-1The region of the DynamoDB tableLOGGINGDictConfiguration of LoggingLOGGING["TYPE"]CONSOLEOnly accept two kinds of parameters:CONSOLE,FILE. If this set toCONSOLE, django-dysession will useStreamHandlerto stream to the console. If this set toFILE, django-dysession will useFileHandlerto stream toLOGGING["FILE_PATH"].LOGGING["FILE_PATH"]session.logOptional. Only use this configuration when LOGGING["TYPE"] is set toFILE. The file path to save logs of session managements.LoggingDjango-Dysession support three kinds of logging.Colorful TTY-based Console LogSupport colorful and beautiful log when django-dysession interacting with AWS Dysession.Default logging streamDjango-Dysession use python core librarylogging.StreamHandlerDefault File StreamDjango-Dysession use python core librarylogging.FileHandler