{"id":350407,"date":"2023-07-18T09:03:19","date_gmt":"2023-07-18T09:03:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=350407"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=350407","title":{"rendered":"<span>\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043b\u044e\u0431\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432 FastAPI. \u041d\u0430 \u043f\u0440\u0438\u0446\u0435\u043b\u0435 Flask<\/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>\u042f \u0443\u0432\u0435\u0440\u0435\u043d, \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <strong>FastAPI<\/strong>. \u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u043f\u0440\u043e\u0441\u043e\u0432 <strong>Stackoverflow<\/strong> \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u043e\u043f \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u043e\u0432, \u043d\u043e \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u0446\u0435\u043b\u043e\u043c. \u0418 \u043d\u0435 \u0437\u0440\u044f: \u0437\u0430 \u0441\u0447\u0435\u0442 \u0441\u0432\u0435\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0438\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>\u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d <strong>FastAPI<\/strong> <a href=\"https:\/\/habr.com\/ru\/articles\/708678\" rel=\"noopener noreferrer nofollow\">\u0438\u0437\u043d\u0443\u0442\u0440\u0438<\/a>. \u0422\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u044b \u0434\u0435\u0442\u0430\u043b\u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 <strong>Starlette<\/strong>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <strong>pydantic<\/strong>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u043e\u0439 <strong>Python<\/strong> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432 \u0438\u0434\u0435\u0439\u043d\u043e\u0435 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 <strong>FastAPI<\/strong>. \u041f\u0440\u0438\u0447\u0435\u043c \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431 <em>HTTP<\/em> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445. \u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u0432\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <em>CLI<\/em>, \u0438\u043b\u0438 <em>telegram<\/em>-\u0431\u043e\u0442\u043e\u0432, \u0438\u043b\u0438 \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432\u0430\u0448\u0430 \u0434\u0443\u0448\u0430 \u043f\u043e\u0436\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<h3>\u0427\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c?<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u043e\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u043e\u0434 <em>\u043f\u043e\u0434\u043e\u0431\u0438\u0435\u043c FastAPI<\/em>. \u042f \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0441\u044e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>pydantic<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c <strong>FastAPI<\/strong>, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e <strong>OpenAPI<\/strong> \u0441\u0445\u0435\u043c\u044b (\u0445\u043e\u0442\u044f \u0438 \u0441\u0430\u043c <a class=\"mention\" href=\"\/users\/tiangolo\">@tiangolo<\/a> \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u044d\u0442\u0443 \u0438\u0434\u0435\u044e \u0443 <strong>Django Rest Framework<\/strong>). \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430 \u0444\u0438\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 <em>\u043b\u044e\u0431\u043e\u043c\u0443<\/em> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0443. \u041d\u0435 \u0432\u0441\u0435 \u0436\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 <em>HTTP<\/em>.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 <strong>FastAPI<\/strong> &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0431\u0430\u0442\u0430\u0440\u0435\u0435\u043a \u0438 \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u043d\u0430\u0434 <strong>Starlette<\/strong>. \u0422\u0430\u043a \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0434\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <strong>FastAPI<\/strong>.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441 \u044d\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c.<\/p>\n<h3>\u041a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u043e?<\/h3>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435, \u0443\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u044d\u0442\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0438 \u0434\u0430\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0437\u044f\u0442\u044b\u0439 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 <strong>FastAPI<\/strong>.<\/p>\n<p>\u0418\u0434\u0435\u044f \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0434\u0432\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">def func(     user_id: int,     username: str, ):     pass <\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code class=\"python\">from pydantic import BaseModel  class FuncArguments(BaseModel):     user_id: int     username: str <\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0435\u0442\u0435 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430? \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, <a class=\"mention\" href=\"\/users\/tiangolo\">@tiangolo<\/a> \u0437\u0430\u043c\u0435\u0442\u0438\u043b. \u0418 \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u0435\u0449\u044c: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0441\u0442\u0440\u043e\u0438\u0442 <strong>pydantic<\/strong> \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0435\u0435 \u043e\u0441\u043d\u043e\u0432\u0435.<\/p>\n<p>\u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0433\u0438\u0438 \u0432 \u0441\u0442\u0438\u043b\u0435<\/p>\n<pre><code class=\"python\">func(**FuncArguments(user_id=1, username=\"john\").dict()) <\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0443\u0436\u0435 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from functools import wraps  def validate(func):     pydantic_args_model = build_pydantic_model(func)      @wraps(func)     def validate_wrapper(*args, **kwargs):         arguments = merge_args_and_kwargs(args, kwargs)         validated_args = pydantic_args_model(**arguments).dict()         return func(**validated_args)          return validate_wrapper <\/code><\/pre>\n<p>\u041f\u043b\u044e\u0441\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430 \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f <strong>pydantic<\/strong> \u043c\u043e\u0434\u0435\u043b\u0438 (\u0447\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <strong>Rust<\/strong>) \u0438 \u0432\u044b\u0437\u043e\u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u041e\u0432\u0435\u0440\u0445\u0435\u0434 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0435\u043d.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><code>build_pydantic_model<\/code><\/p>\n<\/li>\n<li>\n<p><code>merge_args_and_kwargs<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0435\u0442\u0430\u043b\u0438 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0442\u0430\u043c \u043d\u0435\u0442 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439). \u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 <a href=\"https:\/\/github.com\/Lancetnik\/FastDepends\/blob\/main\/fast_depends\/core\/build.py\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438<\/a>.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/Lancetnik\/FastDepends\" rel=\"noopener noreferrer nofollow\">FastDepends<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432 <strong>FastAPI<\/strong>.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0438 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong><\/p>\n<\/li>\n<li>\n<p><em>Depends<\/em>, \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0435 <s>\u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c<\/s> <em>fastapi.Depends<\/em><\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f &#8212; \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u0430\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e, \u0442\u0430\u043a \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<h3>Flask + FastDepends<\/h3>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u043c \u0434\u0430\u0435\u0442.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <strong>Flask<\/strong> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0443\u0434\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>inject<\/code> \u0438\u0437 <strong>FastDepends<\/strong>.<\/p>\n<pre><code class=\"python\">from flask import Flask from fast_depends import inject, Depends from pydantic import Field, PositiveInt  app = Flask(__name__)  def get_user(user_id: PositiveInt = Field(..., alias=\"id\")):     return f\"user-{user_id}\"  @app.get(\"\/&lt;id>\") @inject def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<p>\u041e\u043d\u043e \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442! \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 handler \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <code>id<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u043e \u043d\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>Depends<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u044c \u0441\u0430\u043c\u043e\u0439 \u0440\u0443\u0447\u043a\u0438.<\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h4>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 <strong>Flask<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <strong>500<\/strong>-\u043a\u0438 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442.\u043a. \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <code>pydantic.ValidationError<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u043d\u0430\u0443\u0447\u0438\u043c?<\/p>\n<pre><code class=\"python\">from functools import wraps from pydantic import ValidationError  ...  def catch_validation_error(handler):     @wraps(handler)     def catch_wrapper(*args, **kwargs):         try:             return handler(*args, **kwargs)         except ValidationError as e:             # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c BadRequest \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438             return e.json(), 400       return catch_wrapper  @app.get(\"\/&lt;id>\") @catch_validation_error @inject def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<h4>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0435\u0448\u043a\u0443<\/h4>\n<p>\u0422\u0430\u043a\u0430\u044f \u043a\u0443\u0447\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0443\u043e\u0437\u043d\u043e\u0439? \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0445 \u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">from flask import Flask from flask.scaffold import setupmethod  class FastFlask(Flask):     @setupmethod     def route(self, rule: str, **options):         def decorator(f):             f = catch_validation_error(inject(f))  # \u043f\u0440\u044f\u0447\u0435\u043c \u0432\u0441\u0435 \u0441\u044e\u0434\u0430             endpoint = options.pop(\"endpoint\", None)             self.add_url_rule(rule, endpoint, f, **options)             return f         return decorator  app = FastFlask(__name__)  ...  @app.get(\"\/&lt;id>\") def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435!<\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0438\u0434\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/h4>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0448 <strong>FastFlask<\/strong> \u0443\u043c\u0435\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0443\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 <code>POST - JSON<\/code> \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 <strong>FastDepends<\/strong> \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043c\u0435\u0442\u043e\u0434 <code>use<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c, \u0443\u0431\u0438\u0440\u0430\u0442\u044c, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0432 \u0432\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"python\">from flask import request from fast_depends.library import CustomField  class Body(CustomField):     def use(self, **kwargs):         return {             **super().use(**kwargs),             self.param_name: (request.json or {}).get(self.param_name)         }  ...  @app.post(\"\/\") def hello(user_id: PositiveInt = Body()):     # \u043e\u0436\u0438\u0434\u0430\u0435\u0442 JSON \u0432\u0438\u0434\u0430 { \"user_id\": 1 }     return { \"Hi!\": user_id } <\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>Flask<\/strong> \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0443\u043c\u0435\u043b \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong>, \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u043b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 <strong>Depends<\/strong>.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <strong>FastAPI<\/strong>, \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435?<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0441 <strong>\u043b\u044e\u0431\u044b\u043c<\/strong> <em>HTTP<\/em> (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) Python \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/gist.github.com\/Lancetnik\/0d33f098e6b342ac71e7606f1059db70\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<h3>\u0417\u0430\u0447\u0435\u043c?<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 &#8212; \u0434\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 <strong>OSS<\/strong> \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u043e\u0438\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <em>event-driven<\/em> \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 <a href=\"https:\/\/lancetnik.github.io\/Propan\" rel=\"noopener noreferrer nofollow\"><strong>Propan<\/strong><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 <strong>FastDepends<\/strong> \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a \u043e\u043f\u044b\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u0432\u0430\u043c <strong>FastAPI<\/strong>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u043e \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0438 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0433\u043b\u0430\u0434\u0438\u0442\u044c \u0432\u0430\u0448\u0438 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u043b\u0435\u0433\u0430\u0441\u0438.<\/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\/748618\/\"> https:\/\/habr.com\/ru\/articles\/748618\/<\/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>\u042f \u0443\u0432\u0435\u0440\u0435\u043d, \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <strong>FastAPI<\/strong>. \u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u043f\u0440\u043e\u0441\u043e\u0432 <strong>Stackoverflow<\/strong> \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u043e\u043f \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u043e\u0432, \u043d\u043e \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u0446\u0435\u043b\u043e\u043c. \u0418 \u043d\u0435 \u0437\u0440\u044f: \u0437\u0430 \u0441\u0447\u0435\u0442 \u0441\u0432\u0435\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0438\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>\u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d <strong>FastAPI<\/strong> <a href=\"https:\/\/habr.com\/ru\/articles\/708678\" rel=\"noopener noreferrer nofollow\">\u0438\u0437\u043d\u0443\u0442\u0440\u0438<\/a>. \u0422\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u044b \u0434\u0435\u0442\u0430\u043b\u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 <strong>Starlette<\/strong>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <strong>pydantic<\/strong>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u043e\u0439 <strong>Python<\/strong> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432 \u0438\u0434\u0435\u0439\u043d\u043e\u0435 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 <strong>FastAPI<\/strong>. \u041f\u0440\u0438\u0447\u0435\u043c \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431 <em>HTTP<\/em> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445. \u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u0432\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <em>CLI<\/em>, \u0438\u043b\u0438 <em>telegram<\/em>-\u0431\u043e\u0442\u043e\u0432, \u0438\u043b\u0438 \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0432\u0430\u0448\u0430 \u0434\u0443\u0448\u0430 \u043f\u043e\u0436\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<h3>\u0427\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c?<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u043e\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u043e\u0434 <em>\u043f\u043e\u0434\u043e\u0431\u0438\u0435\u043c FastAPI<\/em>. \u042f \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0441\u044e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>pydantic<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c <strong>FastAPI<\/strong>, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e <strong>OpenAPI<\/strong> \u0441\u0445\u0435\u043c\u044b (\u0445\u043e\u0442\u044f \u0438 \u0441\u0430\u043c <a class=\"mention\" href=\"\/users\/tiangolo\">@tiangolo<\/a> \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u044d\u0442\u0443 \u0438\u0434\u0435\u044e \u0443 <strong>Django Rest Framework<\/strong>). \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430 \u0444\u0438\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 <em>\u043b\u044e\u0431\u043e\u043c\u0443<\/em> \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0443. \u041d\u0435 \u0432\u0441\u0435 \u0436\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 <em>HTTP<\/em>.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 <strong>FastAPI<\/strong> &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0431\u0430\u0442\u0430\u0440\u0435\u0435\u043a \u0438 \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u043d\u0430\u0434 <strong>Starlette<\/strong>. \u0422\u0430\u043a \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0434\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <strong>FastAPI<\/strong>.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441 \u044d\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c.<\/p>\n<h3>\u041a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u043e?<\/h3>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435, \u0443\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u044d\u0442\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0438 \u0434\u0430\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0437\u044f\u0442\u044b\u0439 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 <strong>FastAPI<\/strong>.<\/p>\n<p>\u0418\u0434\u0435\u044f \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0434\u0432\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">def func(     user_id: int,     username: str, ):     pass <\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code class=\"python\">from pydantic import BaseModel  class FuncArguments(BaseModel):     user_id: int     username: str <\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0435\u0442\u0435 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430? \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, <a class=\"mention\" href=\"\/users\/tiangolo\">@tiangolo<\/a> \u0437\u0430\u043c\u0435\u0442\u0438\u043b. \u0418 \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u0435\u0449\u044c: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0441\u0442\u0440\u043e\u0438\u0442 <strong>pydantic<\/strong> \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0435\u0435 \u043e\u0441\u043d\u043e\u0432\u0435.<\/p>\n<p>\u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0433\u0438\u0438 \u0432 \u0441\u0442\u0438\u043b\u0435<\/p>\n<pre><code class=\"python\">func(**FuncArguments(user_id=1, username=\"john\").dict()) <\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0443\u0436\u0435 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from functools import wraps  def validate(func):     pydantic_args_model = build_pydantic_model(func)      @wraps(func)     def validate_wrapper(*args, **kwargs):         arguments = merge_args_and_kwargs(args, kwargs)         validated_args = pydantic_args_model(**arguments).dict()         return func(**validated_args)          return validate_wrapper <\/code><\/pre>\n<p>\u041f\u043b\u044e\u0441\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430 \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f <strong>pydantic<\/strong> \u043c\u043e\u0434\u0435\u043b\u0438 (\u0447\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <strong>Rust<\/strong>) \u0438 \u0432\u044b\u0437\u043e\u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u041e\u0432\u0435\u0440\u0445\u0435\u0434 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0435\u043d.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><code>build_pydantic_model<\/code><\/p>\n<\/li>\n<li>\n<p><code>merge_args_and_kwargs<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0435\u0442\u0430\u043b\u0438 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0442\u0430\u043c \u043d\u0435\u0442 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439). \u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 <a href=\"https:\/\/github.com\/Lancetnik\/FastDepends\/blob\/main\/fast_depends\/core\/build.py\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438<\/a>.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/Lancetnik\/FastDepends\" rel=\"noopener noreferrer nofollow\">FastDepends<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432 <strong>FastAPI<\/strong>.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0438 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong><\/p>\n<\/li>\n<li>\n<p><em>Depends<\/em>, \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0435 <s>\u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c<\/s> <em>fastapi.Depends<\/em><\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f &#8212; \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u0430\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e, \u0442\u0430\u043a \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<h3>Flask + FastDepends<\/h3>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u043c \u0434\u0430\u0435\u0442.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <strong>Flask<\/strong> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0443\u0434\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>inject<\/code> \u0438\u0437 <strong>FastDepends<\/strong>.<\/p>\n<pre><code class=\"python\">from flask import Flask from fast_depends import inject, Depends from pydantic import Field, PositiveInt  app = Flask(__name__)  def get_user(user_id: PositiveInt = Field(..., alias=\"id\")):     return f\"user-{user_id}\"  @app.get(\"\/&lt;id>\") @inject def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<p>\u041e\u043d\u043e \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442! \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 handler \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <code>id<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u043e \u043d\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>Depends<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u044c \u0441\u0430\u043c\u043e\u0439 \u0440\u0443\u0447\u043a\u0438.<\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h4>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 <strong>Flask<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <strong>500<\/strong>-\u043a\u0438 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442.\u043a. \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <code>pydantic.ValidationError<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u043d\u0430\u0443\u0447\u0438\u043c?<\/p>\n<pre><code class=\"python\">from functools import wraps from pydantic import ValidationError  ...  def catch_validation_error(handler):     @wraps(handler)     def catch_wrapper(*args, **kwargs):         try:             return handler(*args, **kwargs)         except ValidationError as e:             # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c BadRequest \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438             return e.json(), 400       return catch_wrapper  @app.get(\"\/&lt;id>\") @catch_validation_error @inject def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<h4>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0435\u0448\u043a\u0443<\/h4>\n<p>\u0422\u0430\u043a\u0430\u044f \u043a\u0443\u0447\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0443\u043e\u0437\u043d\u043e\u0439? \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0445 \u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">from flask import Flask from flask.scaffold import setupmethod  class FastFlask(Flask):     @setupmethod     def route(self, rule: str, **options):         def decorator(f):             f = catch_validation_error(inject(f))  # \u043f\u0440\u044f\u0447\u0435\u043c \u0432\u0441\u0435 \u0441\u044e\u0434\u0430             endpoint = options.pop(\"endpoint\", None)             self.add_url_rule(rule, endpoint, f, **options)             return f         return decorator  app = FastFlask(__name__)  ...  @app.get(\"\/&lt;id>\") def hello(user: str = Depends(get_user)):     return f\"&lt;p>Hello, {user}!&lt;\/p>\" <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435!<\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0438\u0434\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/h4>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0448 <strong>FastFlask<\/strong> \u0443\u043c\u0435\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0443\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 <code>POST - JSON<\/code> \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 <strong>FastDepends<\/strong> \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043c\u0435\u0442\u043e\u0434 <code>use<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c, \u0443\u0431\u0438\u0440\u0430\u0442\u044c, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0432 \u0432\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"python\">from flask import request from fast_depends.library import CustomField  class Body(CustomField):     def use(self, **kwargs):         return {             **super().use(**kwargs),             self.param_name: (request.json or {}).get(self.param_name)         }  ...  @app.post(\"\/\") def hello(user_id: PositiveInt = Body()):     # \u043e\u0436\u0438\u0434\u0430\u0435\u0442 JSON \u0432\u0438\u0434\u0430 { \"user_id\": 1 }     return { \"Hi!\": user_id } <\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>Flask<\/strong> \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0443\u043c\u0435\u043b \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>pydantic<\/strong>, \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u043b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 <strong>Depends<\/strong>.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <strong>FastAPI<\/strong>, \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435?<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0441 <strong>\u043b\u044e\u0431\u044b\u043c<\/strong> <em>HTTP<\/em> (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) Python \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/gist.github.com\/Lancetnik\/0d33f098e6b342ac71e7606f1059db70\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<h3>\u0417\u0430\u0447\u0435\u043c?<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 &#8212; \u0434\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 <strong>OSS<\/strong> \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u043e\u0438\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <em>event-driven<\/em> \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 <a href=\"https:\/\/lancetnik.github.io\/Propan\" rel=\"noopener noreferrer nofollow\"><strong>Propan<\/strong><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 <strong>FastDepends<\/strong> \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c \u043e\u043f\u044b\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a \u043e\u043f\u044b\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u0432\u0430\u043c <strong>FastAPI<\/strong>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u043e \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0438 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0433\u043b\u0430\u0434\u0438\u0442\u044c \u0432\u0430\u0448\u0438 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u043b\u0435\u0433\u0430\u0441\u0438.<\/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\/748618\/\"> https:\/\/habr.com\/ru\/articles\/748618\/<\/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-350407","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350407","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=350407"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350407\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}