Skip to main content

A simple Flask extension for automatically casting the type of query arguments.

Project description

This simple Flask extension allows you to cast the type of (and assign defaults to) request query parameters in Flask.

Example Usage

from flask import Flask
from flask_caster import FlaskCaster

app = Flask(__name__)

caster = FlaskCaster(app)
caster.ints = ['size']
caster.booleans = ['json']
caster.always = ['json']

This will do a few things:

  • Assure that the size query parameter is always an integer.
  • Assure that the json query parameter is always an boolean.
  • Assure that the json query parameter is always present, even if if it wasn’t provided by the end-user.

Assignable properties include ints, booleans, always, and always_default. The always_default property can be set to any value, or to a callable, which will receive one keyword argument: arg_name.

For boolean casting, 0, false, f, and null will automatically be converted to False.

Installation

$ pip install Flask-Caster

✨🍰✨

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-Caster, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size Flask_Caster-0.1.0-py2-none-any.whl (4.3 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size Flask-Caster-0.1.0.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page