How to efficiently use a Session from within a python object to keep tensorflow as an implementation detail?
Don't open a session at each function call, that could be very inefficient if the function is called many times.
If for some reason, you don't want to expose a context manager, then you need to open the session yourself, and leave it open. It is perhaps a bit simpler for the user, but sharing the tf.Session with other objects or libraries might be more difficult. Also trying to hide the fact that you are using tensorflow may be a bit vain, as it is potentially incompatible with other libraries also relying on the GPU. (Also the user will need to install tensorflow to use the library, s/he will definitely know that you are using it).
So I would not try to encapsulate things that can't or shouldn't (in my opinion) and use a context manager for the tf.Session (maybe even using directly a tf.Session itself if I don't mind exposing tensorflow, otherwise wrapping it in my own context manager).
I'm implementing a custom sklearn Transformer, which requires an optimization step which has been coded in Tensorflow. TF requires a Session, which should be used as a context manager or explicitly closed. The question is: adding a close() method to the Transformer would be odd (and unexpected for a user), what is the best place to close the session? Should I open and close a new session for a every call to fit()? Or should I keep it open and leave the session.close() to the __del__ method of the transformer? Any other options?