Skip to main content

Rigid MVC content negotiation for Flask

Project description

This is Holster, an extension for Flask that makes RESTfulness and content negotiation easy:

from flask import Flask
from flask.ext.holster.main import init_holster

app = Flask(__name__)
init_holster(app)

@app.holster("/test")
def test():
    from math import pi

    return {
        "data": "Hello from Holster!",
        "nested": {
            "numeric": 0,
            "floating": pi,
            "unicode": u"Espa\xf1ol",
        },
        "secure": {
            "xss-sword": ';!--"<XSS>=&{()}',
        }
    }

if __name__ == "__main__":
    app.run()

This application will automatically figure out which data type to return, using a combination of user agent parameters and URL extensions. If a user agent requests “/test.html” they will get HTML, but if they request “/test.json” they will get JSON instead. No longer do you have to worry about constructing sites with separate interfaces for HTML and JSON; one holstered site can do it all!

Holster currently has default renderers for the following formats:

  • HTML

  • JSON

  • Plaintext

  • YAML

Users can also override renderers for any format or MIME type they would like, with with_template:

from my_sweet_website import PNGHeaderMaker
from flask.ext.holster.views import with_template

@app.holster("/customized")
@with_template("image/png", PNGHeaderMaker)
def custom():
    return {"header": "Welcome to my site!"}

Changelog

1.1.2

  • Feature: Changelog

  • Feature: Documentation

  • Feature: Optional HOLSTER_COMPRESS setting for automatically compressing response data

  • Enhancement: Vary header is filled out

  • Change: Improved names of view objects

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-Holster-0.1.2.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file Flask-Holster-0.1.2.tar.gz.

File metadata

  • Download URL: Flask-Holster-0.1.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-Holster-0.1.2.tar.gz
Algorithm Hash digest
SHA256 02b704d971862820c20547acfc32f280cfcacfbd99a56b2e577d7e620918c9d0
MD5 51dbbd3b908e464c30855935fca64258
BLAKE2b-256 41f1784ad787c4eb194d08103bd798a00cf0a4dd89bdab531df5938775ed9f10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page