Python Development: Requests, Testing, and Workflow

·28m 38s
Shared point

Enhancing requests Usage

Beyond basic API calls, Python's requests library offers advanced functionality for robust development.
Session Hooks: Utilize hooks to automate processes such as calling raise_for_status() on every request.
Base URLs: Simplify complex API integrations by using Request Toolbelt to define base URLs, reducing code duplication and path errors.
Retry Logic: Implement custom retry policies to handle transient network failures effectively.
User-Agent Spoofing: Manage headers to test how web services respond to different clients or to bypass certain security filters.

Advanced Testing Strategies

Testing is critical for stable codebases, and several tools can improve the development experience.
Fluent Assertions: A library that enables readable, fluent APIs for testing, allowing developers to chain assertions (e.g., .isnotnone.isfloat) into a single, clean line.
VCR.py: This tool simplifies testing against external APIs by recording HTTP interactions into "cassettes" (YAML files). This ensures tests are deterministic, offline-capable, and significantly faster.
GitHub Actions: A powerful, native CI/CD solution for Python projects. It facilitates running tests across multiple environments and Python versions with simple YAML configuration.

Code Security and Optimization

"Debugging: Being the detective in a crime movie where you are also the murderer."

Security and clean code are foundational to high-quality software.
Bento: An automated analysis tool that scans Flask applications (and eventually others) to identify security vulnerabilities, such as insecure HTTP headers or improper configuration, before they reach production.
Feature Appreciation: Reflecting on Python's most expressive features, including list comprehensions, negative indexing, and f-strings, which contribute to why Python remains a favorite language for developers.

Topics

Chapters

6 chapters
Python Bytes
AI chat — answers grounded in episodes