mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Add Client.close() and context manager
#277
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @roskakori on GitHub (Jun 11, 2025).
Currently, a client to interact with the Ollama API can be created using
However, there is no way to close the client and give back the resources it acquired. Eventually, Python's garbage collector will, but it would be nice to be able to do that as early as possible.
From my understanding, adding the following methods to
ollama._client.Clientwould address this:And then something similar for the
AsyncClient.That way, the client could be used like:
If you want, I can look into this and prepare a PR.
Update: This should also fix warnings when using ollama-python with pytest: