How to use the fastapi.Query function in fastapi

To help you get started, we’ve selected a few fastapi 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 tiangolo / fastapi / tests / test_invalid_sequence_param.py View on Github external
        def read_items(q: Dict[str, Item] = Query(None)):
            pass  # pragma: no cover
github sage-org / sage-engine / sage / http_server / fastapi.py View on Github external
async def sparql_get(
        request: Request,
        query: str = Query(..., description="The SPARQL query to execute."),
        default_graph_uri: str = Query(..., alias="default-graph-uri", description="The URI of the default RDF graph queried."),
        next_link: str = Query(None, alias="next", description="(Optional) A next link used to resume query execution from a saved state.")
    ):
        """Execute a SPARQL query using the Web Preemption model"""
        try:
            mimetypes = request.headers['accept'].split(",")
            server_url = urlunparse(request.url.components[0:3] + (None, None, None))
            bindings, next_page, stats = await execute_query(query, default_graph_uri, next_link, dataset, server_url)
            return create_response(mimetypes, bindings, next_page, stats, server_url)
        except HTTPException as err:
            raise err
        except Exception as err:
            logging.error(err)
            raise HTTPException(status_code=500, detail=str(err))
github tiangolo / fastapi / docs / tutorial / src / all / tutorial015.py View on Github external
async def read_items(
    *,
    item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000),
    q: str,
    size: float = Query(..., gt=0, lt=10.5)
):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results
github seik / stilio / stilio / frontend / main.py View on Github external
async def search(
    request: Request,
    query: str = Query(None, max_length=50),
    page: int = Query(1, gt=0),
):
    if not query:
        return RedirectResponse("/")

    torrents, count = Torrent.search_by_name(
        query,
        limit=project_settings.PAGE_SIZE,
        offset=project_settings.PAGE_SIZE * (page - 1),
    )
    return templates.TemplateResponse(
        "search.html",
        {
            "request": request,
            "query": query,
            "torrents": torrents,
github tiangolo / fastapi / docs / tutorial / src / all / tutorial003.py View on Github external
async def read_items(
    q: str = Query(None, min_length=3, max_length=50, regex="^fixedquery$")
):
    results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
    if q:
        results.update({"q": q})
    return results
github QwantResearch / idunn / idunn / api / places_list.py View on Github external
async def get_places_bbox(
    bbox: str = Query(
        ...,
        title="Bounding box to search",
        description="Format: left_lon,bottom_lat,right_lon,top_lat",
        example="-4.56,48.35,-4.42,48.46",
    ),
    category: Optional[List[str]] = Query(None),
    raw_filter: Optional[List[str]] = Query(None),
    source: Optional[str] = Query(None),
    q: Optional[str] = Query(None, title="Query", description="Full text query"),
    size: Optional[int] = Query(None),
    lang: Optional[str] = Query(None),
    verbosity: Optional[str] = Query(None),
    extend_bbox: bool = Query(False),
) -> PlacesBboxResponse:
    params = PlacesQueryParam(**locals())
    source = params.source
    if source is None:
        if (
            params.q or (params.category and all(c.get("pj_filters") for c in params.category))
        ) and pj_source.bbox_is_covered(params.bbox):
            params.source = PoiSource.PAGESJAUNES
        else:
            params.source = PoiSource.OSM
github tiangolo / fastapi / docs / src / query_params_str_validations / tutorial005.py View on Github external
async def read_items(q: str = Query("fixedquery", min_length=3)):
    results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
    if q:
        results.update({"q": q})
    return results
github QwantResearch / idunn / idunn / api / directions.py View on Github external
def get_directions(
    # Query parameters
    origin: str = Query(..., description="Origin place id"),
    destination: str = Query(..., description="Destination place id"),
    type: str = Query(..., description="Transport mode"),
    language: str = Query("en", description="User language"),
    # Request
    request: Request = Depends(directions_request),
):
    rate_limiter.check_limit_per_client(request)
    try:
        from_place = place_from_id(origin)
        to_place = place_from_id(destination)
    except InvalidPlaceId as exc:
        raise HTTPException(status_code=404, detail=exc.message)

    return directions_client.get_directions(
        from_place, to_place, type, language, params=request.query_params
    )
github 3lpsy / boucanpy / boucanpy / api / routers / user / router.py View on Github external
async def show(
    user_id: int,
    user_repo: UserRepo = Depends(UserRepo()),
    token: TokenPayload = Depends(ScopedTo("user:show", "super")),
    includes: List[str] = Query(None),
):
    includes = only(includes, [], values=True)

    item = user_repo.loads(includes).get_or_fail(user_id).includes(includes).data()
    return UserResponse(user=item)
github 3lpsy / boucanpy / boucanpy / api / routers / dns_server / router.py View on Github external
async def show(
    dns_server: str,
    dns_server_repo: DnsServerRepo = Depends(DnsServerRepo()),
    token: TokenPayload = Depends(ScopedTo("dns-server:show")),
    includes: List[str] = Query(None),
):
    includes = only(includes, ["zones"], values=True)

    dns_server_id_label = dns_server_repo.label("id")

    try:
        dns_server = int(dns_server)
        label = dns_server_id_label
    except ValueError:
        label = dns_server_repo.label("name")

    # TODO: is this vulnerable to sql injection?
    item = (
        dns_server_repo.loads(includes)
        .filter(label == dns_server)
        .first_or_fail()