Skip to main content

"django-dysession is a django extension which integrated AWS DynamoDB as a session backend"

Project description


django-dysession is a django extension by using AWS DynamoDB as a session backend


codecov Supported Python version badge
Github Issue badge Lience badge Downloads badge

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


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


Install from PyPI ( or manually download from PyPI ):

pip install -U django-dysession

Getting Started

First of all, add dysession into INSTALLED_APPS in Change SESSION_ENGINE to dysession.backends.db in order use our SessionStore.

    "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 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 --help

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

Available subcommands:



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

You can overwrite any value in DYSESSION or just ignore it to use the default value!

    "DYNAMODB_TABLENAME": "sessions",
    "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.


Django-Dysession support three kinds of logging.

  1. Colorful TTY-based Console Log

    Support colorful and beautiful log when django-dysession interacting with AWS Dysession.

  2. Default logging stream

    Django-Dysession use python core library logging.StreamHandler

  3. 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

django-dysession-1.1.1.tar.gz (17.2 kB view hashes)

Uploaded Source

Built Distribution

django_dysession-1.1.1-py3-none-any.whl (25.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page