ollama-python 0.4+: ollama.list() loop fails with KeyError: 'name'; models are pydantic objects whose field is .model, and .get('name') silently returns None
Read the model id from m.model (or m['model']): for m in ollama.list().models: print(m.model, m.size). The list entries no longer have a name key.
Since 0.4, ollama-python returns pydantic response objects (ListResponse, ChatResponse, ...) built on a SubscriptableBaseModel. They support both attribute access (r.message.content) and dict-style access (r['message']['content']), so most dict-era code keeps working. That hides the one place that changed. In ollama 0.4.4, ListResponse.Model has exactly the fields model, modified_at, digest, size, details. model['name'] raises:
File ".../ollama/_types.py", line 33, in __getitem__
raise KeyError(key)
KeyError: 'name'A defensive m.get('name', 'unknown') is worse: it returns None and your UI shows blank model names. The raw /api/tags JSON likely still carries name, and older snippets were written against that. Verified with ListResponse.Model(model='qwen2.5:3b', size=1) in python:3.11-slim. Prefer attribute access in new code so type checkers catch renamed fields.