How to use the webargs.Arg function in webargs

To help you get started, we’ve selected a few webargs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmcarp / neurotrends / neurotrends / api / api.py View on Github external
return Q('tags', 'all', rules)


def query_article_fetched(value):
    if value:
        return Q('verified.0', 'exists', True)
    return None


article_query_args = {
    'doi': Arg(str, use=strip),
    'pmid': Arg(str, use=strip),
    'title': Arg(str, use=strip_lower),
    'journal': Arg(str, use=strip_lower),
    'authors': Arg(str, multiple=True, use=strip_lower),
    'tags': Arg(str, multiple=True, use=strip_lower),
    'fetched': utils.make_bool_arg(default=True),
}

article_query_translator = utils.QueryTranslator(
    model.Article,
    doi=utils.QueryFieldTranslator('doi'),
    pmid=utils.QueryFieldTranslator('pmid'),
    title=utils.QueryFieldTranslator('_lrecord.TI', 'contains'),
    journal=utils.QueryFieldTranslator('_lrecord.JT', 'contains'),
    authors=query_article_authors,
    tags=query_article_tags,
    fetched=query_article_fetched,
)


author_query_args = {
github theotherp / nzbhydra / nzbhydra.py View on Github external
import search
import database
import requests
requests.packages.urllib3.disable_warnings()

logger = None 
app = Flask(__name__)

api_args = {
    # Todo: Throw exception on unsupported actions
    # TODO: validate using own code, web_args' return is not very helpful. On the other side the api is only consumed by us or external tools which better know what they're doing...
    "apikey": Arg(str),
    "t": Arg(str),
    "q": Arg(str),
    "group": Arg(str),
    "limit": Arg(int),  # for now we don't limit our results
    "offset": Arg(str),  # so we dont use an offset
    "cat": Arg(str),
    "o": Arg(str),  # for now we only support xml which is what most tools ask for anyway
    "attrs": Arg(str),
    "extended": Arg(bool),  # TODO to test 
    "del": Arg(str),
    "maxage": Arg(str),
    "rid": Arg(str),
    "genre": Arg(str),
    "imbdid": Arg(str),
    "tvdbid": Arg(str),  # nzbs.org
    "season": Arg(str),
    "ep": Arg(str)

    # TODO: Support comments, music search, book search, details, etc(?)
}
github meyersj / wifi / server / app / mod_web_api / endpoints.py View on Github external
from app.models import Stream

mod_web_api = Blueprint('web_api', __name__, url_prefix='/api')


@mod_web_api.route('/')
def api_index():
    return "api root"


def round_arrival(minutes, value):
    bucket = floor(float(value) / (minutes * 60.0)) * (minutes * 60)
    return bucket

ping_args = {
    'min':Arg(float, required=False, default=None),
    'max':Arg(float, required=False, default=None),
    'mac':Arg(str, required=False, default=None),
    'unique':Arg(bool, required=False, default=False)
}


@mod_web_api.route('/pings')
@use_args(ping_args)
def ping(args):
    now = float(time.time())
    if not args["min"]: args["min"] = now - 3600
    if not args["max"]: args["max"] = now
    data = []
    meta = {}
    if args["unique"]:
        resultset = db.session.query(
github vasumv / pokemon_ai / server / server.py View on Github external
        @app.route("/api/play_game", methods=['get', 'post'])
        @use_args({
            'iterations': Arg(int, default=1),
            'username': Arg(str, required=True),
            'password': Arg(str, required=True),
            'teamfile': Arg(str, required=True),
            'teamtext': Arg(str, required=True),
            'challenge': Arg(str, default=None),
            'browser': Arg(str, default="phantomjs"),
        })
        def play_game(args):
            if args['teamtext'] != "":
                team_text = args['teamtext']
            else:
                team_text = (self.teamdir / args['teamfile']).text()
            showdown = Showdown(
                team_text,
                PessimisticMinimaxAgent(2, self.pokedata),
                args['username'],
                self.pokedata,
                browser=args['browser'],
                password=args['password'],
            )
            id = self.run_showdown(showdown, args)
github okpy / ok / server / app / api.py View on Github external
class AnalyticsAPI(APIResource):
    """
    The API resource for the AnalyticsDump Object
    """
    model = analytics.AnalyticsDump

    methods = {
        'get': {
        },
        'index': {
        },
        'post': {
            'web_args': {
                'job_type': Arg(str, required=True),
                'filters': Arg(None, use=parse_json_list_field, required=True),
            }
        },
    }

    def post(self, user, data):

        need = Need('create')

        if not self.model.can(user, need, None):
            raise need.exception()

        job_type, filters = data['job_type'], data['filters']

        if not isinstance(filters, list):
            raise BadValueError('filters must be a list of triples')
        for filter in filters:
github vasumv / pokemon_ai / server / server.py View on Github external
        @app.route("/api/play_game", methods=['get', 'post'])
        @use_args({
            'iterations': Arg(int, default=1),
            'username': Arg(str, required=True),
            'password': Arg(str, required=True),
            'teamfile': Arg(str, required=True),
            'teamtext': Arg(str, required=True),
            'challenge': Arg(str, default=None),
            'browser': Arg(str, default="phantomjs"),
        })
        def play_game(args):
            if args['teamtext'] != "":
                team_text = args['teamtext']
            else:
                team_text = (self.teamdir / args['teamfile']).text()
            showdown = Showdown(
                team_text,
                PessimisticMinimaxAgent(2, self.pokedata),
                args['username'],
github jmcarp / neurotrends / neurotrends / api / utils.py View on Github external
def make_bool_arg(**kwargs):
    return Arg(
        use=lambda x: text_bool_map.get(x.lower()),
        validate=lambda x: x is not None,
        **kwargs
    )
github okpy / ok / server / app / api.py View on Github external
'max_group_size': Arg(int, required=True),
                'due_date': DateTimeArg(required=True),
                'templates': Arg(str, use=lambda temps: json.dumps(temps),
                    required=True),
                'revision': Arg(bool),
                'lock_date': DateTimeArg(),
                'autograding_enabled': Arg(bool),
                'autograding_key': Arg(str),
                'url': Arg(str)
            }
        },
        'put': {
            'web_args': {
                'name': Arg(str),
                'display_name': Arg(str),
                'points': Arg(float),
                'course': KeyArg('Course'),
                'max_group_size': Arg(int),
                'due_date': DateTimeArg(),
                'templates': Arg(str, use=lambda temps: json.dumps(temps)),
                'revision': Arg(bool),
                'lock_date': DateTimeArg(),
                'autograding_enabled': Arg(bool),
                'autograding_key': Arg(str),
                'url': Arg(str)
            }
        },
        'get': {
        },
        'edit': {
            'methods': set(['POST']),
            'web_args': {
github okpy / ok / server / app / api.py View on Github external
class AnalyticsAPI(APIResource):
    """
    The API resource for the AnalyticsDump Object
    """
    model = analytics.AnalyticsDump

    methods = {
        'get': {
        },
        'index': {
        },
        'post': {
            'web_args': {
                'job_type': Arg(str, required=True),
                'filters': Arg(None, use=parse_json_list_field, required=True),
            }
        },
    }

    def post(self, user, data):

        need = Need('create')

        if not self.model.can(user, need, None):
            raise need.exception()

        job_type, filters = data['job_type'], data['filters']

        if not isinstance(filters, list):
            raise BadValueError('filters must be a list of triples')
github jmcarp / neurotrends / neurotrends / api / api.py View on Github external
'normalize': utils.make_bool_arg(default=False),
}

version_count_args = {
    'normalize': utils.make_bool_arg(default=False),
    'threshold': Arg(float, default=0.0),
}


place_count_args = {
    'normalize': utils.make_bool_arg(default=False),
}


extract_args = {
    'text': Arg(
        unicode,
        required=True,
        use=lambda value: value.strip()
    ),
}


# View functions

@app.route('/', methods=['GET'])
def index():
    return {
        'message': 'Welcome to the NeuroTrends API',
        '_links': collections.OrderedDict([
            ('articles', url_for('articles', _external=True)),
            ('authors', url_for('authors', _external=True)),

webargs

Declarative parsing and validation of HTTP request objects, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, Falcon, and aiohttp.

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis

Similar packages