How can I use webargs or reqparse from flask_restful to pass a numpy array while making a POST call. I am able to pass arguments of other data types (string, int) with ease but numpy arrays get translated to unicode or throws an error.
I want to able to do something like:
from flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument('url', type=str)
parser.add_argument('id', type=str, required=True)
# Pass in numpy array
parser.add_argument('arr', type=numpy.array, required=True)
I also tried with webargs but haven't found a way to make it compatible with numpy arrays. I have this set up:
from webargs import fields
from webargs.flaskparser import use_args
my_args = {'url': fields.Str(),
'id': fields.Str(required=True),
'arr': fields.Field()} # not sure what to put here
Is there a way to efficiently pass in a numpy array using a flask restful API?
Edit:
I've tried setting data type as List but get a new error indicating u"'List' object is not callable".
I've changed:
# pass in numpy array
parser.add_argument('arr', type=fields.List(fields.Raw()))