Skip to content

Commit

Permalink
Merge pull request #3 from MissterHao/readme
Browse files Browse the repository at this point in the history
Add Readme and Github Action
  • Loading branch information
MissterHao authored Feb 3, 2023
2 parents 510efb7 + 32bec70 commit a7a0d9a
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 79 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload Python Package to PyPI

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release new version

on:
push:
branches:
- readme
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
python-version:
- 3.8
- 3.9
steps:
- uses: actions/checkout@v3

- name: Setup Python ${{ matrix.python-version }} Environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/coverage.txt
- name: Coverage Test
run: |
coverage run runtests.py
coverage report
- name: Set env
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "STRIP_RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
- name: Build
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
python setup.py sdist bdist_wheel
- name: Archive wheel artifacts file
uses: actions/upload-artifact@v3
with:
name: django-dysession-${{ env.RELEASE_VERSION }}-artifacts
path: |
dist/*
10 changes: 8 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
include LICENSE
include README*
recursive-include django-dysession *.py
include README.md
include MANIFEST.in
include dysession/version.txt
recursive-include django-dysession *.py
graft dysession
graft tests
global-exclude __pycache__
global-exclude *.py[co]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ coverage:

.PHONY: release
release:
python3 setup.py bdist
python setup.py sdist bdist_wheel
twine check dist/*

clean:
find . -type f -name *.pyc -delete
Expand Down
149 changes: 114 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
<div align="center">
<h1>django-dysession</h1>
<p>
django-dysessino is a django extension by using AWS DynamoDB as a session backend
</p>
<img src="https://socialify.git.ci/MissterHao/django-dysession/image?description=1&font=Source%20Code%20Pro&language=1&name=1&owner=1&pattern=Plus&stargazers=1&theme=Light" alt="django-dysession" width="640" height="320" />

<p align="center" >
<!-- First line -->
<a href="https://codecov.io/gh/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/codecov/c/gh/MissterHao/django-dysession?style=for-the-badge&token=M0U87NR9KI&logo=Codecov" alt="codecov" />
</a>
<a href="https://github.com/MissterHao/django-dysession">
<img
src="https://img.shields.io/pypi/pyversions/django-dysession?style=for-the-badge&logo=Python" alt="Supported Python version badge" >
</a>
<br>
<!-- Second line -->
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img
src="https://img.shields.io/github/issues/MissterHao/django-dysession?style=for-the-badge" alt="Github Issue badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img
src="https://img.shields.io/github/license/MissterHao/django-dysession?style=for-the-badge" alt="Lience badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img
src="https://img.shields.io/pypi/dm/django-dysession?logo=python&style=for-the-badge" alt="Downloads badge" />
</a>
<br>
</p>
<h1>django-dysession</h1>
<p>django-dysession is a django extension by using AWS DynamoDB as a session backend</p>
<img src="https://socialify.git.ci/MissterHao/django-dysession/image?description=1&font=Source%20Code%20Pro&language=1&name=1&owner=1&pattern=Plus&stargazers=1&theme=Light" alt="django-dysession" width="640" height="320" />

<p align="center" >
<!-- First line -->
<a href="https://codecov.io/gh/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/codecov/c/gh/MissterHao/django-dysession?style=for-the-badge&token=M0U87NR9KI&logo=Codecov" alt="codecov" />
</a>
<a href="https://github.com/MissterHao/django-dysession">
<img src="https://img.shields.io/pypi/pyversions/django-dysession?style=for-the-badge&logo=Python" alt="Supported Python version badge" >
</a>
<br>
<!-- Second line -->
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/github/issues/MissterHao/django-dysession?style=for-the-badge" alt="Github Issue badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/github/license/MissterHao/django-dysession?style=for-the-badge" alt="Lience badge" />
</a>
<a href="https://github.com/MissterHao/django-dysession" style="margin-right: 8px;">
<img src="https://img.shields.io/pypi/dm/django-dysession?logo=python&style=for-the-badge" alt="Downloads badge" />
</a>
<br>
</p>
</div>


## What is a django-session?
## 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**.

## Installation
+ Django >= 3.2
+ boto3 >= 1.26.59

## Example
## Installation

Install from PyPI ( or manually download from PyPI):
```bash
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.
```python
INSTALLED_APPS = [
...
Expand All @@ -51,4 +64,70 @@ INSTALLED_APPS = [
]

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.
```bash
python manage.py dysession_init
```

Then, we can enjoy it now!
```python
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

```bash
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!
```python
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 |



28 changes: 0 additions & 28 deletions dysession/management/commands/dysession_clear.py

This file was deleted.

4 changes: 2 additions & 2 deletions dysession/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def get_config() -> Dict[str, Union[str, int]]:
Dict[str, Union[str, int]]
"""
config = DEFAULT_CONFIG.copy()
custom_config = getattr(settings, "DYSESSION_CONFIG", {})
custom_config = getattr(settings, "DYSESSION", {})
config.update(custom_config)
return config


@receiver(setting_changed)
def update_dysession_config(*, setting, **kwargs):
if setting == "DYSESSION_CONFIG": # pragma: no cover
if setting == "DYSESSION": # pragma: no cover
get_config.cache_clear() # pragma: no cover


Expand Down
1 change: 1 addition & 0 deletions dysession/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
27 changes: 16 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
[metadata]
name = django-dysession
version = 0.0.1
description = django-dysession is a django extension by using AWS DynamoDB as a session backend
long_description = file:README.md
version = file: dysession/version.txt
description = "django-dysession is a django extension which integrated AWS DynamoDB as a session backend"
long_description = file: README.md
long_description_content_type = text/markdown
keywords = "django,session,aws,dynamodb"
url = https://github.com/MissterHao/django-dysession
download_url = "https://pypi.org/project/django-dysession/"
url = "https://github.com/MissterHao/django-dysession/"
download_url = "https://github.com/MissterHao/django-dysession/"
author = "Hao-Wei, Li"
author_email = "[email protected]"
maintainer = "MissterHao"
maintainer_email = "[email protected]"
license = MIT
license_files = LICENSE
classifiers =
Development Status :: 4 - Beta
Development Status :: 5 - Production/Stable
Environment :: Web Environment
Framework :: Django
Framework :: Django :: 3.2
Framework :: Django :: 4
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.6
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation
Topic :: Software Development :: Libraries :: Application Frameworks
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Internet :: WWW/HTTP :: Session
Topic :: Security
Topic :: Database

[options]
packages=find:
include_package_data = true
python_requires = >=3.6
python_requires = >=3.8
setup_requires =
setuptools >= 38.3.0
install_requires =
Django>=3.2
Django>=3.2
boto3>=1.26.59

0 comments on commit a7a0d9a

Please sign in to comment.