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 details)

Uploaded Source

Built Distribution

flask_once-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file flask-once-0.0.2.tar.gz.

File metadata

  • Download URL: flask-once-0.0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for flask-once-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8cef816500ac8ed0ba51efdd9ca21ef81180173f2548bcdf9b6234b329f8bcbc
MD5 c2acc4382b9bac21252b5c35e71f029e
BLAKE2b-256 4115e3b50637a593cd1c58924cedc6dc741872262f0bbc7cf3ee0c32c0d2fc13

See more details on using hashes here.

File details

Details for the file flask_once-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: flask_once-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for flask_once-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4cc3c1ed0d4ffdef311437167a2d64ad8bc5f9d082924b6eb20cb66133ddf06
MD5 dfc069c42471d8123c353b7fa55f6d54
BLAKE2b-256 1788ac48738197de3d64f83a9e270d87beb2798c47ff7150e5d54feaff985f24

See more details on using hashes here.

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