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.

Source Distribution

flask-args-0.3.0.zip (3.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page