当前位置: 首页>>代码示例>>Python>>正文


Python fastapi.Body方法代码示例

本文整理汇总了Python中fastapi.Body方法的典型用法代码示例。如果您正苦于以下问题:Python fastapi.Body方法的具体用法?Python fastapi.Body怎么用?Python fastapi.Body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fastapi的用法示例。


在下文中一共展示了fastapi.Body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_user_me

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def update_user_me(
    *,
    password: str = Body(None),
    full_name: str = Body(None),
    email: EmailStr = Body(None),
    current_user: UserInDB = Depends(get_current_active_user),
):
    """
    Update own user.
    """
    user_in = UserUpdate(**current_user.dict())
    if password is not None:
        user_in.password = password
    if full_name is not None:
        user_in.full_name = full_name
    if email is not None:
        user_in.email = email
    bucket = get_default_bucket()
    user = crud.user.update(bucket, username=current_user.username, user_in=user_in)
    return user 
开发者ID:tiangolo,项目名称:full-stack-fastapi-couchbase,代码行数:22,代码来源:users.py

示例2: reset_password

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def reset_password(token: str = Body(...), new_password: str = Body(...)):
    """
    Reset password.
    """
    username = verify_password_reset_token(token)
    if not username:
        raise HTTPException(status_code=400, detail="Invalid token")
    bucket = get_default_bucket()
    user = crud.user.get(bucket, username=username)
    if not user:
        raise HTTPException(
            status_code=404,
            detail="The user with this username does not exist in the system.",
        )
    elif not crud.user.is_active(user):
        raise HTTPException(status_code=400, detail="Inactive user")
    user_in = UserUpdate(name=username, password=new_password)
    user = crud.user.update(bucket, username=username, user_in=user_in)
    return {"msg": "Password updated successfully"} 
开发者ID:tiangolo,项目名称:full-stack-fastapi-couchbase,代码行数:21,代码来源:login.py

示例3: read_items

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def read_items(
    item_id: UUID,
    start_datetime: Optional[datetime] = Body(None),
    end_datetime: Optional[datetime] = Body(None),
    repeat_at: Optional[time] = Body(None),
    process_after: Optional[timedelta] = Body(None),
):
    start_process = start_datetime + process_after
    duration = end_datetime - start_process
    return {
        "item_id": item_id,
        "start_datetime": start_datetime,
        "end_datetime": end_datetime,
        "repeat_at": repeat_at,
        "process_after": process_after,
        "start_process": start_process,
        "duration": duration,
    } 
开发者ID:tiangolo,项目名称:fastapi,代码行数:20,代码来源:tutorial001.py

示例4: get_autocomplete

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def get_autocomplete(
    query: QueryParams = Depends(QueryParams), extra: ExtraParams = Body(ExtraParams())
):
    async def get_intentions():
        if not query.nlu or query.lang not in nlu_allowed_languages:
            return None

        focus = None
        if query.lon and query.lat:
            focus = Point(query.lon, query.lat)

        return await nlu_client.get_intentions(text=query.q, lang=query.lang, focus=focus)

    autocomplete_response, intentions = await asyncio.gather(
        bragi_client.autocomplete(query, extra), get_intentions()
    )
    if intentions is not None:
        autocomplete_response["intentions"] = intentions
    return autocomplete_response 
开发者ID:QwantResearch,项目名称:idunn,代码行数:21,代码来源:geocoder.py

示例5: create_new_article

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def create_new_article(
    article_create: ArticleInCreate = Body(..., embed=True, alias="article"),
    user: User = Depends(get_current_user_authorizer()),
    articles_repo: ArticlesRepository = Depends(get_repository(ArticlesRepository)),
) -> ArticleInResponse:
    slug = get_slug_for_article(article_create.title)
    if await check_article_exists(articles_repo, slug):
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=strings.ARTICLE_ALREADY_EXISTS,
        )

    article = await articles_repo.create_article(
        slug=slug,
        title=article_create.title,
        description=article_create.description,
        body=article_create.body,
        author=user,
        tags=article_create.tags,
    )
    return ArticleInResponse(article=ArticleForResponse.from_orm(article)) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:23,代码来源:articles_resource.py

示例6: tokenize

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def tokenize(self, text_input: str = Body(None, embed=True), return_ids: bool = Body(False, embed=True)):
        """
        Tokenize the provided input and eventually returns corresponding tokens id:
        - **text_input**: String to tokenize
        - **return_ids**: Boolean flags indicating if the tokens have to be converted to their integer mapping.
        """
        try:
            tokens_txt = self._pipeline.tokenizer.tokenize(text_input)

            if return_ids:
                tokens_ids = self._pipeline.tokenizer.convert_tokens_to_ids(tokens_txt)
                return ServeTokenizeResult(tokens=tokens_txt, tokens_ids=tokens_ids)
            else:
                return ServeTokenizeResult(tokens=tokens_txt)

        except Exception as e:
            raise HTTPException(status_code=500, detail={"model": "", "error": str(e)}) 
开发者ID:bhoov,项目名称:exbert,代码行数:19,代码来源:serving.py

示例7: detokenize

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def detokenize(
        self,
        tokens_ids: List[int] = Body(None, embed=True),
        skip_special_tokens: bool = Body(False, embed=True),
        cleanup_tokenization_spaces: bool = Body(True, embed=True),
    ):
        """
        Detokenize the provided tokens ids to readable text:
        - **tokens_ids**: List of tokens ids
        - **skip_special_tokens**: Flag indicating to not try to decode special tokens
        - **cleanup_tokenization_spaces**: Flag indicating to remove all leading/trailing spaces and intermediate ones.
        """
        try:
            decoded_str = self._pipeline.tokenizer.decode(tokens_ids, skip_special_tokens, cleanup_tokenization_spaces)
            return ServeDeTokenizeResult(model="", text=decoded_str)
        except Exception as e:
            raise HTTPException(status_code=500, detail={"model": "", "error": str(e)}) 
