A Streamlit app may need information from another website, such as a daily joke or movie details. `requests` is a Python library for sending HTTP requests to an API and working with its responses. It provides a simpler interface than handling HTTP with Python alone. section 5.3.2 section 11.1.1
A basic API call has a few parts:
- Install the library with `pip install requests`; use `pip show requests` to check the installation. section 5.3.2
- Call `requests.get(url)` to send a GET request. The returned `Response` holds the server’s reply; `response.text` reads its body as a string. section 5.3.2
- Pass a dictionary through `headers` when an API requires a header such as `X-Api-Key`, or through `params` when it expects URL query parameters. section 5.3.2 section 11.1.1
A missing key is useful feedback
A joke API request without its required key returns `<Response [400]>` and `{"error": "Missing API Key."}` in `response.text`. Supply the key in the `X-Api-Key` header, and the response instead contains a joke. Keep real credentials out of committed code. section 5.3.2 section 5.5
>>> import requests
>>> params = {'api_key': 'Replace with your API key', 'query': 'ferris bueller'}
>>> response = requests.get('https://api.themoviedb.org/3/search/movie', params=params)
>>> response.json()
For a movie search, `params` carries the API key and search term. `response.json()` reads the JSON reply as Python data; its `results` list contains movie records. section 11.1.1
For deployment, list `requests` in `requirements.txt` alongside other dependencies. You can specify a compatible version or pin an exact one so a difference between development and production does not break the app. Store API credentials separately: use `st.secrets` locally and configure production secrets in Streamlit Community Cloud. section 5.4.1 section 5.5





