Introduction to APIs in Python
Chris Ramakers
Engineering Manager


| Method | Ease of Implementation | Security Rating |
|---|---|---|
| Basic Authentication | ⭐ ⭐ ⭐ ⭐ ⭐ | ⭐ ☆ ☆ ☆ ☆ |
| API key/token Authentication | ⭐ ⭐ ⭐ ⭐ ☆ | ⭐ ⭐ ☆ ☆ ☆ |
| JWT Authentication | ⭐ ⭐ ⭐ ☆ ☆ | ⭐ ⭐ ⭐ ⭐ ☆ |
| OAuth 2.0 | ⭐ ⭐ ☆ ☆ ☆ | ⭐ ⭐ ⭐ ⭐ ⭐ |
Tip: Check the documentation of the API you are using to learn which method to use for authentication!

# This will automatically add a Basic Authentication header before sending the request
requests.get('http://api.music-catalog.com', auth=('username', 'password'))
http://api.music-catalog.com/albums?access_token=faaa1c97bd3f4bd9b024c708c979feca
params = {'access_token': 'faaa1c97bd3f4bd9b024c708c979feca'}
requests.get('http://api.music-catalog.com/albums', params=params)

headers = {'Authorization': 'Bearer faaa1c97bd3f4bd9b024c708c979feca'}
requests.get('http://api.music-catalog.com/albums', headers=headers)
Introduction to APIs in Python