{"id":349678,"date":"2023-07-03T03:00:25","date_gmt":"2023-07-03T03:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349678"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349678","title":{"rendered":"<span>Fastapi 0.100.0-beta1: \u0435\u0449\u0451 \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u0432\u044b\u0448\u043b\u0430 \u0431\u0435\u0442\u0430-\u0432\u0435\u0440\u0441\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e <a href=\"https:\/\/github.com\/tiangolo\/fastapi\/releases\" rel=\"noopener noreferrer nofollow\">FastAPI 0.100-beta1<\/a>, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f performance-\u0442\u0435\u0441\u0442\u043e\u0432!<\/p>\n<h4>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI &#8212; \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pydantic v2.0b3 &#8212; \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Rust. \u0414\u043b\u044f Pydantic \u043e\u0431\u0435\u0449\u0430\u044e\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 5-50x \u0440\u0430\u0437! \u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 FastAPI \u0432 \u0446\u0435\u043b\u043e\u043c. \u0414\u0440\u0443\u0433\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 0.100-beta1 \u0432 <a href=\"https:\/\/github.com\/tiangolo\/fastapi\/releases\" rel=\"noopener noreferrer nofollow\">release notes<\/a> \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f Pydantic \u0436\u0435<\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043d\u0434\u0430<\/h4>\n<p>\u041c\u044b, \u0432\u0435\u0431-\u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u044b, <s>\u043d\u0435<\/s>\u043b\u044e\u0431\u0438\u043c CRUD-\u0434\u044b, \u0432\u043e\u0442 \u043d\u0430 \u043d\u0435\u043c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c. \u0427\u0442\u043e\u0431\u044b \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 SQLAlchemy \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u0435\u0441\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/NewSouthMjos\/fastapi_100_test\" rel=\"noopener noreferrer nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>, \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>\u0423 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u043e\u0439\u043a\u0443 \u043f\u043e\u043b\u0435\u0439 \u0434\u0430\u0442\u044b-\u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0434\u0432\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044f, \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u044f <code>bool<\/code>, \u043d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 <code>id<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># commons\/models.py from datetime import datetime  from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from sqlalchemy.types import Text from sqlalchemy.sql import func   class Base(DeclarativeBase):     pass   class Post(Base):     __tablename__ = \"posts\"      id: Mapped[int] = mapped_column(primary_key=True)     created_at: Mapped[datetime] = mapped_column(server_default=func.now())     updated_at: Mapped[datetime] = mapped_column(onupdate=func.now())     published_at: Mapped[datetime] = mapped_column(nullable=False)     title: Mapped[str] = mapped_column(Text)     content: Mapped[str] = mapped_column(Text)     is_deleted: Mapped[bool] = mapped_column(nullable=False, default=False) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0427\u0442\u043e? \u0415\u0449\u0451 \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u043d\u043e\u0432\u044b\u0439-\u0441\u0442\u0438\u043b\u044c\u043d\u044b\u0439-\u043c\u043e\u043b\u043e\u0434\u0451\u0436\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c SQLAlchemy \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>mapping_styles<\/code> ? \u0422\u043e\u0433\u0434\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u043a <a href=\"https:\/\/docs.sqlalchemy.org\/en\/20\/orm\/mapping_styles.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0441\u043d\u043e\u0432\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 IDE\u0448\u043a\u0438 \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0438\u0441\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 Column \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 Column, \u0430 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 int, str \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 Pydantic v1 &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c Pydantic:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0441\u043c\u0435\u0445\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># commons\/schemas.py from datetime import datetime from enum import StrEnum  from pydantic import BaseModel, validator   class PostOut(BaseModel):     id: int     published_at: datetime     updated_at: datetime     title: str     content: str     is_published: bool | None = None      @validator(\"is_published\", always=True)     def compute_is_published(cls, v, values, **kwargs):         return datetime.utcnow() >= values[\"published_at\"]      class Config:         orm_mode = True   class PostsOut(BaseModel):     posts: list[PostOut]   class PostIn(BaseModel):     title: str     content: str     published_at: datetime   class Order(StrEnum):     ASC = \"asc\"     DESC = \"desc\" <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0442\u0443\u0442 &#8212; \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>is_published<\/code> &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u0442\u043e \u0435\u0441\u0442\u044c &#8212; \u043f\u0440\u0438 \u043e\u0442\u0434\u0430\u0447\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 &#8212; \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u0411\u0414, \u0434\u0440\u0443\u0433\u0430\u044f &#8212; \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u043e\u0432 \u0438\u0437 \u0411\u0414, \u0442\u0440\u0435\u0442\u044c\u044f &#8212; \u0447\u0438\u0441\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># api\/posts\/router.py from fastapi import APIRouter, Depends, Response, status, HTTPException from sqlalchemy.orm import Session  from commons.database import get_db from commons import schemas from crud import posts   router = APIRouter(tags=[\"posts\"])   @router.get(\"\/posts\") def get_posts(     per_page: int = 10,     page: int = 0,     order: schemas.Order = schemas.Order.DESC,     session: Session = Depends(get_db), ) -> schemas.PostsOut:     return schemas.PostsOut(posts=posts.get(per_page, per_page*page, order, session))   @router.get(\"\/posts_synthetic\") def posts_synthetic(     per_page: int = 10, ) -> schemas.PostsOut:     return schemas.PostsOut(         posts=[             schemas.PostOut(                 id=i,                 published_at=datetime(2023, 6, 30, 12, 0, 0),                 updated_at=datetime(2023, 6, 30, 12, 0, 0),                 title=\"\u0421\u0442\u0430\u0442\u044c\u044f\",                 content=\"\u0421\u044a\u0435\u0448\u044c \u0435\u0449\u0451 \u044d\u0442\u0438\u0445 \u043c\u044f\u0433\u043a\u0438\u0445 \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u0438\u0445 \u0431\u0443\u043b\u043e\u043a, \u0434\u0430 \u0432\u044b\u043f\u0435\u0439 \u0436\u0435 \u0447\u0430\u044e.\",             )             for i in range(per_page)         ]     )   @router.post(\"\/posts\") def create_post(     post_in: schemas.PostIn, session: Session = Depends(get_db) ) -> schemas.PostOut:     post = posts.create(post_in, session)     return post <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u043f\u043e\u043b\u043d\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u044f \u043e\u0442\u0434\u0430\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0437 SQLAlchemy \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 FastAPI.<\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0411\u0414 \u044f \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430, \u0431\u0435\u0437 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># crud\/posts.py from datetime import datetime from typing import Sequence from sqlalchemy import insert, select, update, desc, asc from sqlalchemy.orm import Session from sqlalchemy import exc from commons.schemas import PostIn, Order  from commons.models import Post   def get(limit: int, offset: int, order: Order, session: Session) -> Sequence[Post]:     q = (         select(Post)         .where(Post.is_deleted == False)         .order_by(             desc(Post.published_at) if order is Order.DESC else asc(Post.published_at)         )         .limit(limit)         .offset(offset)     )     return session.execute(q).scalars().all()   def create(post_in: PostIn, session: Session) -> Post:     q = (         insert(Post)         .values(             updated_at=datetime.utcnow(),             published_at=post_in.published_at,             title=post_in.title,             content=post_in.content,             is_deleted=False,         )         .returning(Post)     )     post = session.execute(q).scalar_one()     session.commit()     return post <\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 Pydantic 2<\/h4>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0436\u043e\u0440\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441 \u0441\u043e\u0431\u043e\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0439 \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.100.0-beta1 + Pydantic 2 \u0442\u043e\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0411\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0432 <a href=\"https:\/\/docs.pydantic.dev\/dev-v2\/migration\/\" rel=\"noopener noreferrer nofollow\">Migration Guide<\/a>, \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u0412\u043e\u0442 \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b \u0441\u044e\u0440\u043f\u0440\u0438\u0437 &#8212; \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 Pydantic 2 \u043e\u043d\u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435 \u043c\u043d\u043e\u0433\u0438\u043c <code>BaseSettings<\/code> \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>pydantic-settings<\/code>! \u0410 \u043e\u043d\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u0445 <code>typing-extensions&lt;4.0.0<\/code>, \u043a\u043e\u0433\u0434\u0430 \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0430\u043b\u0445\u0438\u043c\u0438\u0438 2.0.17 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <code>typing-extensions>=4.2.0<\/code> &#8230; \u0425\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u0432 \u043c\u043e\u0435\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c CRUD\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <code>os.getenv<\/code> \u0438 \u0437\u0430\u0431\u044b\u043b\u0438 &#8212; \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0440\u0430\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0440\u0432\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 Pydantic <code>orm_mode<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043d\u0430 <code>from_attributes<\/code>. \u041c\u0435\u043d\u044f\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>always=True \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 Pydantic \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0437\u0430\u0442\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>computed_field<\/code> &#8212; \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u0435\u0439:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">class PostOut(BaseModel):     ...      @computed_field     @property     def is_published(self) -> bool:         return datetime.utcnow() >= self.published_at <\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e.<\/p>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0432\u0438\u0448\u0435\u043d\u043a\u0435 \u043d\u0430 \u0442\u043e\u0440\u0442\u0435 &#8212; \u0441\u0430\u043c\u0438\u043c \u0442\u0435\u0441\u0442\u0430\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442 <code>test.sh<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0411\u0414, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>ab<\/code> (Apache benchmark) \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.98.0<\/p>\n<\/li>\n<li>\n<p>\u0441\u043d\u043e\u0441\u0438\u0442 \u0432\u0441\u0451 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 docker compose down -v<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.100-beta1<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 1000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 POST \/posts \u0438 1000 \u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u0445 100 \u043f\u043e\u0441\u0442\u043e\u0432 GET \/posts?per_page=100, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>c<\/code>) = 10<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u043c \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u043e\u043c bash, \u0442\u043e \u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u044f\u0432\u044b\u0439, \u0432\u0430\u043c \u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432\u0435\u0437\u0434\u0435 \u0431\u0440\u0430\u043b \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438\u0437 \u0442\u0440\u0451\u0445 \u043f\u0440\u043e\u0433\u043e\u043d\u043e\u0432, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u043c):<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">fastapi 0.98.0<\/p>\n<\/th>\n<th>\n<p align=\"left\">fastapi 0.100.0-beta1<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">READ r\/s<\/p>\n<\/td>\n<td>\n<p align=\"left\">126.90<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>371.19<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">READ r\/s syntetic<\/p>\n<\/td>\n<td>\n<p align=\"left\">172.57<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>1203.18<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">WRITE r\/s<\/p>\n<\/td>\n<td>\n<p align=\"left\">342.11<\/p>\n<\/td>\n<td>\n<p align=\"left\">352.65<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MEM USAGE BEFORE<\/p>\n<\/td>\n<td>\n<p align=\"left\">72.44MiB<\/p>\n<\/td>\n<td>\n<p align=\"left\">85.95MiB<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MEM USAGE AFTER<\/p>\n<\/td>\n<td>\n<p align=\"left\">85.95MiB<\/p>\n<\/td>\n<td>\n<p align=\"left\">98.91MiB<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0442\u0434\u0430\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0445 100 \u043f\u043e\u0441\u0442\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c \u0432 x2,92 \u0440\u0430\u0437\u0430! \u0422\u0443\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u043d\u0435 \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0410 \u0432\u043e\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0447\u0438\u0441\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u043e\u0437\u0440\u0430\u0441\u043b\u0430 \u0432 <strong>~7 \u0440\u0430\u0437<\/strong>!<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0411\u0414 &#8212; \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c, \u043d\u043e \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e \u0437\u0430 \u0432\u0441\u0451 \u043d\u0443\u0436\u043d\u043e \u043f\u043b\u0430\u0442\u0438\u0442\u044c &#8212; \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 15%.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u042f \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 FastAPI. \u0412 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 Pydantic V2 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 <a href=\"https:\/\/github.com\/pydantic\/pydantic\/issues?q=is%3Aissue+is%3Aopen+label%3A%22bug+V2%22\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u043a\u0440\u044b\u0442\u043e 7 issue<\/a>, 4 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 &#8212; \u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u0445 \u043a\u043e\u0434\u0430, \u0432 \u0446\u0435\u043b\u043e\u043c &#8212; \u043d\u0435 \u043c\u043d\u043e\u0433\u043e.<br \/> \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b &#8212; \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0444\u043e\u0440\u043a\u043d\u0443\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e welcome!<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<br \/> <a href=\"https:\/\/github.com\/NewSouthMjos\/fastapi_100_test\" rel=\"noopener noreferrer nofollow\">github.com<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745402\/\"> https:\/\/habr.com\/ru\/articles\/745402\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u0432\u044b\u0448\u043b\u0430 \u0431\u0435\u0442\u0430-\u0432\u0435\u0440\u0441\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e <a href=\"https:\/\/github.com\/tiangolo\/fastapi\/releases\" rel=\"noopener noreferrer nofollow\">FastAPI 0.100-beta1<\/a>, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f performance-\u0442\u0435\u0441\u0442\u043e\u0432!<\/p>\n<h4>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI &#8212; \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pydantic v2.0b3 &#8212; \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Rust. \u0414\u043b\u044f Pydantic \u043e\u0431\u0435\u0449\u0430\u044e\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 5-50x \u0440\u0430\u0437! \u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 FastAPI \u0432 \u0446\u0435\u043b\u043e\u043c. \u0414\u0440\u0443\u0433\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 0.100-beta1 \u0432 <a href=\"https:\/\/github.com\/tiangolo\/fastapi\/releases\" rel=\"noopener noreferrer nofollow\">release notes<\/a> \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f Pydantic \u0436\u0435<\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043d\u0434\u0430<\/h4>\n<p>\u041c\u044b, \u0432\u0435\u0431-\u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u044b, <s>\u043d\u0435<\/s>\u043b\u044e\u0431\u0438\u043c CRUD-\u0434\u044b, \u0432\u043e\u0442 \u043d\u0430 \u043d\u0435\u043c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c. \u0427\u0442\u043e\u0431\u044b \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 SQLAlchemy \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u043e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u0435\u0441\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/NewSouthMjos\/fastapi_100_test\" rel=\"noopener noreferrer nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>, \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>\u0423 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u043e\u0439\u043a\u0443 \u043f\u043e\u043b\u0435\u0439 \u0434\u0430\u0442\u044b-\u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0434\u0432\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044f, \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u044f <code>bool<\/code>, \u043d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 <code>id<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># commons\/models.py from datetime import datetime  from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from sqlalchemy.types import Text from sqlalchemy.sql import func   class Base(DeclarativeBase):     pass   class Post(Base):     __tablename__ = \"posts\"      id: Mapped[int] = mapped_column(primary_key=True)     created_at: Mapped[datetime] = mapped_column(server_default=func.now())     updated_at: Mapped[datetime] = mapped_column(onupdate=func.now())     published_at: Mapped[datetime] = mapped_column(nullable=False)     title: Mapped[str] = mapped_column(Text)     content: Mapped[str] = mapped_column(Text)     is_deleted: Mapped[bool] = mapped_column(nullable=False, default=False) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0427\u0442\u043e? \u0415\u0449\u0451 \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u043d\u043e\u0432\u044b\u0439-\u0441\u0442\u0438\u043b\u044c\u043d\u044b\u0439-\u043c\u043e\u043b\u043e\u0434\u0451\u0436\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c SQLAlchemy \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>mapping_styles<\/code> ? \u0422\u043e\u0433\u0434\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u043a <a href=\"https:\/\/docs.sqlalchemy.org\/en\/20\/orm\/mapping_styles.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0441\u043d\u043e\u0432\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 IDE\u0448\u043a\u0438 \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0438\u0441\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 Column \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 Column, \u0430 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 int, str \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 Pydantic v1 &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c Pydantic:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0441\u043c\u0435\u0445\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># commons\/schemas.py from datetime import datetime from enum import StrEnum  from pydantic import BaseModel, validator   class PostOut(BaseModel):     id: int     published_at: datetime     updated_at: datetime     title: str     content: str     is_published: bool | None = None      @validator(\"is_published\", always=True)     def compute_is_published(cls, v, values, **kwargs):         return datetime.utcnow() >= values[\"published_at\"]      class Config:         orm_mode = True   class PostsOut(BaseModel):     posts: list[PostOut]   class PostIn(BaseModel):     title: str     content: str     published_at: datetime   class Order(StrEnum):     ASC = \"asc\"     DESC = \"desc\" <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0442\u0443\u0442 &#8212; \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>is_published<\/code> &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u0442\u043e \u0435\u0441\u0442\u044c &#8212; \u043f\u0440\u0438 \u043e\u0442\u0434\u0430\u0447\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 &#8212; \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u0411\u0414, \u0434\u0440\u0443\u0433\u0430\u044f &#8212; \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u043e\u0432 \u0438\u0437 \u0411\u0414, \u0442\u0440\u0435\u0442\u044c\u044f &#8212; \u0447\u0438\u0441\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># api\/posts\/router.py from fastapi import APIRouter, Depends, Response, status, HTTPException from sqlalchemy.orm import Session  from commons.database import get_db from commons import schemas from crud import posts   router = APIRouter(tags=[\"posts\"])   @router.get(\"\/posts\") def get_posts(     per_page: int = 10,     page: int = 0,     order: schemas.Order = schemas.Order.DESC,     session: Session = Depends(get_db), ) -> schemas.PostsOut:     return schemas.PostsOut(posts=posts.get(per_page, per_page*page, order, session))   @router.get(\"\/posts_synthetic\") def posts_synthetic(     per_page: int = 10, ) -> schemas.PostsOut:     return schemas.PostsOut(         posts=[             schemas.PostOut(                 id=i,                 published_at=datetime(2023, 6, 30, 12, 0, 0),                 updated_at=datetime(2023, 6, 30, 12, 0, 0),                 title=\"\u0421\u0442\u0430\u0442\u044c\u044f\",                 content=\"\u0421\u044a\u0435\u0448\u044c \u0435\u0449\u0451 \u044d\u0442\u0438\u0445 \u043c\u044f\u0433\u043a\u0438\u0445 \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u0438\u0445 \u0431\u0443\u043b\u043e\u043a, \u0434\u0430 \u0432\u044b\u043f\u0435\u0439 \u0436\u0435 \u0447\u0430\u044e.\",             )             for i in range(per_page)         ]     )   @router.post(\"\/posts\") def create_post(     post_in: schemas.PostIn, session: Session = Depends(get_db) ) -> schemas.PostOut:     post = posts.create(post_in, session)     return post <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u043f\u043e\u043b\u043d\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u044f \u043e\u0442\u0434\u0430\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0437 SQLAlchemy \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 FastAPI.<\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0411\u0414 \u044f \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430, \u0431\u0435\u0437 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># crud\/posts.py from datetime import datetime from typing import Sequence from sqlalchemy import insert, select, update, desc, asc from sqlalchemy.orm import Session from sqlalchemy import exc from commons.schemas import PostIn, Order  from commons.models import Post   def get(limit: int, offset: int, order: Order, session: Session) -> Sequence[Post]:     q = (         select(Post)         .where(Post.is_deleted == False)         .order_by(             desc(Post.published_at) if order is Order.DESC else asc(Post.published_at)         )         .limit(limit)         .offset(offset)     )     return session.execute(q).scalars().all()   def create(post_in: PostIn, session: Session) -> Post:     q = (         insert(Post)         .values(             updated_at=datetime.utcnow(),             published_at=post_in.published_at,             title=post_in.title,             content=post_in.content,             is_deleted=False,         )         .returning(Post)     )     post = session.execute(q).scalar_one()     session.commit()     return post <\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 Pydantic 2<\/h4>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0436\u043e\u0440\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441 \u0441\u043e\u0431\u043e\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0439 \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.100.0-beta1 + Pydantic 2 \u0442\u043e\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0411\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0432 <a href=\"https:\/\/docs.pydantic.dev\/dev-v2\/migration\/\" rel=\"noopener noreferrer nofollow\">Migration Guide<\/a>, \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u0412\u043e\u0442 \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b \u0441\u044e\u0440\u043f\u0440\u0438\u0437 &#8212; \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 Pydantic 2 \u043e\u043d\u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435 \u043c\u043d\u043e\u0433\u0438\u043c <code>BaseSettings<\/code> \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>pydantic-settings<\/code>! \u0410 \u043e\u043d\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u0445 <code>typing-extensions&lt;4.0.0<\/code>, \u043a\u043e\u0433\u0434\u0430 \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0430\u043b\u0445\u0438\u043c\u0438\u0438 2.0.17 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <code>typing-extensions>=4.2.0<\/code> &#8230; \u0425\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u0432 \u043c\u043e\u0435\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c CRUD\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <code>os.getenv<\/code> \u0438 \u0437\u0430\u0431\u044b\u043b\u0438 &#8212; \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0440\u0430\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0440\u0432\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 Pydantic <code>orm_mode<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043d\u0430 <code>from_attributes<\/code>. \u041c\u0435\u043d\u044f\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>always=True \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 Pydantic \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0437\u0430\u0442\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>computed_field<\/code> &#8212; \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u0435\u0439:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">class PostOut(BaseModel):     ...      @computed_field     @property     def is_published(self) -> bool:         return datetime.utcnow() >= self.published_at <\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e.<\/p>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0432\u0438\u0448\u0435\u043d\u043a\u0435 \u043d\u0430 \u0442\u043e\u0440\u0442\u0435 &#8212; \u0441\u0430\u043c\u0438\u043c \u0442\u0435\u0441\u0442\u0430\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442 <code>test.sh<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0411\u0414, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>ab<\/code> (Apache benchmark) \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.98.0<\/p>\n<\/li>\n<li>\n<p>\u0441\u043d\u043e\u0441\u0438\u0442 \u0432\u0441\u0451 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 docker compose down -v<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 FastAPI 0.100-beta1<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 1000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 POST \/posts \u0438 1000 \u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u0445 100 \u043f\u043e\u0441\u0442\u043e\u0432 GET \/posts?per_page=100, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>c<\/code>) = 10<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u043c \u043c\u0430\u0433\u0438\u0441\u0442\u0440\u043e\u043c bash, \u0442\u043e \u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u044f\u0432\u044b\u0439, \u0432\u0430\u043c \u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432\u0435\u0437\u0434\u0435 \u0431\u0440\u0430\u043b \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438\u0437 \u0442\u0440\u0451\u0445 \u043f\u0440\u043e\u0433\u043e\u043d\u043e\u0432, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u043c):<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">fastapi 0.98.0<\/p>\n<\/th>\n<th>\n<p align=\"left\">fastapi 0.100.0-beta1<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">READ r\/s<\/p>\n<\/td>\n<td>\n<p align=\"left\">126.90<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>371.19<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">READ r\/s syntetic<\/p>\n<\/td>\n<td>\n<p align=\"left\">172.57<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>1203.18<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">WRITE r\/s<\/p>\n<\/td>\n<td>\n<p align=\"left\">342.11<\/p>\n<\/td>\n<td>\n<p align=\"left\">352.65<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MEM USAGE BEFORE<\/p>\n<\/td>\n<td>\n<p align=\"left\">72.44MiB<\/p>\n<\/td>\n<td>\n<p align=\"left\">85.95MiB<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MEM USAGE AFTER<\/p>\n<\/td>\n<td>\n<p align=\"left\">85.95MiB<\/p>\n<\/td>\n<td>\n<p align=\"left\">98.91MiB<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412\u044b\u0432\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0442\u0434\u0430\u0447\u0438 \u043f\u0435\u0440\u0432\u044b\u0445 100 \u043f\u043e\u0441\u0442\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c \u0432 x2,92 \u0440\u0430\u0437\u0430! \u0422\u0443\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u043d\u0435 \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0410 \u0432\u043e\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0447\u0438\u0441\u0442\u043e \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u043e\u0437\u0440\u0430\u0441\u043b\u0430 \u0432 <strong>~7 \u0440\u0430\u0437<\/strong>!<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0411\u0414 &#8212; \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c, \u043d\u043e \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e \u0437\u0430 \u0432\u0441\u0451 \u043d\u0443\u0436\u043d\u043e \u043f\u043b\u0430\u0442\u0438\u0442\u044c &#8212; \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 15%.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u042f \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 FastAPI. \u0412 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 Pydantic V2 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 <a href=\"https:\/\/github.com\/pydantic\/pydantic\/issues?q=is%3Aissue+is%3Aopen+label%3A%22bug+V2%22\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u043a\u0440\u044b\u0442\u043e 7 issue<\/a>, 4 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 &#8212; \u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u0445 \u043a\u043e\u0434\u0430, \u0432 \u0446\u0435\u043b\u043e\u043c &#8212; \u043d\u0435 \u043c\u043d\u043e\u0433\u043e.<br \/> \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b &#8212; \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0444\u043e\u0440\u043a\u043d\u0443\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e welcome!<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<br \/> <a href=\"https:\/\/github.com\/NewSouthMjos\/fastapi_100_test\" rel=\"noopener noreferrer nofollow\">github.com<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745402\/\"> https:\/\/habr.com\/ru\/articles\/745402\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-349678","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349678"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349678\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}