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.
import 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
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.