
Intermediate
Call a Local Language Model from Python
Send prompts to a model running on your own machine through Ollama’s local HTTP API.
20 min 2 steps Local AI
Use Python’s standard library to request JSON from a public API and print the fields you need.
15 min3 stepsPublished

A REST API returns data at a URL, usually as JSON. GitHub’s public API returns information about any public repository without a key (with a low rate limit).
Create a file named repo_info.py:
import json
import urllib.request
URL = "https://api.github.com/repos/python/cpython"
request = urllib.request.Request(URL, headers={"User-Agent": "virtuvia-tutorial"})
with urllib.request.urlopen(request, timeout=10) as response:
data = json.load(response)
print(f"Repository: {data['full_name']}")
print(f"Description: {data['description']}")
print(f"Default branch: {data['default_branch']}")python repo_info.pyRepository: python/cpython
Description: The Python programming language
Default branch: mainUnauthenticated requests are limited per hour. Wait, or use an access token as described in GitHub’s documentation.
Check your internet connection or proxy settings.

Send prompts to a model running on your own machine through Ollama’s local HTTP API.
20 min 2 steps Local AI