Skip to content

bl4ckst0ne/flask-pynamodb

Repository files navigation

Flask-PynamoDB

codecov Code style: black PyPI Python

Flask-PynamoDB is an externsion for Flask that integrates with DynamoDB using the powerful PynamoDB library.

Flask-PynamoDB simplfies the configuration of PynamoDB for your application, as well as adds utilities for better integration with PynamoDB.

Installation

You can install & update the library using pip:

python -m pip install -U Flask-PynamoDB

or:

pip install -U Flask-PynamoDB

Quickstart

from uuid import uuid4
from typing import List

from flask import Flask, render_template
from flask_pynamodb import PynamoDB
from pynamodb.attributes import BooleanAttribute, UnicodeAttribute


class Config:
    DYNAMODB_HOST = "http://localhost:8000"
    DYNAMODB_AWS_ACCESS_KEY_ID = "test"
    DYNAMODB_AWS_SECRET_ACCESS_KEY = "test"
    DYNAMODB_READ_CAPACITY_UNITS = 10
    DYNAMODB_WRITE_CAPACITY_UNITS = 10


app = Flask(__name__)
app.config.from_object(Config)
db = PynamoDB(app)


class Todo(db.Model):
    class Meta:
        table_name = "todo"

    id = UnicodeAttribute(hash_key=True)
    name = UnicodeAttribute()
    description = UnicodeAttribute()
    done = BooleanAttribute(default=False)


@app.route("/")
def index() -> List[str]:
    return [todo.name for i in Todo.scan()]

About

Flask extension for DynamoDB using PynamoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages