Error when pickling Grist object / how to cache?

I’m trying to avoid calling the Grist API too often - and speed up my scripts - by pickling the Grist object. But I get the error _pickle.PicklingError: Can't pickle <class 'grist_api.grist_api.Countries'>: attribute lookup Countries on grist_api.grist_api failed.

Is there something I can do to pickle it successfully?
Or is there another simple way to cache a Grist object?

Hi @Nic.

I’m not sure why pickling is failing, but one thing you could try is adding caching to all http requests in your script. The requests_cache package has an install_cache method that should add caching globally to anything using the requests package (which includes the Grist API).

https://requests-cache.readthedocs.io/en/stable/user_guide/general.html#patching

Thanks for the tip! That looks exactly what I need for this use case (and others using requests)!