Modern Python Web Development
Bill Lubanovic

#FastAPI
#Python
#Web_Development
#Async
#framework
اگه فریمورکهای وب پایتون رو به ماشین تشبیه کنیم، فلسک (Flask) یه ماشین شهری جمع و جوره که کارت رو راه میندازه، جنگو (Django) یه اتوبوس دوطبقه با کلی امکاناته، ولی FastAPI یه ماشین مسابقه فرمول یکه که تازه از کارخونه در اومده! 🏎️💨
این کتاب بلیط شما برای نشستن پشت فرمون این ماشین جدیده. بیا ببینیم چی تو چنته داره:
FastAPI یک فریمورک جوانه ولی در عین حال محکمه که از ویژگیهای جدیدتر پایتون در یک طراحی تمیز بهره میبره. همونطور که از اسمش پیداست، FastAPI واقعاً سریع هست و با فریمورکهای مشابه در زبانهایی مثل گولنگ (Golang) رقابت میکنه. با این کتاب عملی، توسعهدهندگانی که با پایتون آشنا هستن یاد میگیرن که چطور FastAPI بهشون اجازه میده در زمان کمتر و با کد کمتر، کارهای بیشتری انجام بدن.
نویسنده، بیل لوبانوویچ (Bill Lubanovic)، تمام فوت و فنهای توسعه با FastAPI رو با راهنماهای کاربردی در موضوعات مختلف مثل فرمها، دسترسی به دیتابیس، گرافیک، نقشه و چیزای دیگه که شما رو فراتر از اصول اولیه میبرن، پوشش میده. این کتاب همچنین راهنماهایی داره که شما رو سریعاً با APIهای RESTful، اعتبارسنجی داده، احراز هویت و بهینهسازی عملکرد آشنا میکنه. با شباهتهایی که به فریمورکهایی مثل فلسک و جنگو داره، شروع کار با FastAPI براتون خیلی راحت خواهد بود.
🎯 در طول این کتاب شما:
✅ یاد میگیرید چطور با FastAPI وباپلیکیشن بسازید.
🤔 تفاوتهای بین FastAPI، Starlette و Pydantic رو درک میکنید (این سه تفنگدار، قدرت اصلی FastAPI هستن).
✌️ دو ویژگی اصلی که FastAPI رو متمایز میکنه یاد میگیرید: توابع ناهمگام (asynchronous) و بررسی و اعتبارسنجی نوع دادهها (data type checking).
🐍 با ویژگیهای جدید پایتون +3.8، به خصوص Type Annotations، آشنا میشید.
⚡ تفاوت بین پایتون همگام (sync) و ناهمگام (async) رو میفهمید.
🌐 یاد میگیرید چطور به APIها و سرویسهای خارجی متصل بشید.
بخش اول: چه خبره؟ (نگاهی به دنیای مدرن)
فصل ۱: وب مدرن
فصل ۲: پایتون مدرن
بخش دوم: یه گشت و گذار در دنیای FastAPI
فصل ۳: گشتی در FastAPI
فصل ۴: گشتی در Async، Concurrency و Starlette
فصل ۵: گشتی در Pydantic، Type Hints و مدلها
فصل ۶: وابستگیها (Dependencies)
فصل ۷: مقایسه فریمورکها
بخش سوم: ساخت یک وبسایت (از صفر تا صد!)
فصل ۸: لایه وب
فصل ۹: لایه سرویس
فصل ۱۰: لایه داده
فصل ۱۱: احراز هویت و مجوزها
فصل ۱۲: تستنویسی
فصل ۱۳: بردن به پروداکشن
بخش چهارم: گالری پروژهها (این بخش عالیه!)
فصل ۱۴: دیتابیسها، علم داده و یه کوچولو هوش مصنوعی
فصل ۱۵: کار با فایلها
فصل ۱۶: فرمها و تمپلیتها
فصل ۱۷: کشف و مصورسازی دادهها
فصل ۱۸: بازیسازی
این بخش از مقدمه کتاب رو خود نویسنده، که یه برنامهنویس کهنهکاره، تعریف میکنه و خیلی جالبه:
این یک معرفی عملگرایانه به FastAPI است… و داستانی از اینکه چطور گاهی اوقات، چیزهای براق و جدیدی که بهشان برمیخوریم، میتوانند بسیار مفید از آب دربیایند. داشتن یک گلوله نقرهای وقتی با یک گرگینه روبرو میشوی خیلی خوب است. (و شما در این کتاب با گرگینهها روبرو خواهید شد.) 😉
من از دهه ۷۰ برنامهنویسی رو شروع کردم. وقتی در سال ۱۹۷۷ با یونیکس و C آشنا شدم، حس کردم این یونیکس مثل اینکه قراره بگیره.
وقتی در سال ۱۹۹۳ مرورگر Mosaic در اینترنت پخش شد، حس کردم این وب هم مثل اینکه قراره بگیره.
چند سال بعد که با پایتون کار کردم و دیدم چقدر سریع میتونم باهاش کار کنم، حس کردم این پایتونه هم مثل اینکه قراره بگیره.
چند سال پیش، چشمم به یه چیز براق جدید خورد: یک فریمورک وب پایتون به نام FastAPI. از طراحی و فکری که پشتش بود شگفتزده شدم. این یک پروژه برای سرگرمی نبود، بلکه یک فریمورک جدی برای توسعه واقعی بود. و حالا حس میکنم این FastAPI هم مثل
اینکه قراره بگیره!
ما یک API بزرگ بیومدیکال رو با FastAPI بازنویسی کردیم و اونقدر خوب پیش رفت که تیممون اون رو برای همه پروژههای جدید انتخاب کرد. ما فهمیدیم که داریم کد بهتری، سریعتر و با باگهای کمتری مینویسیم.
پس چرا با وجود داکیومنتهای عالی خود FastAPI، یک کتاب بنویسیم؟
این کتاب قرار نیست جامع و خستهکننده باشه. قراره مفید باشه—تا به شما کمک کنه سریع ایدههای اصلی FastAPI رو یاد بگیرید و به کار ببرید. من تکنیکهایی که پیدا کردنشون نیاز به کمی کارآگاهبازی داشت رو به شما نشون میدم و در مورد بهترین شیوههای روزمره بهتون مشاوره میدم.
بیل لوبانوویچ (Bill Lubanovic) بیش از چهل ساله که توسعهدهنده است و در لینوکس، وب و پایتون تخصص داره. کتابهای معروفی مثل “Introducing Python” از انتشارات O’Reilly رو نوشته. وقتی آدمی با این همه تجربه میگه یه چیزی آینده داره، باید حرفش رو جدی گرفت!
خلاصه کلام:
اگه از سرعت پایین یا پیچیدگی فریمورکهای فعلی خسته شدید و دنبال یه راه مدرن، سریع، تمیز و لذتبخش برای ساخت API و وباپلیکیشن با پایتون هستید، این کتاب از یه استاد کارکشته، بهترین نقطه برای شروعه. 🚀💯
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:
Table of Contents
Part I. What's New?
Chapter 1. The Modern Web
Chapter 2. Modern Python
Part II. A FastAPI Tour
Chapter 3. FastAPI Tour
Chapter 4. Async, Concurrency, and Starlette Tour
Chapter 5. Pydantic, Type Hints, and Models Tour
Chapter 6. Dependencies
Chapter 7. Framework Comparisons
Part Ill. Making a Website
Chapter 8. Web Layer
Chapter 9. Service Layer
Chapter 10. Data layer
Chapter 11 . Authentication and Authorization
Chapter 12. Testing
Chapter 13. Production
Part IV. A Gallery
Chapter 14. Databases, Data Science, and a little Al
Chapter 15. Files
Chapter 16. Forms and Templates
Chapter 17. Data Discovery and Visualization
Chapter 18. Games
This is a pragmatic introduction to FastAPI—a modern Python web framework. It’s also a story of how, now and then, the bright and shiny objects that we stumble across can turn out to be very useful. A silver bullet is nice to have when you encounter a werewolf. (And you will encounter werewolves later in this book.)
I started programming scientific applications in the mid-1970s. And after I first met Unix and C on a PDP-11 in 1977, I had a feeling that this Unix thing might catch on.
In the ’80s and early ’90s, the internet was still noncommercial, but already a good source for free software and technical info. And when a web browser called Mosaic was distributed on the baby open internet in 1993, I had a feeling that this web thing might catch on.
When I started my own web development company a few years later, my tools were the usual suspects at the time: PHP, HTML, and Perl. On a contract job a few years later, I finally experimented with Python and was surprised at how quickly I was able to access, manipulate, and display data. In my spare time over two weeks, I was able to replicate most of a C application that had taken four developers a year to write. Now I had a feeling that this Python thing might catch on.
After that, most of my work involved Python and its web frameworks, mostly Flask and Django. I particularly liked the simplicity of Flask and preferred it for many jobs. But just a few years ago, I spied something glinting in the underbrush: a new Python web framework called FastAPI, written by Sebastián Ramírez.
As I read his (excellent) documentation, I was impressed by the design and thought that had gone into it. In particular, his history page showed how much care he had taken evaluating alternatives. This was not an ego project or a fun experiment, but a serious framework for real-world development. Now I had a feeling that this FastAPI thing might catch on.
I wrote a biomedical API site with FastAPI, and it went so well that a team of us rewrote our old core API with FastAPI in the next year. This is still in production and has held up well. Our group learned the basics that you’ll read in this book, and all felt that we were writing better code, faster, with fewer bugs. And by the way, some of us had not written in Python before, and only I had used FastAPI.
So when I had an opportunity to suggest a follow-up to my Introducing Python book to O’Reilly, FastAPI was at the top of my list. In my opinion, FastAPI will have at least the impact that Flask and Django have had, and maybe more.
As I’ve mentioned, the FastAPI website itself provides world-class documentation, including many details on the usual web topics: databases, authentication, deployment, and so on. So why write a book?
This book isn’t meant to be exhaustive because, well, that’s exhausting. It is meant to be useful—to help you quickly pick up the main ideas of FastAPI and apply them. I will point out various techniques that required some sleuthing and offer advice on day-to-day best practices.
I start each chapter with a Preview of what’s coming. Next, I try not to forget what I just promised, offering details and random asides. Finally, there’s a brief digestible Review.
As the saying goes, “These are the opinions on which my facts are based.” Your experience will be unique, but I hope that you will find enough of value here to become a more productive web developer.
Bill has been a developer for over forty years, specializing in Linux, the web, and Python. He coauthored the O'Reilly book Linux System Administration, and wrote both editions of Introducing Python. He discovered FastAPI a few years ago, and with his team used it to rewrite a large biomedical research API. The experience was so positive that they've adopted it for all new projects.









