6. Verify your setup
Time to test everything together. A short verification script exercises Python, pip, your virtual environment, the requests library, and your first API call all at once. If it passes, you're ready for Chapter 3.
The setup verification script
Create a new file called setup_check.py in your api-projects folder and add this code:
"""
Development Environment Verification Script
This script tests that your Python environment is correctly configured
"""
import sys
def test_python_version():
"""Check Python version meets minimum requirements"""
version = sys.version_info
print(f"✓ Python {version.major}.{version.minor}.{version.micro}")
if (version.major, version.minor) >= (3, 10):
return True
else:
print("✗ Python 3.10 or higher required")
return False
def test_virtual_environment():
"""Check if running in a virtual environment"""
in_venv = hasattr(sys, 'real_prefix') or (
hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix
)
if in_venv:
print("✓ Virtual environment active")
return True
else:
print("✗ Virtual environment not active")
return False
def test_requests_library():
"""Check if requests library is installed"""
try:
import requests
print(f"✓ requests library {requests.__version__}")
return True
except ImportError:
print("✗ requests library not found")
return False
def test_api_connection():
"""Test actual API connection"""
try:
import requests
response = requests.get("https://httpbin.org/get", timeout=5)
if response.status_code == 200:
print("✓ API connection successful")
return True
else:
print(f"✗ API returned status code {response.status_code}")
return False
except requests.exceptions.RequestException as e:
print(f"✗ API connection failed: {e}")
return False
def run_all_tests():
"""Run all verification tests"""
print("=" * 50)
print("Development Environment Verification")
print("=" * 50)
print()
results = []
results.append(test_python_version())
results.append(test_virtual_environment())
results.append(test_requests_library())
results.append(test_api_connection())
print()
print("=" * 50)
if all(results):
print("✓ All tests passed! You're ready for Chapter 3!")
else:
print("⚠ Some tests failed. Please review the issues above.")
print("=" * 50)
if __name__ == "__main__":
run_all_tests()
The script makes a test call to httpbin.org, a public service you'll meet properly in Chapter 3.
python setup_check.py
==================================================
Development Environment Verification
==================================================
✓ Python 3.13.12
✓ Virtual environment active
✓ requests library 2.32.x
✓ API connection successful
==================================================
✓ All tests passed! You're ready for Chapter 3!
==================================================
If all four tests pass, your development environment is correctly configured and you're ready to start building real API applications in Chapter 3.
What if tests fail?
If you see any ✗ marks, here's what they mean:
- Python version test fails. Your Python version is below 3.10. Install a newer version using the guide in Troubleshooting Issue 1.
- Virtual environment test fails. You're not running in an activated virtual environment. Activate it with
source my-first-api-env/bin/activate(macOS/Linux) ormy-first-api-env\Scripts\activate(Windows), then run the test again. - requests library not found. The requests library isn't installed. Make sure your virtual environment is active, then run
python -m pip install requests. - API connection failed. Your internet connection might be down, or httpbin.org might be temporarily unavailable. Try again in a few minutes.
✗ Virtual environment not active
This means Python is running outside your project environment. Activate your virtual environment before working on projects, then run the script again.
If the checks pass, your setup is ready. The review page summarises the habits to take forward, and the troubleshooting page is there if any test failed.