requests
WebHTTP via micropip
What is requests?
Requests is the most popular Python HTTP library, used to send HTTP/1.1 requests elegantly and simply. With it you can GET, POST, PUT, DELETE, and more — handling authentication, cookies, redirects, and timeouts with a clean, Pythonic API.
In PyRun, the requests library is made available via Pyodide's micropip system. It uses the browser's native fetch API under the hood, so requests to CORS-enabled endpoints work seamlessly. This makes it perfect for querying public APIs, exploring REST endpoints, and practising HTTP concepts without any local setup.
Code Example
Fetch data from a public REST API endpoint.
HTTP GET Request
Try in Editorimport requests
import json
url = "https://jsonplaceholder.typicode.com/todos/1"
print(f"Fetching: {url}\n")
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print("Status:", response.status_code)
print("Response:")
print(json.dumps(data, indent=2))
else:
print(f"Error: {response.status_code}")Why run requests in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet