Statistics
348
Views
73
Downloads
0
Donations
Uploader

高宏飞

Shared on 2025-08-04
Support
Share

AuthorRyan Day

To succeed in AI and data science, you must first master APIs. API skills are essential for AI and data science success. With this practical book, data scientists and software developers will gain hands-on experience developing and using APIs with the Python programming language and popular frameworks like FastAPI and StreamLit. Part 1 takes you step-by-step through coding projects to build APIs using Python and FastAPI and deploy them in the cloud. Part 2 teaches you to consume APIs in a data science project using industry-standard tools. And in Part 3, you'll use ChatGPT, the LangChain framework, and other tools to access your APIs with generative AI and large language models (LLMs). As you complete the chapters in the book, you'll be creating a professional online portfolio demonstrating your new skill with APIs, AI, and data science.

Tags
No tags
Publisher: O'Reilly Media
Publish Year: 2025
Language: 中文
File Format: PDF
File Size: 8.8 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Praise for Hands-On APIs for AI and Data Science Hands-On APIs for AI and Data Science is an awesome contribution to the data science community. Day provides a structured guide to a core topic data scientists often learn too late: delivering solutions to users. You’ll master APIs, but along the way, you’ll also add a dozen more tools to your data science toolbox. Do yourself a favor—add this book to your data science library for your continued professional development and become a better, more effective data scientist! —Alex Gutman, author of Becoming a Data Head: How to Think, Speak, and Understand Data Science, Statistics, and Machine Learning Day takes the reader through a thorough, yet clear, roadmap of building APIs, using an extremely topical industry (fantasy football) as the example. This is essential reading for anyone looking to round out their data science capabilities as an individual or better serve their customers as a company. —Eric Eager, vice president of football analytics, Carolina Panthers With the growing importance of APIs in data science and AI, this book is an essential resource for gaining practical insights. It prioritizes understanding your consumers, which is essential for designing and building great APIs. This book is filled with actionable examples and expert guidance. It is an invaluable read for anyone looking to create impactful APIs. —James Gough, author of Mastering API Architecture
This book is a fantastic resource for data scientists who need to use APIs, whether you’re building them or accessing data through them. It’s very practical, it’s fun to read, and it’ll be extremely useful to any data scientist who wants to improve their software engineering skills. —Catherine Nelson, author of Software Engineering for Data Scientists Ryan offers a comprehensive guide for data scientists at all levels that blends deep technical expertise with practical strategies on mastering API usage. —Kris Rowley, CSBS chief data officer and Data Foundation board member Hands-On APIs for AI and Data Science avoids the biggest mistake I see in technical books: it provides practical lessons grounded in how technology is actually used. With fun examples from sports data, author Ryan Day walks through multiple angles of a single API project. Anyone in data science would be wise to build their career on the foundations Ryan has laid out in this book. —Adam DuVander, EveryDeveloper Ryan does a great job teaching you how to both be a better API user and creator using engaging examples from fantasy sports. —Richard Erickson, data scientist and O’Reilly author of Football Analytics with Python and R
Ryan Day’s book is an essential resource for football analytics professionals, from newcomers to seasoned experts. This book equips readers with the tools to build and deploy APIs that power advanced data workflows, from player performance modeling to real-time fantasy football applications. With Ryan’s guidance, you’ll learn to integrate APIs into your analytics toolbox and take your insights to the next level. —Amelia Probst, data scientist, Pro Football Focus If you’re looking to skill up on APIs and understand how important they are to building effective AI applications, this book delivers a mix of theory and hands-on exercise to get you there. —Jeff Frederickson, software engineer This book is a must-have for Python developers seeking to build powerful and efficient APIs, utilizing the latest FastAPI technology. With clear explanations and practical examples, it guides readers through every step of API creation and deployment, making complex topics approachable and actionable. —Megan Silvey, founder and data science consultant, Silvey Solutions Hands-On APIs for AI and Data Science is an essential read for today’s data and IT professionals aiming to keep pace in our ever-evolving data-driven world. Ryan’s ability to present complex concepts through hands-on application makes it easy for readers to apply what they’ve learned in practice, in real-world scenarios, or even on the job. Highly recommended for beginners and seasoned professionals, and you may even learn a little fantasy football along the way! —Richard Bright, enterprise data architect
Hands-On APIs for AI and Data Science Python Development with FastAPI Ryan Day
Hands-On APIs for AI and Data Science by Ryan Day Copyright © 2025 Ryan Day. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800- 998-9938 or corporate@oreilly.com. Acquisitions Editor: Michelle Smith Development Editor: Corbin Collins Production Editor: Aleeya Rahman Copyeditor: Tove Innis Proofreader: Audrey Doyle Indexer: Sue Klefstad Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea March 2025: First Edition
Revision History for the First Edition 2025-03-04: First Release See http://oreilly.com/catalog/errata.csp? isbn=9781098164416 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Hands-On APIs for AI and Data Science, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-098-16441-6 [LSI]
Dedication For Allison
Preface To succeed in AI, first master APIs. Becoming skilled at APIs is more valuable than ever, thanks largely to the growth of artificial intelligence, machine learning, and data science. But learning a such wide-ranging skill is intimidating. How is it to be done? You can take comfort in the fact that you don’t have to learn every skill, and certainly not all at once. Pick up one skill at a time through hands-on practice. Each skill you learn makes the next one easier, like building blocks. Why Should You Read This Book? If you’re reading this book, you want to build your skills. I have found that the best way to do that is through hands-on coding. If you do your coding in the open by publishing your code in a public repository and blogging and sharing what you create, you can pass along your knowledge to help others. You’ll also build a solid portfolio of work that provides a concrete demonstration of your expertise to employers.
Who This Book Is For Since this book sits at the intersection of APIs, AI, and data science, it will be valuable to several types of readers. Data Scientists Data scientists use APIs all the time, so there’s a temptation to think there’s nothing new to learn about using APIs. Isn’t calling an API just a few lines of code? It’s true that making one call to a REST API is a simple task, which is certainly a reason they have become so prevalent. But using an API in a way that is robust and resilient—and that doesn’t cause problems for the provider—requires more care. This book will teach some techniques you may not have learned yet, such as: Developing and deploying APIs Creating software development kits (SDKs) and API clients Creating and publishing Python packages to PyPI Publishing machine learning models as APIs Creating Streamlit data apps Creating Airflow data pipelines Creating generative AI applications using LangChain and ChatGPT
API Developers and Designers API developers and designers can learn how to enhance their APIs for important new audiences. They’ll learn about data scientists: the jobs they do, the tasks they perform, and the API features they love. They’ll also learn about generative AI applications: how they call APIs and what features they need in an API. And the hands-on examples will teach a variety of new skills: Creating Python APIs with FastAPI, SQLAlchemy, and Pydantic Containerizing APIs with Docker Deploying APIs to cloud hosts Creating Python SDKs and publishing to PyPI Creating generative AI applications using LangChain and ChatGPT Job Seekers and Role Changers The skills above are valuable in the marketplace, so learning them can help you find your first role or a new role in data science or software development. This book is arranged around building portfolio projects, which will give you specific goals to accomplish, and tangible evidence of your work. Creating Portfolio Projects While completing the book, you’ll create three portfolio projects that you can publish in GitHub repositories to
show the work you’ve done. Table P-1 explains the purpose and source repository you will use as a basis for your project. Table P-1. New tools or services used in this chapter Project Purpose Part I portfolio project Creating a Python API and SDK Part II portfolio project Creating data science apps using Streamlit, Airflow, and Jupyter Notebooks Part III portfolio project Creating a machine learning API and generative AI application using scikit- learn, ONNX, LangChain, and ChatGPT TIP When you complete your projects, please reach out and let me know at ryan@handsonapibook.com or on LinkedIn so I can celebrate your accomplishment with you. I look forward to seeing what you build. Using This Book Instead of reading this book from beginning to end, I recommend that you pick the skill you want to learn and start working through the chapter that teaches it. You can do this quickly in the following way:
1. Decide whether you want to start by creating an API (Part I), using APIs with data science (Part II), or using APIs with AI (Part III). 2. Follow the instructions in the introductory chapter of that part to clone the GitHub repository and launch a Codespace. 3. Follow the instructions in the relevant chapter and run the code. If I’ve done my job properly, each chapter can stand on its own. After you’ve learned one skill, look around and find another skill you want to learn, and do the same. The skills in this book are like building blocks: each piece you learn prepares you to understand the other parts more deeply. All of them together give you quite a substantial understanding of APIs in data science and AI.
What This Book Is Not This book doesn’t teach Python syntax to beginners. You will get the most from the coding examples if you have a foundational knowledge of Python. Although you can probably get the code to work by following the steps in each chapter, I suggest you begin with one of the excellent introductory Python books that O’Reilly publishes, such as Introducing Python, 3rd Edition, by Bill Lubanovic. This book also assumes a basic understanding of using the command-line terminal in Linux or Unix. You don’t need to be a Linux administrator, but you should be familiar with running commands in the terminal as a developer. (All the steps are explained, but when you run into an issue, you might get frustrated without some background in that environment.) The book introduces several useful Python frameworks such as FastAPI, Pydantic, Streamlit, Airflow, and LangChain. However, it does not address detailed topics necessary to run them in a production environment, such as security, performance, and infrastructure. I hope that you’ll enjoy the projects in this book enough that you’ll continue your learning using the references that I mention at the end of each chapter. Keep in mind that the services and tools in this book are changing rapidly, so depending on when you are reading this, some of the steps and figures may look a bit different.
Why Fantasy Football? If you were to sit down and rank hobbies that people obsess over the details of, fantasy sports and software development would both be near the top of that list. When you combine these hobbies, the possibilities are endless! —Joey Greco, creator of the Leeger stats application The portfolio projects in the book follow the story of an imaginary fantasy sports league host website: SportsWorldCentral.com. Through your projects, you will design and build APIs for data-focused users, then switch roles and build data science and generative AI applications using the APIs you created. As Joey Greco says so eloquently, fantasy sports was the natural choice for the scenario. (You’ll hear more from him later in the book.) Fantasy sports is a natural playground for data scientists, and fantasy websites use plenty of APIs. I’ve spent many hours over the years wading into both of those as a devoted (or addicted) fantasy manager. Fantasy managers are also fast adopters of any predictive or prescriptive analytics feature the fantasy websites give them. (If you doubt it, you haven’t watched a manager pick up two free agents and make three lineup changes to push their win probability from 45% to 53%.) Fantasy sports are a fun way to geek out on the overlap between AI, data science, and APIs. As you code your way through the book, I hope you have as much fun as I did writing it.
Get More Tips on APIs, AI, and Data Science The content in this book will be a really solid foundation for these topics, and I hope it raises your interest in learning more. To get more tips in this subject, you can subscribe to my newsletter by visiting https://handsonapibook.com. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context.
TIP This element signifies a tip or suggestion. NOTE This element signifies a general note. WARNING This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download in three repositories, one for each part: Part I: https://github.com/handsonapibook/api-book- part-one Part II: https://github.com/handsonapibook/api-book- part-two Part III: https://github.com/handsonapibook/api- book-part-three If you have a technical question or a problem using the code examples, please send email to support@oreilly.com. This book is here to help you get your job done. If example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant
portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Hands-On APIs for AI and Data Science by Ryan Day (O’Reilly). Copyright 2025 Ryan Day, 978-1-098-16441-6.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Online Learning NOTE For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in- depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+
other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-889-8969 (in the United States or Canada) 707-827-7019 (international or local) 707-829-0104 (fax) support@oreilly.com https://oreilly.com/about/contact.html We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/hands-on-api. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly- media Watch us on YouTube: https://youtube.com/oreillymedia
Acknowledgments I’m sure I’ll miss a few people, but thank you so much to everyone who has interacted with this content in the past year in articles, newsletters, and presentations. Your feedback has made the content better, and your encouragement and interest have kept me going. Extra- special thanks to the Data Science KC and Data Community DC for all of your feedback. I’m so grateful to the O’Reilly team who guided me through the process of writing this book. Thank you so much to the entire editorial staff. Special thanks to Michelle Smith, the acquisitions editor, and Corbin Collins, the development editor, for believing in the book and getting me to the finish line. Thank you, Chris Faucher, Aleeya Rahman, and Tove Innis, for your professional handling of the authoring process. I had so much fun interviewing experts for this book, and many of their stories are included in the chapters. Thanks to Joey Greco, Kyle Borgognoni, Zan Markhan, Alexandre Airvault, Francisco Goitia, Simon Yu, Robin Linacre, Bill Doerrfield, Samuel Colvin, Frank Kilcommins, Kade Halabuza, and Jim Higginbotham for sharing your expertise and enthusiasm for the technology and data. Thanks to Keith McCormick, who showed me the opportunities available in data science. Thank you so much to my technical reviewers: Richard Bright, Richard Erickson, Jeff Fredrickson, Amelia Probst, and Megan Silvey. You saved me from many embarrassing mistakes, and your technical expertise helped make the book much more accurate and valuable. Extra thanks to Richard Erickson, who guided me through the book
The above is a preview of the first 20 pages. Register to read the complete e-book.