开发者ID:bhoov,项目名称:exbert,代码行数:19,代码来源:serving.py

示例8: forward

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def forward(self, inputs=Body(None, embed=True)):
        """
        **inputs**:
        **attention_mask**:
        **tokens_type_ids**:
        """

        # Check we don't have empty string
        if len(inputs) == 0:
            return ServeForwardResult(output=[], attention=[])

        try:
            # Forward through the model
            output = self._pipeline(inputs)
            return ServeForwardResult(output=output)
        except Exception as e:
            raise HTTPException(500, {"error": str(e)}) 
开发者ID:bhoov,项目名称:exbert,代码行数:19,代码来源:serving.py

示例9: update_user_me

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def update_user_me(
    *,
    db: Session = Depends(deps.get_db),
    password: str = Body(None),
    full_name: str = Body(None),
    email: EmailStr = Body(None),
    current_user: models.User = Depends(deps.get_current_active_user),
) -> Any:
    """
    Update own user.
    """
    current_user_data = jsonable_encoder(current_user)
    user_in = schemas.UserUpdate(**current_user_data)
    if password is not None:
        user_in.password = password
    if full_name is not None:
        user_in.full_name = full_name
    if email is not None:
        user_in.email = email
    user = crud.user.update(db, db_obj=current_user, obj_in=user_in)
    return user 
开发者ID:tiangolo,项目名称:full-stack-fastapi-postgresql,代码行数:23,代码来源:users.py

示例10: create_user_open

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def create_user_open(
    *,
    db: Session = Depends(deps.get_db),
    password: str = Body(...),
    email: EmailStr = Body(...),
    full_name: str = Body(None),
) -> Any:
    """
    Create new user without the need to be logged in.
    """
    if not settings.USERS_OPEN_REGISTRATION:
        raise HTTPException(
            status_code=403,
            detail="Open user registration is forbidden on this server",
        )
    user = crud.user.get_by_email(db, email=email)
    if user:
        raise HTTPException(
            status_code=400,
            detail="The user with this username already exists in the system",
        )
    user_in = schemas.UserCreate(password=password, email=email, full_name=full_name)
    user = crud.user.create(db, obj_in=user_in)
    return user 
开发者ID:tiangolo,项目名称:full-stack-fastapi-postgresql,代码行数:26,代码来源:users.py

示例11: reset_password

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def reset_password(
    token: str = Body(...),
    new_password: str = Body(...),
    db: Session = Depends(deps.get_db),
) -> Any:
    """
    Reset password
    """
    email = verify_password_reset_token(token)
    if not email:
        raise HTTPException(status_code=400, detail="Invalid token")
    user = crud.user.get_by_email(db, email=email)
    if not user:
        raise HTTPException(
            status_code=404,
            detail="The user with this username does not exist in the system.",
        )
    elif not crud.user.is_active(user):
        raise HTTPException(status_code=400, detail="Inactive user")
    hashed_password = get_password_hash(new_password)
    user.hashed_password = hashed_password
    db.add(user)
    db.commit()
    return {"msg": "Password updated successfully"} 
开发者ID:tiangolo,项目名称:full-stack-fastapi-postgresql,代码行数:26,代码来源:login.py

示例12: config_edit

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def config_edit(data: RequestConfigEdit = Body(...)) -> StatusSchema:
    """
    Change a given configuration key to a specified value.

    This endpoint is not stable and may be subject to change in the future.
    """
    db.set_plugin_configuration_key(data.plugin, data.key, data.value)
    return StatusSchema(status="ok") 
开发者ID:CERT-Polska,项目名称:mquery,代码行数:10,代码来源:app.py

示例13: create_user_open

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def create_user_open(
    *,
    username: str = Body(...),
    password: str = Body(...),
    email: EmailStr = Body(None),
    full_name: str = Body(None),
):
    """
    Create new user without the need to be logged in.
    """
    if not config.USERS_OPEN_REGISTRATION:
        raise HTTPException(
            status_code=403,
            detail="Open user resistration is forbidden on this server",
        )
    bucket = get_default_bucket()
    user = crud.user.get(bucket, username=username)
    if user:
        raise HTTPException(
            status_code=400,
            detail="The user with this username already exists in the system",
        )
    user_in = UserCreate(
        username=username, password=password, email=email, full_name=full_name
    )
    user = crud.user.upsert(bucket, user_in=user_in, persist_to=1)
    if config.EMAILS_ENABLED and user_in.email:
        send_new_account_email(
            email_to=user_in.email, username=user_in.username, password=user_in.password
        )
    return user 
开发者ID:tiangolo,项目名称:full-stack-fastapi-couchbase,代码行数:33,代码来源:users.py

示例14: compute

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def compute(a: int = Body(...), b: str = Body(...)):
    return {"a": a, "b": b} 
开发者ID:tiangolo,项目名称:fastapi,代码行数:4,代码来源:a.py

示例15: create_product

# 需要导入模块: import fastapi [as 别名]
# 或者: from fastapi import Body [as 别名]
def create_product(data: Product = Body(..., media_type=media_type, embed=True)):
    pass  # pragma: no cover 
开发者ID:tiangolo,项目名称:fastapi,代码行数:4,代码来源:test_request_body_parameters_media_type.py


注:本文中的fastapi.Body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。