Skip to main content

Idempotent Flask Endpoints

Project description

Flask-Once

Idempotent decorator for flask routes.

Inspired by stripe's idempotent endpoints.

Install

pip install flask-once

Usage

import uuid

from flask import Flask
from flask import jsonify

import flask_once
from flask_once import idempotent


app = Flask(__name__)
#: cache supports dict interface
app.cache = dict()

flask_once.attach(app, app.cache)

@app.route("/endpoint", methods=["POST"])
@idempotent()
def create_transaction():
    uuid = str(uuid.uuid4())
    return jsonify(transaction=uuid)

Test

pip install requirements-dev.txt
make test

Run example

Start app

python example.py

Curl endpoints

curl localhost:5000/endpoint \
    -H 'Idempotent-Key: x'

Upload

make tag

TODO:

  • Only cache routes with decorator.
  • Add tests endpoints not wrapped in idempotency

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

flask-once-0.0.2.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

flask_once-0.0.2-py3-none-any.whl (3.3 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