Skip to content

feat: add exists() convenience method to Client and AsyncClient#652

Open
Ghraven wants to merge 1 commit intoollama:mainfrom
Ghraven:feat/client-exists-method
Open

feat: add exists() convenience method to Client and AsyncClient#652
Ghraven wants to merge 1 commit intoollama:mainfrom
Ghraven:feat/client-exists-method

Conversation

@Ghraven
Copy link
Copy Markdown

@Ghraven Ghraven commented Apr 27, 2026

Closes #640

What

Adds exists(model: str) -> bool to both Client and AsyncClient.

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

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

Implementation

Thin wrapper around show() that catches ResponseError and returns False instead of propagating the exception. Returns True if show() succeeds.

Both the sync and async variants are added to _client.py following the exact same patterns as the existing show() methods directly above them.

Files changed

  • ollama/_client.py — adds Client.exists() and AsyncClient.exists()

Closes ollama#640

Adds a convenience `exists(model)` method to both `Client` and
`AsyncClient` that returns `True` if the model is available locally,
`False` otherwise — no exception handling needed at the call site.

Implemented as a thin wrapper around `show()` that catches
`ResponseError`, matching the pattern already used throughout the SDK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant