Using imported functions inside cached functions


Currently experimenting a fair bit with Streamlit as I found it has great potential.

Trying to clean up a bit my files, I tried to put functions used in other cached functions, into another module

So replacing :

def get_data(site):
return get_site_data()

with this:

import ccb

def get_data(site):
return ccb.get_site_data()

the function ccb.get_site_data() returns the correct data when used at a different location.
However, inside the cached function, I get an error in streamlit:
Streamlit failed to hash an object of type <class ‘function’>.

TypeError : object supporting the buffer API required

File “c:\users\ \cbflcp~1\venv~1\lib\site-packages\streamlit\”, line 241, in _update hasher.update(b)

I am on Win10 with python 3.7.5 and streamlit 0.51 running in a venv

I do not quite understand why the same function cannot be in a different module…

Is it due to the cache function?

Is there any way around it or all components of my cached functions need to be in the streamlit script ?

Thanks a lot,

Replying to myself,
it turns out that if I explicitly import the function from that module, then it works:

from ccb import get_site_data

def get_data(site):
return get_site_data()

Not sure if that is a bug or expected behavior, but it might help someone else.

1 Like