Chapter 21 Further Reading: Working with APIs and External Data Services
Official Documentation
Requests library documentation https://requests.readthedocs.io/en/latest/
The official docs are excellent. Pay particular attention to the "Advanced Usage" section covering sessions, authentication, prepared requests, and streaming responses. The "Authentication" section covers all authentication patterns including custom auth classes.
Python os module documentation
https://docs.python.org/3/library/os.html
Specifically the os.environ section. Understanding environment variables at the Python level is essential for managing credentials across different deployment environments.
python-dotenv documentation https://saurabh-kumar.com/python-dotenv/
Concise documentation for the .env file loading library. Covers .env file syntax, loading order, and how to override existing environment variables.
API Design and REST
Roy Fielding's REST dissertation (Chapter 5) https://ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
This is the original academic document defining REST. You do not need to read all of it, but Chapter 5 is short and gives you the actual definition from the person who coined the term. Most "REST" APIs you encounter are not fully RESTful by this definition, but understanding the original concept is useful.
HTTP Status Codes — MDN Web Docs https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
The most readable reference for HTTP status codes, with explanations of when each code should be used and what it means for the client. Bookmark this — you will reference it regularly.
JSON specification https://www.json.org/json-en.html
A one-page specification for the JSON format. Worth reading once to understand the complete data model, particularly the distinction between JSON numbers and how they map to Python int vs. float.
Free APIs Used in This Chapter
ExchangeRate-API / open.er-api.com https://www.exchangerate-api.com/docs/free
Documentation for the free exchange rate API used throughout the chapter. The free tier requires no registration and no API key for basic USD-based queries.
Open-Meteo https://open-meteo.com/en/docs
Complete documentation for the Open-Meteo weather API. The docs include an interactive parameter explorer that lets you preview the response structure for any combination of parameters. Completely free, no API key required.
NewsAPI https://newsapi.org/docs
Documentation for the news search API. The free developer tier supports 100 requests per day and full article search. Requires registration. Note the free tier restriction: articles older than 30 days require a paid plan.
Alpha Vantage https://www.alphavantage.co/documentation/
Documentation for the stock and company data API. Free tier: 25 requests per day, 5 per minute. The documentation includes a useful function reference showing all available data types.
RestCountries https://restcountries.com/
Documentation for the countries data API. Completely free, no API key required. Useful for any project involving international business, geography, or currency data.
Books and Courses
"APIs: A Strategy Guide" by Daniel Jacobson, Greg Brail, Dan Woods (O'Reilly)
More focused on API design and business strategy than implementation, but useful for understanding why APIs are structured the way they are. Helps you read API documentation more critically.
"Web Scraping with Python" by Ryan Mitchell (O'Reilly)
Covers the complementary skill to APIs: when there is no API and you need to extract data from HTML. Chapter 20 of this textbook covers web scraping, but Mitchell's book goes deeper into complex cases, JavaScript-rendered pages, and large-scale scraping.
"Designing Web APIs" by Brenda Jin, Saurabh Sahni, Amir Shevat (O'Reilly)
Focuses on designing APIs rather than consuming them. Reading this book will improve your ability to read API documentation by helping you understand the design decisions behind it.
Going Deeper: Advanced Topics
OAuth2 and Authentication Flows
When you connect to major platforms (Google, Microsoft, Salesforce, QuickBooks), you will encounter OAuth2 — a more complex authentication flow that involves browser redirects, authorization codes, and access token refresh. The requests-oauthlib library simplifies this considerably.
Requests-OAuthlib documentation: https://requests-oauthlib.readthedocs.io/
GraphQL: An Alternative to REST
Some newer APIs use GraphQL instead of REST. Rather than multiple endpoints for different resources, GraphQL exposes a single endpoint where you specify exactly which fields you want to retrieve. It requires learning a query language but eliminates over-fetching (receiving more data than you need).
GraphQL introduction: https://graphql.org/learn/
The gql Python library provides a clean interface for GraphQL APIs: https://gql.readthedocs.io/
Asynchronous API Calls
When you need to make hundreds or thousands of API calls, making them sequentially (one at a time) is slow. Python's asyncio and the httpx library allow you to make multiple API calls concurrently.
httpx documentation (async-capable requests replacement): https://www.python-httpx.org/
API Rate Limit Management at Scale
For larger projects, the ratelimit library provides function decorators that automatically enforce rate limits:
pip install ratelimit
Documentation: https://pypi.org/project/ratelimit/
Caching API Responses
If your script calls the same API endpoints repeatedly with the same parameters, caching the responses reduces API calls and speeds up development. The requests-cache library adds transparent caching to the requests library.
requests-cache documentation: https://requests-cache.readthedocs.io/
Practice and Discovery
Public APIs GitHub repository https://github.com/public-apis/public-apis
A curated, categorized list of hundreds of free and public APIs. Organized by category (finance, news, weather, government data, geolocation, etc.). A useful resource when you need data for a project and want to find what's available without a paid subscription.
Postman https://www.postman.com/
A GUI tool for exploring and testing APIs interactively before writing code. Invaluable for understanding a new API's response structure, testing authentication configurations, and debugging requests that aren't working as expected. The free tier is sufficient for individual use.
RapidAPI Hub https://rapidapi.com/hub
A marketplace that provides a unified interface to thousands of APIs. Useful for discovering APIs by category and comparing different providers for the same data type (e.g., multiple weather API providers in one place).
Staying Current
API designs, rate limits, and pricing change frequently. For the APIs referenced in this chapter:
- Check the official documentation before starting any significant project
- Sign up for the provider's developer newsletter if available — breaking changes are usually announced
- Check the API's status page for known outages before debugging your code
- Review the terms of service for any API you use commercially — "free for personal use" often has restrictions on commercial applications
Further reading compiled for "Python for Business for Beginners: Coding for Every Person," Chapter 21