Skip to main content

auto type convertion for flask.request.form/args/values

Project description

import json

from flask import Flask, jsonify

from flask_args import args


app = Flask(__name__)
app.debug = True


@app.route('/foo', methods=['POST'])
@args('form', bar=int)
@args('args', baz=float, spam=str)
def foo(bar, baz, spam):
return jsonify({'bar': bar, 'baz': baz, 'spam': spam})


@app.route('/echo', methods=['GET', 'POST'])
@args('values', msg=str)
def echo(msg):
return msg

if __name__ == '__main__':
with app.test_client() as client:
r = client.post('/foo?baz=3.14&spam=spam', data={'bar': 2718281828})
assert json.loads(r.data) == {
'baz': 3.14, 'bar': 2718281828, 'spam': 'spam'}

r = client.get('/echo?msg=hello')
assert r.data == 'hello'

r = client.post('/echo', data={'msg': 'hello'})
assert r.data == 'hello'

Project details


Download files

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

Files for flask-args, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size flask-args-0.3.0.zip (3.1 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