Skip to main content

flask-skinny

A Flask extension that forces extremely skinny controllers.

@app.route("/dogs/<int:dog_id>", methods=["POST"])
@skinny.responses({200: responses.greet_dog, 400: responses.bad_request})
@skinny.intent(intents.greet_dog)
def greet_dog(dog_id):
    pass

Description

This extension contains two decorators, @skinny.intent and @skinny.responses.

  • @skinny.intent(callable)
    • callable: Receives flask.request, returns status_code and outcome.
  • @skinny.responses({status_code: callable, ...})
    • callable: Receives flask.request and outcome, returns headers and body.

@skinny.responses will choose an appropriate response by status_code.

Simple Usage

from flask import Flask
from flask_skinny import skinny
from random import randint
import json


def intent(request):
    if randint(0, 1) == 0:
        status_code = 200
        outcome = "OK"
    else:
        status_code = 403
        outcome = "Forbidden"
    return status_code, outcome


def response(request, outcome):
    headers = {"content-type": "application/json"}
    body = json.dumps({"message": outcome}) + "\n"
    return headers, body


app = Flask(__name__)


@app.route("/", methods=["GET"])
@skinny.responses({200: response, 403: response})
@skinny.intent(intent)
def index():
    pass

Detailed Usage

See app.py.

Installation

$ pip install flask-skinny

Contribution

Create new Pull Request.

License

MIT

Metadata

Release files for flask-skinny 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-skinny 0.1.2
File Size Uploaded
flask-skinny-0.1.2.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-skinny 0.1.2
File Interpreter ABI Platform
flask_skinny-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.1 kB

Release files / flask-skinny-0.1.2.tar.gz

Download URL flask-skinny-0.1.2.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7d0dffcadb4342c1969cdd7c91d6716204ecc4bca5c322158937d1e1fed52748
BLAKE2b-256 checksum
How to use checksums
54bc9502e931001949f8689d4f4a80755192deca65354956ab70f44952f05d0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release files / flask_skinny-0.1.2-py3-none-any.whl

Download URL flask_skinny-0.1.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47be312ecdc2bae44e05d49d3656f70869689730bc23a807d6ad4e013293bf02
BLAKE2b-256 checksum
How to use checksums
bc763fc63b35a7ba3f9514261efcce1d478ae8e5f815818776a14f6ee5015d0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page