FastAPI: Modern Python Web Development / FastAPI: Современная веб-разработка на Python Год издания: 2024 Автор: Lubanovic Bill / Любанович Билл Издательство: O’Reilly Media ISBN: 978-1-098-13550-8 Язык: Английский Формат: PDF, EPUB Качество: Издательский макет или текст (eBook) Интерактивное оглавление: Да Количество страниц: 280 Описание: FastAPI is a young yet solid framework that takes advantage of newer Python features in a clean design. As its name implies, FastAPI is indeed fast, rivaling similar frameworks in languages such as Golang. With this practical book, developers familiar with Python will learn how FastAPI lets you accomplish more in less time with less code. Author Bill Lubanovic covers the nuts and bolts of FastAPI development with how-to guides on various topics such as forms, database access, graphics, maps, and more that will take you beyond the basics. This book also includes how-to guides that will get you up to speed on RESTful APIs, data validation, authorization, and performance. With its similarities to frameworks like Flask and Django, you’ll find it easy to get started with FastAPI. Through the course of this book, you will Learn how to build web applications with FastAPI Understand the differences between FastAPI, Starlette, and pydantic Learn two features that set FastAPI apart: asynchronous functions and data type checking and validation Examine new features of Python 3.8+, especially type annotations Understand the differences between sync and async Python Learn how to connect with external APIs and services FastAPI - это молодой, но надежный фреймворк, который использует преимущества новых функций Python в чистом дизайне. Как следует из названия, FastAPI действительно быстр, конкурируя с аналогичными фреймворками на таких языках, как Golang. Из этой практической книги разработчики, знакомые с Python, узнают, как FastAPI позволяет вам выполнять больше за меньшее время с меньшим количеством кода. Автор Билл Любанович рассказывает о тонкостях разработки FastAPI с помощью практических руководств по различным темам, таким как формы, доступ к базе данных, графика, карты и многое другое, которые выведут вас за рамки основ. В эту книгу также включены практические руководства, которые помогут вам быстро освоить RESTful API, проверку данных, авторизацию и производительность. Благодаря сходству с такими фреймворками, как Flask и Django, вам будет легко начать работу с FastAPI. Из этой книги вы Узнаете, как создавать веб-приложения с помощью FastAPI Разберетесь в различиях между FastAPI, Starlette и pydantic Изучите две функции, отличающие FastAPI: асинхронные функции и проверку типов данных Изучите новые возможности Python 3.8+, особенно аннотации типов Разберитесь в различиях между sync и async Python Узнаете, как подключаться к внешним API и сервисам
Примеры страниц
Оглавление
Preface xiii Part I. What’s New? 1. The Modern Web 3 Preview 3 Services and APIs 4 Kinds of APIs 4 HTTP 5 REST(ful) 5 JSON and API Data Formats 7 JSON:API 7 GraphQL 8 Concurrency 8 Layers 9 Data 12 Review 13 2. Modern Python 15 Preview 15 Tools 15 Getting Started 16 Python Itself 17 Package Management 17 Virtual Environments 17 Poetry 18 Source Formatting 19 Testing 19 Source Control and Continuous Integration 19 Web Tools 19 APIs and Services 20 Variables Are Names 20 Type Hints 21 Data Structures 21 Web Frameworks 21 Django 22 Flask 22 FastAPI 22 Review 23 Part II. A FastAPI Tour 3. FastAPI Tour 27 Preview 27 What Is FastAPI? 27 A FastAPI Application 28 HTTP Requests 32 URL Path 33 Query Parameters 34 Body 36 HTTP Header 37 Multiple Request Data 38 Which Method Is Best? 39 HTTP Responses 39 Status Code 39 Headers 40 Response Types 40 Type Conversion 41 Model Types and response_model 42 Automated Documentation 43 Complex Data 47 Review 47 4. Async, Concurrency, and Starlette Tour 49 Preview 49 Starlette 49 Types of Concurrency 50 Distributed and Parallel Computing 50 Operating System Processes 50 Operating System Threads 51 Green Threads 51 Callbacks 51 Python Generators 52 Python async, await, and asyncio 53 FastAPI and Async 55 Using Starlette Directly 57 Interlude: Cleaning the Clue House 57 Review 59 5. Pydantic, Type Hints, and Models Tour 61 Preview 61 Type Hinting 61 Data Grouping 64 Alternatives 68 A Simple Example 69 Validate Types 72 Validate Values 73 Review 75 6. Dependencies 77 Preview 77 What’s a Dependency? 77 Problems with Dependencies 78 Dependency Injection 78 FastAPI Dependencies 78 Writing a Dependency 79 Dependency Scope 80 Single Path 80 Multiple Paths 81 Global 81 Review 82 7. Framework Comparisons 83 Preview 83 Flask 83 Path 84 Query Parameter 85 Body 85 Header 86 Django 86 Other Web Framework Features 87 Databases 88 Recommendations 88 Other Python Web Frameworks 88 Review 89 Part III. Making a Website 8. Web Layer 93 Preview 93 Interlude: Top-Down, Bottom-Up, Middle-Out? 94 RESTful API Design 95 File and Directory Site Layout 97 The First Website Code 98 Requests 100 Multiple Routers 102 Build the Web Layer 103 Define Data Models 103 Stub and Fake Data 104 Create Common Functions Through the Stack 104 Create Fake Data 104 Test! 109 Using the FastAPI Automated Test Forms 110 Talking to the Service and Data Layers 112 Pagination and Sorting 113 Review 114 9. Service Layer 115 Preview 115 Defining a Service 115 Layout 116 Protection 116 Functions 116 Test! 118 Other Service-Level Stuff 120 Logging 120 Metrics, Monitoring, Observability 120 Tracing 120 Other 121 Review 121 10. Data Layer 123 Preview 123 DB-API 123 SQLite 125 Layout 127 Making It Work 127 Test! 131 Full Tests 131 Unit Tests 140 Review 142 11. Authentication and Authorization 143 Preview 143 Interlude 1: Do You Need Authentication? 144 Authentication Methods 145 Global Authentication: Shared Secret 145 Simple Individual Authentication 148 Fancier Individual Authentication 149 OAuth2 150 User Model 151 User Data Layer 151 User Fake Data Layer 153 User Service Layer 154 User Web Layer 156 Test! 158 Top Layer 158 Authentication Steps 158 JWT 159 Third-Party Authentication: OIDC 159 Authorization 160 Middleware 161 CORS 162 Third-Party Packages 163 Review 163 12. Testing 165 Preview 165 Web API Testing 165 Where to Test 166 What to Test 166 Pytest 167 Layout 168 Automated Unit Tests 168 Mocking 168 Test Doubles and Fakes 171 Web 173 Service 175 Data 177 Automated Integration Tests 178 The Repository Pattern 179 Automated Full Tests 180 Security Testing 182 Load Testing 182 Review 183 13. Production 185 Preview 185 Deployment 185 Multiple Workers 186 HTTPS 187 Docker 187 Cloud Services 188 Kubernetes 188 Performance 188 Async 188 Caches 189 Databases, Files, and Memory 189 Queues 189 Python Itself 190 Troubleshooting 190 Kinds of Problems 190 Logging 191 Metrics 191 Review 191 Part IV. A Gallery 14. Databases, Data Science, and a Little AI 195 Preview 195 Data Storage Alternatives 195 Relational Databases and SQL 196 SQLAlchemy 197 SQLModel 198 SQLite 199 PostgreSQL 199 EdgeDB 199 Nonrelational (NoSQL) Databases 200 Redis 200 MongoDB 200 Cassandra 200 Elasticsearch 201 NoSQL Features in SQL Databases 201 Database Load Testing 201 Data Science and AI 203 Review 205 15. Files 207 Preview 207 Multipart Support 207 Uploading Files 207 File() 208 UploadFile 209 Downloading Files 210 FileResponse 210 StreamingResponse 211 Serving Static Files 211 Review 213 16. Forms and Templates 215 Preview 215 Forms 215 Templates 217 Review 220 17. Data Discovery and Visualization 221 Preview 221 Python and Data 221 PSV Text Output 222 csv 222 python-tabulate 223 pandas 224 SQLite Data Source and Web Output 225 Chart/Graph Packages 225 Chart Example 1: Test 226 Chart Example 2: Histogram 228 Map Packages 229 Map Example 230 Review 232 18. Games 233 Preview 233 Python Game Packages 233 Splitting Game Logic 234 Game Design 234 Web Part One: Game Initialization 235 Web Part Two: Game Steps 236 Service Part One: Initialization 238 Service Part Two: Scoring 238 Test! 239 Data: Initialization 240 Let’s Play Cryptonamicon 240 Review 242 A. Further Reading 243 B. Creatures and Humans 247 Index 253
Lubanovic Bill / Любанович Билл - FastAPI: Modern Python Web Development / FastAPI: Современная веб-разработка на Python [2024, PDF, EPUB, ENG] download torrent for free and without registration
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum