{"id":843,"date":"2025-07-21T12:00:00","date_gmt":"2025-07-21T12:00:00","guid":{"rendered":"https:\/\/ouyangminwei.com\/?p=843"},"modified":"2025-07-15T07:49:45","modified_gmt":"2025-07-15T07:49:45","slug":"litestar-vs-fastapi","status":"publish","type":"post","link":"https:\/\/ouyangminwei.com\/index.php\/2025\/07\/21\/litestar-vs-fastapi\/","title":{"rendered":"Litestar vs. FastAPI"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"zh-TW\" class=\"scroll-smooth\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u4e92\u52d5\u5f0f\u5831\u544a\uff1aLitestar vs. FastAPI<\/title>\n    <script src=\"https:\/\/cdn.tailwindcss.com\"><\/script>\n    <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/chart.js\"><\/script>\n    <link rel=\"preconnect\" href=\"https:\/\/fonts.googleapis.com\">\n    <link rel=\"preconnect\" href=\"https:\/\/fonts.gstatic.com\" crossorigin>\n    <link href=\"https:\/\/fonts.googleapis.com\/css2?family=Noto+Sans+TC:wght@400;500;700&#038;display=swap\" rel=\"stylesheet\">\n    <!-- Chosen Palette: Calm Neutrals with Tech Accents -->\n    <!-- Application Structure Plan: The application is designed as a single-page scrolling experience guided by a sticky top navigation, breaking the dense report into four logical, user-friendly sections: 1. **\u6982\u89bd (Overview)** for a quick summary. 2. **\u6838\u5fc3\u5c0d\u6bd4 (Core Comparison)** for a deep, interactive dive into key differences (philosophy, architecture, performance) using visual aids. 3. **\u6c7a\u7b56\u52a9\u624b (Decision Helper)** an interactive tool to provide personalized recommendations. 4. **\u7d50\u8ad6 (Conclusion)** for a final summary. This structure transforms the linear report into a task-oriented exploration, allowing users to either get a quick overview or delve into specific areas of interest, which is more effective for digital consumption than a simple text document. -->\n    <!-- Visualization & Content Choices: \n        - Report Info: Philosophy & Governance -> Goal: Compare -> Viz\/Presentation: Side-by-side text comparison with icons (HTML\/CSS) -> Interaction: None -> Justification: Clearly contrasts the two opposing models (BDFL vs. Community) for quick understanding.\n        - Report Info: Architecture (Routing & DI) -> Goal: Organize & Explain -> Viz\/Presentation: Simplified diagrams using styled HTML divs -> Interaction: None -> Justification: Visually demonstrates abstract concepts like dependency flow, making them more tangible than text alone.\n        - Report Info: Performance Benchmarks -> Goal: Compare -> Viz\/Presentation: Bar Chart -> Interaction: Hover tooltips -> Justification: A bar chart is the most effective way to compare quantitative performance data across multiple frameworks. -> Library\/Method: Chart.js\/Canvas.\n        - Report Info: Strategic Advice (Table 3) -> Goal: Guide & Recommend -> Viz\/Presentation: Interactive selection list -> Interaction: User clicks on a project priority, and the app highlights the recommended framework with an explanation. -> Justification: Turns passive advice into an active, personalized tool, increasing user engagement and utility.\n        - CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->\n    <style>\n        body {\n            font-family: 'Noto Sans TC', sans-serif;\n            background-color: #f8fafc; \/* slate-50 *\/\n        }\n        .chart-container {\n            position: relative;\n            width: 100%;\n            max-width: 800px;\n            margin-left: auto;\n            margin-right: auto;\n            height: 400px;\n            max-height: 50vh;\n        }\n        @media (min-width: 768px) {\n            .chart-container {\n                height: 450px;\n            }\n        }\n        .nav-link {\n            transition: color 0.3s, border-color 0.3s;\n        }\n        .active-link {\n            color: #4f46e5; \/* indigo-600 *\/\n            border-bottom-color: #4f46e5;\n        }\n        .inactive-link {\n            color: #4b5563; \/* gray-600 *\/\n            border-bottom-color: transparent;\n        }\n        .decision-card {\n            transition: all 0.3s ease-in-out;\n            cursor: pointer;\n        }\n        .decision-card.selected {\n            transform: translateY(-5px);\n            box-shadow: 0 10px 15px -3px rgb(0 0 0 \/ 0.1), 0 4px 6px -4px rgb(0 0 0 \/ 0.1);\n        }\n        .highlight-fastapi {\n            background-color: #fff7ed !important; \/* orange-50 *\/\n            border-color: #fb923c !important; \/* orange-400 *\/\n        }\n        .highlight-litestar {\n            background-color: #eff6ff !important; \/* blue-50 *\/\n            border-color: #60a5fa !important; \/* blue-400 *\/\n        }\n    <\/style>\n<\/head>\n<body class=\"text-gray-800\">\n\n    <header class=\"bg-white\/80 backdrop-blur-lg sticky top-0 z-50 shadow-sm\">\n        <nav class=\"container mx-auto px-6 py-3\">\n            <div class=\"flex justify-between items-center\">\n                <div class=\"text-xl font-bold text-gray-800\">\n                    Litestar vs FastAPI\n                <\/div>\n                <div class=\"hidden md:flex space-x-8\">\n                    <a href=\"#overview\" class=\"nav-link pb-1 border-b-2\">\u6982\u89bd<\/a>\n                    <a href=\"#comparison\" class=\"nav-link pb-1 border-b-2\">\u6838\u5fc3\u5c0d\u6bd4<\/a>\n                    <a href=\"#decision-helper\" class=\"nav-link pb-1 border-b-2\">\u6c7a\u7b56\u52a9\u624b<\/a>\n                    <a href=\"#conclusion\" class=\"nav-link pb-1 border-b-2\">\u7d50\u8ad6<\/a>\n                <\/div>\n            <\/div>\n        <\/nav>\n    <\/header>\n\n    <main>\n        <section id=\"overview\" class=\"py-16 md:py-24 bg-white\">\n            <div class=\"container mx-auto px-6 text-center\">\n                <h1 class=\"text-4xl md:text-5xl font-bold text-indigo-600 mb-4\">Python ASGI \u6846\u67b6\u7684\u5c0d\u6c7a<\/h1>\n                <p class=\"text-xl md:text-2xl text-gray-600 mb-8 max-w-3xl mx-auto\">\u4e00\u5834\u95dc\u65bc\u54f2\u5b78\u3001\u67b6\u69cb\u8207\u672a\u4f86\u7684\u6df1\u5ea6\u5256\u6790<\/p>\n                <p class=\"max-w-4xl mx-auto text-lg text-gray-700 leading-relaxed\">\n                    \u5728\u73fe\u4ee3 Python \u5f8c\u7aef\u958b\u767c\u4e2d\uff0cFastAPI \u4ee5\u5176\u6613\u7528\u6027\u548c\u9ad8\u6548\u80fd\u8fc5\u901f\u5d1b\u8d77\u3002\u7136\u800c\uff0c\u4e00\u500b\u5f37\u5927\u7684\u6311\u6230\u8005 Litestar \u61c9\u904b\u800c\u751f\uff0c\u5b83\u4e0d\u50c5\u662f\u53e6\u4e00\u500b\u9078\u9805\uff0c\u66f4\u4ee3\u8868\u4e86\u5c0d\u5927\u578b\u5c08\u6848\u67b6\u69cb\u3001\u9577\u671f\u53ef\u7dad\u8b77\u6027\u548c\u793e\u7fa4\u6cbb\u7406\u7684\u6df1\u523b\u53cd\u601d\u3002\u672c\u4e92\u52d5\u5831\u544a\u5c07\u5e36\u60a8\u6df1\u5165\u63a2\u7d22\u5169\u8005\u7684\u6838\u5fc3\u5dee\u7570\uff0c\u52a9\u60a8\u505a\u51fa\u6700\u9069\u5408\u7684\u6280\u8853\u9078\u64c7\u3002\n                <\/p>\n                <div class=\"mt-12 grid md:grid-cols-2 gap-8 max-w-4xl mx-auto\">\n                    <div class=\"bg-gray-100 p-8 rounded-xl\">\n                        <h3 class=\"text-2xl font-bold text-orange-500 mb-3\">FastAPI<\/h3>\n                        <p class=\"text-gray-700\">\u70ba **\u901f\u5ea6** \u800c\u751f\u3002\u5d07\u5c1a\u81ea\u52d5\u5316\u8207\u300c\u9b54\u6cd5\u300d\uff0c\u63d0\u4f9b\u7121\u8207\u502b\u6bd4\u7684\u958b\u767c\u8005\u9ad4\u9a57\uff0c\u7279\u5225\u9069\u5408\u5feb\u901f\u539f\u578b\u8a2d\u8a08\u548c\u4e2d\u5c0f\u578b\u5c08\u6848\u3002<\/p>\n                    <\/div>\n                    <div class=\"bg-gray-100 p-8 rounded-xl\">\n                        <h3 class=\"text-2xl font-bold text-blue-500 mb-3\">Litestar<\/h3>\n                        <p class=\"text-gray-700\">\u70ba **\u898f\u6a21** \u800c\u5efa\u3002\u5021\u5c0e\u63a7\u5236\u6b0a\u8207\u660e\u78ba\u6027\uff0c\u63d0\u4f9b\u56b4\u8b39\u7684\u67b6\u69cb\u548c\u7a69\u5065\u7684\u6cbb\u7406\uff0c\u5c08\u70ba\u5927\u578b\u3001\u9577\u9031\u671f\u7684\u4f01\u696d\u7d1a\u61c9\u7528\u8a2d\u8a08\u3002<\/p>\n                    <\/div>\n                <\/div>\n            <\/div>\n        <\/section>\n\n        <section id=\"comparison\" class=\"py-16 md:py-24\">\n            <div class=\"container mx-auto px-6\">\n                <div class=\"text-center mb-12\">\n                    <h2 class=\"text-3xl md:text-4xl font-bold mb-4\">\u6838\u5fc3\u5c0d\u6bd4\uff1a\u56db\u5927\u7dad\u5ea6<\/h2>\n                    <p class=\"text-lg text-gray-600 max-w-3xl mx-auto\">\u6df1\u5165\u4e86\u89e3\u5169\u8005\u5728\u8a2d\u8a08\u54f2\u5b78\u3001\u57fa\u790e\u67b6\u69cb\u3001\u6548\u80fd\u8868\u73fe\u548c\u5c08\u6848\u6cbb\u7406\u4e0a\u7684\u6839\u672c\u5dee\u7570\u3002<\/p>\n                <\/div>\n\n                <div class=\"space-y-16\">\n                    \n                    <div class=\"p-8 bg-white rounded-2xl shadow-lg\">\n                        <h3 class=\"text-2xl font-bold mb-6 text-center text-indigo-600\">1. \u54f2\u5b78\u8207\u6cbb\u7406\uff1a\u7368\u88c1\u8005 vs. \u793e\u7fa4<\/h3>\n                        <div class=\"grid md:grid-cols-2 gap-8 text-center\">\n                            <div class=\"border border-gray-200 p-6 rounded-lg\">\n                                <h4 class=\"text-xl font-semibold mb-3 text-orange-500\">FastAPI: \u4ec1\u6148\u7684\u7368\u88c1\u8005 (BDFL)<\/h4>\n                                <div class=\"text-5xl mb-4\">\ud83d\udc51<\/div>\n                                <p class=\"text-gray-700\">\u7531\u5275\u59cb\u4eba\u64c1\u6709\u552f\u4e00\u6c7a\u7b56\u6b0a\u3002\u512a\u9ede\u662f\u9858\u666f\u7d71\u4e00\uff0c\u4f46\u5b58\u5728\u55ae\u9ede\u6545\u969c\u98a8\u96aa\uff0c\u5c08\u6848\u767c\u5c55\u53ef\u80fd\u56e0\u7dad\u8b77\u8005\u7cbe\u529b\u800c\u53d7\u9650\u3002<\/p>\n                            <\/div>\n                            <div class=\"border border-gray-200 p-6 rounded-lg\">\n                                <h4 class=\"text-xl font-semibold mb-3 text-blue-500\">Litestar: \u793e\u7fa4\u9a45\u52d5<\/h4>\n                                <div class=\"text-5xl mb-4\">\ud83d\udc65<\/div>\n                                <p class=\"text-gray-700\">\u7531\u6838\u5fc3\u5718\u968a\u5171\u540c\u7ba1\u7406\u3002\u65e8\u5728\u63d0\u9ad8\u5c08\u6848\u7684\u97cc\u6027\u548c\u9577\u58fd\uff0c\u964d\u4f4e\u56e0\u500b\u4eba\u56e0\u7d20\u5c0e\u81f4\u5c08\u6848\u505c\u6eef\u7684\u98a8\u96aa\u3002<\/p>\n                            <\/div>\n                        <\/div>\n                    <\/div>\n\n                    <div class=\"p-8 bg-white rounded-2xl shadow-lg\">\n                        <h3 class=\"text-2xl font-bold mb-6 text-center text-indigo-600\">2. \u67b6\u69cb\u8207\u8a2d\u8a08\uff1a\u9b54\u6cd5 vs. \u660e\u78ba<\/h3>\n                        <p class=\"text-center text-gray-600 max-w-3xl mx-auto mb-8\">\n                            \u5169\u8005\u6700\u5927\u7684\u67b6\u69cb\u5dee\u7570\u9ad4\u73fe\u5728\u8def\u7531\u5b9a\u7fa9\u548c\u4f9d\u8cf4\u6ce8\u5165\u7684\u65b9\u5f0f\u4e0a\uff0c\u9019\u76f4\u63a5\u5f71\u97ff\u4e86\u5927\u578b\u5c08\u6848\u7684\u7a0b\u5f0f\u78bc\u7d44\u7e54\u548c\u53ef\u7dad\u8b77\u6027\u3002\n                        <\/p>\n                        <div class=\"grid md:grid-cols-2 gap-8\">\n                            <div>\n                                <h4 class=\"text-xl font-semibold mb-3 text-orange-500 text-center\">FastAPI: \u88dd\u98fe\u5668\u8207\u63a7\u5236\u53cd\u8f49<\/h4>\n                                <div class=\"bg-gray-50 p-4 rounded-lg border\">\n                                    <p class=\"font-mono text-sm\">\n                                        <span class=\"text-gray-500\"># app.py<\/span><br>\n                                        <span class=\"text-purple-600\">from<\/span> fastapi <span class=\"text-purple-600\">import<\/span> FastAPI<br>\n                                        app = FastAPI()<br>\n                                        &#8230;<br>\n                                        <span class=\"text-purple-600\">from<\/span> . <span class=\"text-purple-600\">import<\/span> user_routes\n                                    <\/p>\n                                    <hr class=\"my-2\">\n                                    <p class=\"font-mono text-sm\">\n                                        <span class=\"text-gray-500\"># user_routes.py<\/span><br>\n                                        <span class=\"text-purple-600\">from<\/span> .app <span class=\"text-purple-600\">import<\/span> app <span class=\"text-red-500\">&lt;&#8211; \u6f5b\u5728\u5faa\u74b0\u4f9d\u8cf4<\/span><br><br>\n                                        @app.get(&#8220;\/users&#8221;)<br>\n                                        <span class=\"text-purple-600\">def<\/span> get_users(): &#8230;\n                                    <\/p>\n                                <\/div>\n                                <p class=\"mt-3 text-sm text-gray-600\">\u8def\u7531\u8655\u7406\u5668\u4f9d\u8cf4\u61c9\u7528\u5be6\u4f8b\uff0c\u5728\u5927\u578b\u5c08\u6848\u4e2d\u5bb9\u6613\u9020\u6210\u7a0b\u5f0f\u78bc\u7d44\u7e54\u6df7\u4e82\u548c\u5faa\u74b0\u4f9d\u8cf4\u3002<\/p>\n                            <\/div>\n                            <div>\n                                <h4 class=\"text-xl font-semibold mb-3 text-blue-500 text-center\">Litestar: \u660e\u78ba\u8a3b\u518a\u8207\u55ae\u5411\u4f9d\u8cf4<\/h4>\n                                <div class=\"bg-gray-50 p-4 rounded-lg border\">\n                                    <p class=\"font-mono text-sm\">\n                                        <span class=\"text-gray-500\"># main.py<\/span><br>\n                                        <span class=\"text-purple-600\">from<\/span> litestar <span class=\"text-purple-600\">import<\/span> Litestar<br>\n                                        <span class=\"text-purple-600\">from<\/span> .user_controller <span class=\"text-purple-600\">import<\/span> UserController<br><br>\n                                        app = Litestar(route_handlers=[UserController])\n                                    <\/p>\n                                    <hr class=\"my-2\">\n                                     <p class=\"font-mono text-sm\">\n                                        <span class=\"text-gray-500\"># user_controller.py<\/span><br>\n                                        <span class=\"text-purple-600\">from<\/span> litestar <span class=\"text-purple-600\">import<\/span> Controller, get<br><br>\n                                        <span class=\"text-purple-600\">class<\/span> UserController(Controller):<br>\n                                        &nbsp;&nbsp;@get(&#8220;\/users&#8221;)<br>\n                                        &nbsp;&nbsp;<span class=\"text-purple-600\">def<\/span> get_users(self) -> &#8230;: &#8230;\n                                    <\/p>\n                                <\/div>\n                                <p class=\"mt-3 text-sm text-gray-600\">\u8def\u7531\u8655\u7406\u5668\uff08\u5728\u63a7\u5236\u5668\u4e2d\uff09\u7368\u7acb\u5b9a\u7fa9\uff0c\u7531\u61c9\u7528\u5165\u53e3\u7d71\u4e00\u8a3b\u518a\uff0c\u78ba\u4fdd\u4e86\u6e05\u6670\u7684\u55ae\u5411\u4f9d\u8cf4\u6d41\u3002<\/p>\n                            <\/div>\n                        <\/div>\n                    <\/div>\n                    \n                    <div class=\"p-8 bg-white rounded-2xl shadow-lg\">\n                        <h3 class=\"text-2xl font-bold mb-2 text-center text-indigo-600\">3. \u6548\u80fd\u8868\u73fe\uff1a\u4e00\u5834\u95dc\u65bc\u6beb\u79d2\u7684\u6230\u722d<\/h3>\n                        <p class=\"text-center text-gray-600 max-w-3xl mx-auto mb-8\">\n                            \u6548\u80fd\u662f ASGI \u6846\u67b6\u7684\u6838\u5fc3\u8ce3\u9ede\u3002Litestar \u901a\u904e\u81ea\u8a02\u5e95\u5c64\u67b6\u69cb\u548c\u63a1\u7528 `msgspec`\uff0c\u5728\u591a\u500b\u57fa\u6e96\u6e2c\u8a66\u4e2d\u5c55\u73fe\u51fa\u512a\u52e2\u3002\u4ee5\u4e0b\u5716\u8868\u57fa\u65bc\u516c\u958b\u7684\u57fa\u6e96\u6e2c\u8a66\u6578\u64da\uff0c\u5c55\u793a\u4e86\u5728 JSON \u5e8f\u5217\u5316\u5834\u666f\u4e0b\u7684\u76f8\u5c0d\u6548\u80fd\u3002\n                        <\/p>\n                        <div class=\"chart-container\">\n                            <canvas id=\"performanceChart\"><\/canvas>\n                        <\/div>\n                    <\/div>\n\n                <\/div>\n            <\/div>\n        <\/section>\n        \n        <section id=\"decision-helper\" class=\"py-16 md:py-24 bg-white\">\n            <div class=\"container mx-auto px-6\">\n                <div class=\"text-center mb-12\">\n                    <h2 class=\"text-3xl md:text-4xl font-bold mb-4\">\u4e92\u52d5\u6c7a\u7b56\u52a9\u624b<\/h2>\n                    <p class=\"text-lg text-gray-600 max-w-3xl mx-auto\">\u60a8\u7684\u5c08\u6848\u9700\u6c42\u662f\u4ec0\u9ebc\uff1f\u9ede\u64ca\u4e0b\u65b9\u6700\u7b26\u5408\u60a8\u8003\u91cf\u7684\u6a19\u6e96\uff0c\u67e5\u770b\u63a8\u85a6\u7684\u6846\u67b6\u3002<\/p>\n                <\/div>\n                <div class=\"grid md:grid-cols-3 gap-6 mb-8\">\n                    <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"fastapi\">\n                        <h4 class=\"font-bold text-lg\">\u521d\u59cb\u958b\u767c\u901f\u5ea6<\/h4>\n                    <\/div>\n                     <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"litestar\">\n                        <h4 class=\"font-bold text-lg\">\u9577\u671f\u53ef\u7dad\u8b77\u6027<\/h4>\n                    <\/div>\n                    <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"litestar\">\n                        <h4 class=\"font-bold text-lg\">\u6975\u81f4\u6548\u80fd<\/h4>\n                    <\/div>\n                    <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"litestar\">\n                        <h4 class=\"font-bold text-lg\">\u67b6\u69cb\u9748\u6d3b\u6027<\/h4>\n                    <\/div>\n                     <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"fastapi\">\n                        <h4 class=\"font-bold text-lg\">\u5b78\u7fd2\u66f2\u7dda\/\u5165\u9580\u96e3\u5ea6<\/h4>\n                    <\/div>\n                     <div class=\"decision-card bg-gray-50 p-4 rounded-lg border-2 border-transparent text-center\" data-choice=\"litestar\">\n                        <h4 class=\"font-bold text-lg\">\u6cbb\u7406\u8207\u5c08\u6848\u7a69\u5b9a\u6027<\/h4>\n                    <\/div>\n                <\/div>\n                \n                <div id=\"recommendation-box\" class=\"grid md:grid-cols-2 gap-8 mt-10\">\n                    <div id=\"fastapi-card\" class=\"p-8 rounded-xl border-4 border-dashed border-gray-300 transition-all duration-300\">\n                        <h3 class=\"text-2xl font-bold text-orange-500 mb-3\">FastAPI<\/h3>\n                        <p id=\"fastapi-reason\" class=\"text-gray-700 h-24\">\u5353\u8d8a\u7684\u6587\u4ef6\u548c\u4f4e\u5165\u9580\u9580\u6abb\uff0c\u8b93\u60a8\u80fd\u5feb\u901f\u555f\u52d5\u5c08\u6848\u3002\u9069\u5408\u5feb\u901f\u539f\u578b\u3001MVP \u548c\u7d93\u9a57\u8f03\u6dfa\u7684\u5718\u968a\u3002<\/p>\n                    <\/div>\n                    <div id=\"litestar-card\" class=\"p-8 rounded-xl border-4 border-dashed border-gray-300 transition-all duration-300\">\n                        <h3 class=\"text-2xl font-bold text-blue-500 mb-3\">Litestar<\/h3>\n                        <p id=\"litestar-reason\" class=\"text-gray-700 h-24\">\u66f4\u512a\u7684\u7a0b\u5f0f\u78bc\u7d50\u69cb\u3001\u660e\u78ba\u7684 DI \u548c\u793e\u7fa4\u6cbb\u7406\u6a21\u5f0f\uff0c\u70ba\u5927\u578b\u3001\u9577\u9031\u671f\u5c08\u6848\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u64f4\u5c55\u6027\u4fdd\u99d5\u8b77\u822a\u3002<\/p>\n                    <\/div>\n                <\/div>\n            <\/div>\n        <\/section>\n\n        <section id=\"conclusion\" class=\"py-16 md:py-24 bg-slate-800 text-white\">\n            <div class=\"container mx-auto px-6\">\n                 <div class=\"text-center mb-12\">\n                    <h2 class=\"text-3xl md:text-4xl font-bold mb-4\">\u7d50\u8ad6\u8207\u672a\u4f86\u5c55\u671b<\/h2>\n                    <p class=\"text-lg text-slate-300 max-w-3xl mx-auto\">\u9019\u4e0d\u662f\u300c\u66f4\u597d\u300d\u6216\u300c\u66f4\u58de\u300d\u7684\u9078\u64c7\uff0c\u800c\u662f\u5c07\u6846\u67b6\u54f2\u5b78\u8207\u5c08\u6848\u9700\u6c42\u76f8\u5339\u914d\u7684\u904e\u7a0b\u3002<\/p>\n                <\/div>\n                <div class=\"max-w-4xl mx-auto bg-slate-700 p-8 rounded-lg\">\n                    <p class=\"mb-4\">\n                        <strong>FastAPI<\/strong> \u70ba\u300c\u901f\u5ea6\u300d\u9032\u884c\u4e86\u512a\u5316\u3002\u5b83\u63d0\u4f9b\u7121\u8207\u502b\u6bd4\u7684\u6613\u7528\u6027\u548c\u9f90\u5927\u7684\u751f\u614b\u7cfb\u7d71\uff0c\u4ee3\u50f9\u662f\u6f5b\u5728\u7684\u67b6\u69cb\u7d04\u675f\u548c\u66f4\u9ad8\u7684\u6cbb\u7406\u98a8\u96aa\u3002\n                    <\/p>\n                    <p class=\"mb-6\">\n                        <strong>Litestar<\/strong> \u70ba\u300c\u898f\u6a21\u300d\u548c\u300c\u53ef\u6301\u7e8c\u6027\u300d\u9032\u884c\u4e86\u512a\u5316\u3002\u5b83\u63d0\u4f9b\u5353\u8d8a\u7684\u6548\u80fd\u6f5b\u529b\u3001\u56b4\u8b39\u7684\u67b6\u69cb\u548c\u7a69\u5065\u7684\u6cbb\u7406\uff0c\u4ee3\u50f9\u662f\u76f8\u5c0d\u9661\u5ced\u7684\u5b78\u7fd2\u66f2\u7dda\u548c\u4e00\u500b\u6210\u9577\u4e2d\u7684\u751f\u614b\u3002\n                    <\/p>\n                    <p class=\"font-medium text-slate-200\">\n                        \u60a8\u4eca\u5929\u7684\u9078\u64c7\uff0c\u4e0d\u50c5\u662f\u70ba\u7576\u524d\u5c08\u6848\u9078\u64c7\u5de5\u5177\uff0c\u4e5f\u662f\u5728\u5c0d\u5169\u500b\u5c08\u6848\u672a\u4f86\u7684\u767c\u5c55\u8ecc\u8de1\u9032\u884c\u6295\u8cc7\u3002\u5e0c\u671b\u672c\u5831\u544a\u80fd\u8ce6\u4e88\u60a8\u80fd\u529b\uff0c\u505a\u51fa\u6700\u660e\u667a\u7684\u6230\u7565\u6289\u64c7\u3002\n                    <\/p>\n                <\/div>\n            <\/div>\n        <\/section>\n    <\/main>\n    \n    <footer class=\"bg-gray-800 text-white py-6\">\n        <div class=\"container mx-auto px-6 text-center text-sm text-gray-400\">\n            <p>\u6b64\u4e92\u52d5\u5831\u544a\u6839\u64da\u516c\u958b\u7814\u7a76\u5831\u544a\u751f\u6210\uff0c\u50c5\u4f9b\u53c3\u8003\u3002<\/p>\n            <p>&copy; 2024. All Rights Reserved.<\/p>\n        <\/div>\n    <\/footer>\n\n    <script>\n        document.addEventListener('DOMContentLoaded', function() {\n            const performanceData = {\n                labels: ['Starlette', 'FastAPI (Pydantic)', 'Litestar (msgspec)'],\n                datasets: [{\n                    label: '\u6bcf\u79d2\u8acb\u6c42\u6578 (\u8d8a\u9ad8\u8d8a\u597d)',\n                    data: [135000, 125000, 180000], \n                    backgroundColor: [\n                        'rgba(107, 114, 128, 0.6)', \/\/ gray-500\n                        'rgba(251, 146, 60, 0.6)', \/\/ orange-400\n                        'rgba(59, 130, 246, 0.6)'  \/\/ blue-500\n                    ],\n                    borderColor: [\n                        'rgba(107, 114, 128, 1)',\n                        'rgba(251, 146, 60, 1)',\n                        'rgba(59, 130, 246, 1)'\n                    ],\n                    borderWidth: 1\n                }]\n            };\n\n            const config = {\n                type: 'bar',\n                data: performanceData,\n                options: {\n                    maintainAspectRatio: false,\n                    scales: {\n                        y: {\n                            beginAtZero: true,\n                            title: {\n                                display: true,\n                                text: '\u8acb\u6c42\u6578 \/ \u79d2'\n                            }\n                        }\n                    },\n                    plugins: {\n                        title: {\n                            display: true,\n                            text: 'JSON \u5e8f\u5217\u5316\u6548\u80fd\u57fa\u6e96\u6bd4\u8f03',\n                            font: {\n                                size: 18\n                            },\n                            padding: {\n                                top: 10,\n                                bottom: 20\n                            }\n                        },\n                        tooltip: {\n                            callbacks: {\n                                label: function(context) {\n                                    let label = context.dataset.label || '';\n                                    if (label) {\n                                        label += ': ';\n                                    }\n                                    if (context.parsed.y !== null) {\n                                        label += new Intl.NumberFormat('en-US').format(context.parsed.y);\n                                    }\n                                    return label;\n                                }\n                            }\n                        }\n                    }\n                }\n            };\n            \n            const performanceChartCtx = document.getElementById('performanceChart');\n            if(performanceChartCtx) {\n                new Chart(performanceChartCtx, config);\n            }\n\n            const decisionCards = document.querySelectorAll('.decision-card');\n            const fastapiCard = document.getElementById('fastapi-card');\n            const litestarCard = document.getElementById('litestar-card');\n            const fastapiReasonEl = document.getElementById('fastapi-reason');\n            const litestarReasonEl = document.getElementById('litestar-reason');\n            \n            const reasons = {\n                '\u521d\u59cb\u958b\u767c\u901f\u5ea6': { framework: 'fastapi', text: '\u5353\u8d8a\u7684\u6587\u4ef6\u3001\u66f4\u4f4e\u7684\u5165\u9580\u9580\u6abb\u548c\u66f4\u5c11\u7684\u6a23\u677f\u7a0b\u5f0f\u78bc\uff0c\u5c08\u70ba\u5feb\u901f\u555f\u52d5\u800c\u8a2d\u8a08\u3002' },\n                '\u9577\u671f\u53ef\u7dad\u8b77\u6027': { framework: 'litestar', text: '\u66f4\u512a\u7684\u7a0b\u5f0f\u78bc\u7d50\u69cb\uff08\u63a7\u5236\u5668\uff09\u3001\u660e\u78ba\u7684\u5206\u5c64 DI\u3001\u6e05\u6670\u7684\u4f9d\u8cf4\u95dc\u4fc2\uff0c\u70ba\u9577\u671f\u7dad\u8b77\u6253\u4e0b\u5805\u5be6\u57fa\u790e\u3002' },\n                '\u6975\u81f4\u6548\u80fd': { framework: 'litestar', text: '\u81ea\u8a02\u7684 ASGI \u6838\u5fc3\u3001\u9ad8\u6548\u8def\u7531\u3001\u5167\u90e8\u4f7f\u7528 msgspec\uff0c\u6548\u80fd\u5929\u82b1\u677f\u66f4\u9ad8\uff0c\u9069\u5408\u5c0d\u5ef6\u9072\u654f\u611f\u7684\u61c9\u7528\u3002' },\n                '\u67b6\u69cb\u9748\u6d3b\u6027': { framework: 'litestar', text: '\u53ef\u63d2\u62d4\u7684\u8cc7\u6599\u6a21\u578b\u3001\u9748\u6d3b\u7684\u5206\u5c64 DI \u8986\u84cb\u6a5f\u5236\uff0c\u7d66\u4e88\u958b\u767c\u8005\u66f4\u5927\u7684\u63a7\u5236\u6b0a\u3002' },\n                '\u5b78\u7fd2\u66f2\u7dda\/\u5165\u9580\u96e3\u5ea6': { framework: 'fastapi', text: '\u88ab\u516c\u8a8d\u70ba\u696d\u754c\u6a19\u7aff\u7684\u6559\u7a0b\u5f0f\u6587\u4ef6\uff0c\u5c0d\u65b0\u624b\u6975\u70ba\u53cb\u597d\uff0c\u793e\u7fa4\u9f90\u5927\uff0c\u8cc7\u6e90\u8c50\u5bcc\u3002' },\n                '\u6cbb\u7406\u8207\u5c08\u6848\u7a69\u5b9a\u6027': { framework: 'litestar', text: '\u793e\u7fa4\u4e3b\u5c0e\uff0c\u591a\u4f4d\u6838\u5fc3\u7dad\u8b77\u8005\uff0c\u5df4\u58eb\u4fc2\u6578\u9ad8\uff0c\u5c08\u6848\u98a8\u96aa\u66f4\u4f4e\uff0c\u9069\u5408\u4f01\u696d\u7d1a\u9577\u9031\u671f\u5c08\u6848\u3002' }\n            };\n\n            decisionCards.forEach(card => {\n                card.addEventListener('click', () => {\n                    const choiceKey = card.querySelector('h4').textContent;\n                    const reasonData = reasons[choiceKey];\n                    \n                    decisionCards.forEach(c => c.classList.remove('selected', 'bg-blue-100', 'bg-orange-100'));\n                    \n                    card.classList.add('selected');\n\n                    fastapiCard.classList.remove('highlight-fastapi');\n                    litestarCard.classList.remove('highlight-litestar');\n                    fastapiReasonEl.textContent = '...';\n                    litestarReasonEl.textContent = '...';\n                    \n                    if (reasonData.framework === 'fastapi') {\n                        card.classList.add('bg-orange-100');\n                        fastapiCard.classList.add('highlight-fastapi');\n                        fastapiReasonEl.textContent = reasonData.text;\n                    } else {\n                        card.classList.add('bg-blue-100');\n                        litestarCard.classList.add('highlight-litestar');\n                        litestarReasonEl.textContent = reasonData.text;\n                    }\n                });\n            });\n\n            const navLinks = document.querySelectorAll('.nav-link');\n            const sections = document.querySelectorAll('main section');\n            \n            const observerOptions = {\n                root: null,\n                rootMargin: '0px',\n                threshold: 0.5 \n            };\n\n            const observer = new IntersectionObserver((entries) => {\n                entries.forEach(entry => {\n                    if (entry.isIntersecting) {\n                        const id = entry.target.getAttribute('id');\n                        navLinks.forEach(link => {\n                            link.classList.remove('active-link');\n                            link.classList.add('inactive-link');\n                            if (link.getAttribute('href') === `#${id}`) {\n                                link.classList.add('active-link');\n                                link.classList.remove('inactive-link');\n                            }\n                        });\n                    }\n                });\n            }, observerOptions);\n\n            sections.forEach(section => {\n                observer.observe(section);\n            });\n        });\n    <\/script>\n<\/body>\n<\/html>\n\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e92\u52d5\u5f0f\u5831\u544a\uff1aLitestar vs. FastAPI Litestar vs F &hellip; <a href=\"https:\/\/ouyangminwei.com\/index.php\/2025\/07\/21\/litestar-vs-fastapi\/\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"post_format":[],"class_list":["post-843","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_edit_lock":"1752829800:1","_edit_last":"1","_aioseo_title":"#post_title #separator_sa #site_title","_aioseo_description":"#post_excerpt","_aioseo_keywords":"","_aioseo_og_title":"","_aioseo_og_description":"","_aioseo_og_article_section":"","_aioseo_og_article_tags":"","_aioseo_twitter_title":"","_aioseo_twitter_description":"","_oembed_2544c1d0cb3503ab4c4d558c3b3c8873":"","_oembed_time_2544c1d0cb3503ab4c4d558c3b3c8873":"","_oembed_99481806ecbe6ce4ee46f8588d320993":"","_oembed_db663acf973e82e6d9d80df71945dfb8":"","_oembed_16cdfab488f57db73586f4286af2704f":"","_wp_old_slug":"","_links":{"self":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/comments?post=843"}],"version-history":[{"count":1,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"predecessor-version":[{"id":844,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/843\/revisions\/844"}],"wp:attachment":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/tags?post=843"},{"taxonomy":"post_format","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/post_format?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}