
Beginner
Fetch Data from a REST API with Python (No Libraries Needed)
Use Python’s standard library to request JSON from a public API and print the fields you need.
15 min 3 steps Python
Send prompts to a model running on your own machine through Ollama’s local HTTP API.
20 min2 stepsPublished

ollama pull llama3.2ollama listYou should see the models you downloaded. Ollama listens on http://localhost:11434.
import json
import urllib.request
payload = {
"model": "llama3.2",
"prompt": "Give me three tips for writing clear emails.",
"stream": False,
}
request = urllib.request.Request(
"http://localhost:11434/api/generate",
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(request, timeout=120) as response:
answer = json.load(response)
print(answer["response"])Start Ollama (open the app, or run `ollama serve`).
Download it first with `ollama pull llama3.2`.

Use Python’s standard library to request JSON from a public API and print the fields you need.
15 min 3 steps Python