Skip to content

feat: add helpers to expose package version and server version API #647

Open
ravivarmanr26 wants to merge 2 commits intoollama:mainfrom
ravivarmanr26:feature/version-helper
Open

feat: add helpers to expose package version and server version API #647
ravivarmanr26 wants to merge 2 commits intoollama:mainfrom
ravivarmanr26:feature/version-helper

Conversation

@ravivarmanr26
Copy link
Copy Markdown

Closes #646

There was no clean way to check the installed package version or query the running Ollama server version from Python without resorting to workarounds like parsing package metadata manually or catching exceptions.

This PR exposes two things:

  • ollama.__version__ : already existed internally in _client.py for the User-Agent header, just not exported. Now re-exported via __init__.py.
  • ollama.version() : top-level alias for Client.version(), which calls GET /api/version and returns the version string. AsyncClient.version() added for completeness.

Usage

import ollama

print(ollama.__version__)   # package version e.g. "0.6.1"
print(ollama.version())     # server version e.g. "0.18.2"

Changes

  • ollama/__init__.py : exports __version__ and wires version as a top-level alias
  • ollama/_client.py : adds version() to Client and AsyncClient
  • tests/test_client.py : 4 new tests: package attribute check, sync/async , missing field edge case

Tests

All tests pass locally.
Command used:
pytest tests/test_client.py

Result :

76 passed in 2.32s 

Adds:
- ollama.__version__  for the installed package version
- .version() method on Client and AsyncClient to fetch /api/version
Includes tests.

Closes ollama#646
@ParthSareen ParthSareen self-requested a review April 22, 2026 07:55
@ravivarmanr26
Copy link
Copy Markdown
Author

Hi @ParthSareen just checking in on this PR. Happy to make any changes if there's feedback. Let me know if anything needs adjusting before this can be reviewed. Thanks!

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.

Feature: expose __version__ and top-level version() for server version Closes #623

1 participant