{"id":477190,"date":"2023-08-09T09:08:44","date_gmt":"2023-08-09T09:08:44","guid":{"rendered":""},"modified":"2023-09-05T11:14:14","modified_gmt":"2023-09-05T11:14:14","slug":"fastapi","status":"publish","type":"wiki","link":"https:\/\/oneproxy.pro\/cn\/wiki\/fastapi\/","title":{"rendered":"\u5feb\u901fAPI"},"content":{"rendered":"<p>FastAPI \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u6613\u4e8e\u4f7f\u7528\u7684 Web \u6846\u67b6\uff0c\u7528\u4e8e\u57fa\u4e8e\u6807\u51c6 Python \u7c7b\u578b\u63d0\u793a\u4f7f\u7528 Python 3.6+ \u6784\u5efa API\u3002\u5b83\u7684\u8bbe\u8ba1\u5177\u6709\u9ad8\u5ea6\u53ef\u6269\u5c55\u6027\u548c\u6613\u4e8e\u4f7f\u7528\u7684\u7279\u70b9\uff0c\u540c\u65f6\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u4f7f\u5176\u6210\u4e3a\u73b0\u4ee3 Web \u5f00\u53d1\u7684\u7edd\u4f73\u9009\u62e9\u3002<\/p>\n<h2>FastAPI \u7684\u8d77\u6e90<\/h2>\n<p>FastAPI \u7531 Sebasti\u00e1n Ram\u00edrez \u521b\u5efa\uff0c\u4e8e 2018 \u5e74 12 \u6708\u9996\u6b21\u53d1\u5e03\u3002\u5f00\u53d1 FastAPI \u7684\u4e3b\u8981\u52a8\u673a\u662f\u521b\u5efa\u4e00\u4e2a\u65e2\u9ad8\u6548\u53c8\u7528\u6237\u53cb\u597d\u7684 Web \u6846\u67b6\uff0c\u5229\u7528 Python \u7684\u65b0\u529f\u80fd\uff0c\u5c24\u5176\u662f Python 3.6+ \u7c7b\u578b\u63d0\u793a\u3002 FastAPI \u9996\u6b21\u51fa\u73b0\u5728 GitHub \u4e0a\uff0c\u7531\u4e8e\u5176\u6027\u80fd\u3001\u6613\u7528\u6027\u548c\u51fa\u8272\u7684\u793e\u533a\u652f\u6301\uff0c\u5b83\u5728 GitHub \u4e0a\u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\u3002<\/p>\n<h2>FastAPI \u7684\u4e16\u754c\u5185\u90e8<\/h2>\n<p>FastAPI \u5229\u7528\u7c7b\u578b\u6ce8\u91ca\u7684\u6982\u5ff5\u548c\u5f3a\u5927\u7684 Starlette Web \u90e8\u4ef6\u6846\u67b6\u3002\u5b83\u8fd8\u4f7f\u7528 Pydantic \u8fdb\u884c\u6570\u636e\u5904\u7406\u3002\u8fd9\u4e24\u4e2a\u57fa\u672c\u7ec4\u4ef6\u4e0e FastAPI \u7684\u72ec\u7279\u529f\u80fd\u76f8\u7ed3\u5408\uff0c\u4f7f\u5176\u6210\u4e3a Web \u5f00\u53d1\u7684\u5f3a\u5927\u5de5\u5177\u3002<\/p>\n<p>\u4e0e\u5176\u4ed6\u4e00\u4e9b Web \u6846\u67b6\u4e0d\u540c\uff0cFastAPI \u88ab\u8bbe\u8ba1\u4e3a\u5f02\u6b65\u7684\uff0c\u5141\u8bb8\u5b83\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002\u8fd9\u79cd\u5f02\u6b65\u6027\u662f\u4f7f\u7528 Python \u7684 async \u548c wait \u5173\u952e\u5b57\u5b9e\u73b0\u7684\uff0c\u8fd9\u4f7f\u5f97 FastAPI \u6210\u4e3a\u6784\u5efa\u5b9e\u65f6\u5e94\u7528\u7a0b\u5e8f\u548c\u5fae\u670d\u52a1\u7684\u7edd\u4f73\u9009\u62e9\u3002<\/p>\n<h2>FastAPI \u7684\u4e3b\u8981\u7279\u70b9<\/h2>\n<p>FastAPI \u5177\u6709\u591a\u79cd\u529f\u80fd\uff0c\u4f7f\u5176\u6709\u522b\u4e8e\u5176\u4ed6 Web \u6846\u67b6\uff1a<\/p>\n<ol>\n<li><strong>\u5feb\u901f\u5730<\/strong>\uff1a\u5b83\u662f Python \u53ef\u7528\u7684\u6700\u5feb\u6846\u67b6\u4e4b\u4e00\uff0c\u5728\u901f\u5ea6\u65b9\u9762\u4ec5\u6b21\u4e8e NodeJS \u548c Go\u3002<\/li>\n<li><strong>\u7b80\u5355\u7684<\/strong>\uff1a\u5b83\u5bf9\u5f00\u53d1\u4eba\u5458\u975e\u5e38\u53cb\u597d\uff0c\u9700\u8981\u66f4\u5c11\u7684\u6837\u677f\u4ee3\u7801\uff0c\u8fd9\u4f7f\u5f97\u65b0\u5f00\u53d1\u4eba\u5458\u66f4\u5bb9\u6613\u5b66\u4e60\u3002<\/li>\n<li><strong>\u76f4\u89c9\u7684<\/strong>\uff1aFastAPI \u5229\u7528 Python \u7684\u7c7b\u578b\u63d0\u793a\u6765\u63d0\u4f9b\u81ea\u52a8\u6570\u636e\u9a8c\u8bc1\u3001\u5e8f\u5217\u5316\u548c\u6587\u6863\u8bb0\u5f55\u3002<\/li>\n<li><strong>\u57fa\u4e8e\u6807\u51c6<\/strong>\uff1aFastAPI \u57fa\u4e8e\uff08\u5e76\u5b8c\u5168\u517c\u5bb9\uff09API \u7684\u5f00\u653e\u6807\u51c6\uff1aOpenAPI\uff08\u4ee5\u524d\u79f0\u4e3a Swagger\uff09\u548c JSON Schema\u3002<\/li>\n<li><strong>\u5f3a\u58ee\u7684<\/strong>\uff1a\u5b83\u652f\u6301 OAuth2 \u8eab\u4efd\u9a8c\u8bc1\u5904\u7406\u3001JSON Web \u4ee4\u724c\u3001HTTP\/2 \u548c WebSockets\u3002<\/li>\n<li><strong>\u53ef\u6269\u5c55<\/strong>\uff1aFastAPI \u652f\u6301\u5f02\u6b65\u8bf7\u6c42\u5904\u7406\uff0c\u4f7f\u5176\u6210\u4e3a\u5904\u7406\u957f\u671f\u8fde\u63a5\u548c\u5b9e\u65f6\u66f4\u65b0\u7684\u7edd\u4f73\u9009\u62e9\u3002<\/li>\n<\/ol>\n<h2>FastAPI \u5e94\u7528\u7a0b\u5e8f\u7684\u7c7b\u578b<\/h2>\n<p>FastAPI \u6ca1\u6709\u7279\u5b9a\u7684\u201c\u7c7b\u578b\u201d\uff0c\u56e0\u4e3a\u5b83\u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u5206\u7c7b\u3002\u4f46\u662f\uff0c\u5b83\u53ef\u7528\u4e8e\u6784\u5efa\u4e0d\u540c\u7c7b\u578b\u7684 Web \u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<ol>\n<li><strong>\u871c\u8702<\/strong>\uff1a\u5b83\u4e3b\u8981\u65e8\u5728\u521b\u5efa\u5f3a\u5927\u4e14\u53ef\u6269\u5c55\u7684 API\u3002<\/li>\n<li><strong>\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f<\/strong>\uff1a\u5b83\u8fd8\u53ef\u4ee5\u7528\u4e8e\u6784\u5efa\u6210\u719f\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li><strong>\u5fae\u670d\u52a1<\/strong>\uff1aFastAPI \u56e0\u5176\u901f\u5ea6\u548c\u53ef\u6269\u5c55\u6027\u800c\u6210\u4e3a\u5fae\u670d\u52a1\u7684\u7edd\u4f73\u9009\u62e9\u3002<\/li>\n<li><strong>\u5b9e\u65f6\u5e94\u7528<\/strong>\uff1a\u7531\u4e8e\u5b83\u652f\u6301WebSockets\uff0c\u56e0\u6b64\u9002\u5408\u5b9e\u65f6\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<\/ol>\n<h2>\u4f7f\u7528 FastAPI \u7684\u5b9e\u9645\u7528\u4f8b\u548c\u95ee\u9898\u89e3\u51b3<\/h2>\n<p>FastAPI \u5df2\u5e7f\u6cdb\u5e94\u7528\u4e8e\u4ece\u91d1\u878d\u79d1\u6280\u5230\u751f\u7269\u6280\u672f\u7b49\u884c\u4e1a\uff0c\u7528\u4e8e\u6784\u5efa RESTful API\u3001\u5b9e\u65f6\u9884\u6d4b\u670d\u52a1\u5668\u7b49\u4efb\u52a1\u3002<\/p>\n<p>\u4f7f\u7528 API \u65f6\u7684\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u9a8c\u8bc1\u8f93\u5165\u6570\u636e\u3002 FastAPI \u901a\u8fc7\u4f7f\u7528 Python \u7684\u7c7b\u578b\u63d0\u793a\u548c\u81ea\u52a8\u6267\u884c\u6570\u636e\u9a8c\u8bc1\u7684 Pydantic \u5e93\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u53e6\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u7ba1\u7406\u5f02\u6b65\u4efb\u52a1\u3002 FastAPI \u5177\u6709\u5bf9 Python \u5f02\u6b65\u7684\u5185\u7f6e\u652f\u6301\uff0c\u4f7f\u5f02\u6b65\u4efb\u52a1\u7684\u5904\u7406\u53d8\u5f97\u7b80\u5355\u3002<\/p>\n<h2>FastAPI \u4e0e\u5176\u4ed6\u6846\u67b6<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u7279\u5f81<\/th>\n<th>\u5feb\u901fAPI<\/th>\n<th>\u70e7\u74f6<\/th>\n<th>\u59dc\u6208<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u901f\u5ea6<\/td>\n<td>\u5f88\u9ad8<\/td>\n<td>\u7f13\u548c<\/td>\n<td>\u7f13\u548c<\/td>\n<\/tr>\n<tr>\n<td>\u5b66\u4e60\u66f2\u7ebf<\/td>\n<td>\u4f4e\u7684<\/td>\n<td>\u4f4e\u7684<\/td>\n<td>\u9ad8\u7684<\/td>\n<\/tr>\n<tr>\n<td>\u7075\u6d3b\u6027<\/td>\n<td>\u9ad8\u7684<\/td>\n<td>\u9ad8\u7684<\/td>\n<td>\u7f13\u548c<\/td>\n<\/tr>\n<tr>\n<td>\u53ef\u6269\u5c55\u6027<\/td>\n<td>\u9ad8\u7684<\/td>\n<td>\u7f13\u548c<\/td>\n<td>\u9ad8\u7684<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u7f6e\u529f\u80fd<\/td>\n<td>\u9ad8\u7684<\/td>\n<td>\u7f13\u548c<\/td>\n<td>\u9ad8\u7684<\/td>\n<\/tr>\n<tr>\n<td>\u5f02\u6b65\u652f\u6301<\/td>\n<td>\u662f\u7684<\/td>\n<td>\u4e0d<\/td>\n<td>\u4e0d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>FastAPI \u7684\u672a\u6765<\/h2>\n<p>FastAPI \u7684\u672a\u6765\u770b\u8d77\u6765\u5145\u6ee1\u5e0c\u671b\u3002\u7531\u4e8e\u5b83\u662f\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\uff0c\u8d21\u732e\u8005\u7684\u6570\u91cf\u4e0d\u65ad\u589e\u957f\uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u671f\u5f85\u65b0\u7684\u529f\u80fd\u548c\u6539\u8fdb\u3002\u968f\u7740\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u5728\u5176\u9879\u76ee\u4e2d\u91c7\u7528 FastAPI\uff0c\u53ef\u4ee5\u80af\u5b9a\u5730\u8ba4\u4e3a\u5b83\u5c06\u4ecd\u7136\u662f Python Web \u6846\u67b6\u9886\u57df\u7684\u91cd\u8981\u53c2\u4e0e\u8005\u3002<\/p>\n<p>\u65e0\u670d\u52a1\u5668\u67b6\u6784\u3001\u5bb9\u5668\u5316\u548c\u5fae\u670d\u52a1\u7b49\u65b0\u5174\u6280\u672f\u4e5f\u4e0e FastAPI \u517c\u5bb9\u3002\u56e0\u6b64\uff0c\u9884\u8ba1\u5b83\u4f1a\u4e0e\u8fd9\u4e9b\u65b0\u8303\u5f0f\u4e00\u8d77\u9002\u5e94\u548c\u53d1\u5c55\u3002<\/p>\n<h2>\u4ee3\u7406\u670d\u52a1\u5668\u548c FastAPI<\/h2>\n<p>\u4ee3\u7406\u670d\u52a1\u5668\u662f\u5145\u5f53\u5ba2\u6237\u7aef\u4ece\u5176\u4ed6\u670d\u52a1\u5668\u5bfb\u6c42\u8d44\u6e90\u7684\u8bf7\u6c42\u7684\u4e2d\u4ecb\u7684\u670d\u52a1\u5668\u3002\u5b83\u53ef\u4ee5\u4e0e FastAPI \u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u4f9b\u989d\u5916\u7684\u5b89\u5168\u5c42\u3001\u8d1f\u8f7d\u5e73\u8861\u548c\u7f13\u5b58\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5728\u5178\u578b\u7684\u7528\u4f8b\u4e2d\uff0c\u60a8\u53ef\u80fd\u6709\u4e00\u4e2a\u5728\u4ee3\u7406\u670d\u52a1\u5668\u540e\u9762\u8fd0\u884c\u7684 FastAPI \u5e94\u7528\u7a0b\u5e8f\u3002\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u4ee5\u5904\u7406\u5ba2\u6237\u7aef\u548c FastAPI \u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u7684\u8bf7\u6c42\u548c\u54cd\u5e94\u3002\u5b83\u53ef\u4ee5\u7f13\u5b58\u6765\u81ea FastAPI \u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\uff0c\u4ece\u800c\u51cf\u5c11\u8d1f\u8f7d\u5e76\u7f29\u77ed\u54cd\u5e94\u65f6\u95f4\u3002\u6b64\u5916\uff0c\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u4ee5\u63d0\u4f9b\u989d\u5916\u7684\u5b89\u5168\u63aa\u65bd\uff0c\u4f8b\u5982\u901f\u7387\u9650\u5236\u6216\u963b\u6b62\u7279\u5b9a IP \u5730\u5740\u3002<\/p>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<ul>\n<li>FastAPI GitHub \u5b58\u50a8\u5e93\uff1a <a href=\"https:\/\/github.com\/tiangolo\/fastapi\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/github.com\/tiangolo\/fastapi<\/a><\/li>\n<li>FastAPI\u5b98\u65b9\u6587\u6863\uff1a <a href=\"https:\/\/fastapi.tiangolo.com\/\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/fastapi.tiangolo.com\/<\/a><\/li>\n<li>Starlette GitHub \u5b58\u50a8\u5e93\uff1a <a href=\"https:\/\/github.com\/encode\/starlette\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/github.com\/encode\/starlette<\/a><\/li>\n<li>Pydantic GitHub \u5b58\u50a8\u5e93\uff1a <a href=\"https:\/\/github.com\/samuelcolvin\/pydantic\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/github.com\/samuelcolvin\/pydantic<\/a><\/li>\n<li>OpenAPI \u5021\u8bae\uff1a <a href=\"https:\/\/www.openapis.org\/\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/www.openapis.org\/<\/a><\/li>\n<li>JSON \u67b6\u6784\uff1a <a href=\"https:\/\/json-schema.org\/\" target=\"_new\" rel=\"noopener nofollow\">https:\/\/json-schema.org\/<\/a><\/li>\n<\/ul>","protected":false},"featured_media":468376,"menu_order":0,"template":"","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"class_list":["post-477190","wiki","type-wiki","status-publish","has-post-thumbnail","hentry"],"acf":{"faq_title":"Frequently Asked Questions about <mark>FastAPI: A Revolution in Web Development<\/mark>","faq_items":[{"question":"What is FastAPI?","answer":"<p>FastAPI is a high-performance web framework for building APIs with Python 3.6+. It is designed to be efficient, user-friendly, and supports asynchronous request handling.<\/p>"},{"question":"Who created FastAPI and when was it first released?","answer":"<p>FastAPI was created by Sebasti\u00e1n Ram\u00edrez and was first released in December 2018.<\/p>"},{"question":"What are the key features of FastAPI?","answer":"<p>FastAPI boasts several key features, including high speed, easy-to-use development, automatic data validation, and compatibility with open standards like OpenAPI and JSON Schema. It also supports OAuth2 authentication, JSON Web Tokens, HTTP\/2, and WebSockets.<\/p>"},{"question":"What types of applications can be built using FastAPI?","answer":"<p>FastAPI can be used to build a variety of applications, including APIs, web applications, microservices, and real-time applications.<\/p>"},{"question":"How does FastAPI compare to other frameworks like Flask and Django?","answer":"<p>When compared to Flask and Django, FastAPI stands out with its blazing speed, low learning curve, high flexibility, and excellent scalability. Additionally, it supports asynchronous request handling, which the other frameworks lack.<\/p>"},{"question":"What is the future outlook for FastAPI?","answer":"<p>The future of FastAPI looks promising as it is an open-source project with a growing community of contributors. It is expected to adapt to emerging technologies like serverless architecture and microservices.<\/p>"},{"question":"How can proxy servers be used with FastAPI?","answer":"<p>Proxy servers can be combined with FastAPI to provide additional security, load balancing, and caching. They act as intermediaries between the client and FastAPI application, enhancing performance and security.<\/p>"},{"question":"Where can I find more information about FastAPI?","answer":"<p>For more information about FastAPI, you can visit the official GitHub repository (<a href=\"https:\/\/github.com\/tiangolo\/fastapi\" target=\"_new\">https:\/\/github.com\/tiangolo\/fastapi<\/a>) or the official documentation (<a href=\"https:\/\/fastapi.tiangolo.com\/\" target=\"_new\">https:\/\/fastapi.tiangolo.com\/<\/a>). You may also explore related resources like Starlette (<a href=\"https:\/\/github.com\/encode\/starlette\" target=\"_new\">https:\/\/github.com\/encode\/starlette<\/a>) and Pydantic (<a href=\"https:\/\/github.com\/samuelcolvin\/pydantic\" target=\"_new\">https:\/\/github.com\/samuelcolvin\/pydantic<\/a>) used in conjunction with FastAPI.<\/p>"}]},"_links":{"self":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/477190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki"}],"about":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/types\/wiki"}],"version-history":[{"count":0,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/477190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media\/468376"}],"wp:attachment":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media?parent=477190"}],"curies":[{"name":"\u53ef\u6e7f\u6027\u7c89\u5242","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}