Skip to content

feat: add client.exists() or client.has_model() method to check if a model is available locally #640

@Pawansingh3889

Description

@Pawansingh3889

Feature Request

Currently there is no clean way to check whether a model is already pulled locally without either:

  1. Calling ollama.show(model) and catching the exception
  2. Calling ollama.list() and iterating through all models

Proposed API

import ollama

if not ollama.exists("llama3.1:8b"):
    ollama.pull("llama3.1:8b")

Or on the client:

client = ollama.Client()
if not client.exists("llama3.1:8b"):
    client.pull("llama3.1:8b")

Use Case

When building applications that need to ensure a model is available before running inference (e.g., CI pipelines, first-run setup scripts, or tools like factory floor AI systems that need to work offline), a simple boolean check is much cleaner than exception-based flow control.

Current Workaround

try:
    ollama.show("llama3.1:8b")
except ollama.ResponseError:
    ollama.pull("llama3.1:8b")

This works but is not discoverable and uses exceptions for control flow, which is an anti-pattern in Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions