12👍
As written by others, Django does not have NoSQL DBMS support, but there are third-party packages.
PynamoDB seems fine, but I have never used it, so I can’t recommend it. In all use cases I came across, boto3 was sufficient. Setup is pretty simple, but the devil is in details (in the data structure and how nested it is, to be precise). Basically, three steps are needed:
- Connect with the DB and perform the operation you want (boto3)
- Parse incoming data into a Python dictionary (e.g. with dynamodb-json, boto3.dynamodb.types.TypeDeserializer or you can build your own)
- Do business logic, store data into relational DB using the Django ORM or whatever you need
Simplest example:
from dynamodb_json import json_util as dynamodb_json
from .models import YourModel
def get(request, partition_key):
table = boto3.resource(
'dynamodb',
aws_access_key_id=...,
aws_secret_access_key=...,
region_name=...,
).Table(some_table_name)
try:
response = table.get_item(
Key={partition_key: partition_key})
except ClientError as e:
logger.warning(e.response['Error']['Message'])
else:
data_str = response['Item']
_data_dict = dynamodb_json.loads(data_str)
# Validation and modification of incoming data goes here.
data_dict = validation_and_modification(_data_dict)
# Then you can do whatever you need, for example:
obj, created = YourModel.objects.update_or_create(**data_dict)
...
Examples for create, delete, list and update views can be found in the serverless repo.
4👍
It’s not like ready made battery for django, but worth looking at it regardless.
https://github.com/pynamodb/PynamoDB
- Django unable to find MySQLdb python module
- Have a url that accepts all characters
- Why "class Meta" is necessary while creating a model form?
1👍
DynamoDB is non-relational which I think makes it architecturally incompatible with an ORM like Django’s.
- Django form with fields from two different models
- Does anyone know about workflow frameworks/libraries in Python?
- How to emit SocketIO event on the serverside
0👍
There is no Django model interface for AWS DynamoDB, but you may retrieve data from that kind of db using boto3 software provided by AWS.
- Can Django run on Gunicorn alone (no Apache or nginx)?
- How to use ModelMultipleChoiceFilter?
- Django static files on heroku
- Why use Django's collectstatic instead of just serving the files directly from your static directory?