Open JohnPaton opened 2 years ago
What do you have in mind?
I think that the functionality from AirbaseClient
and AirbaseRequest
could be neatly combined into a context manager class that works something like:
from airbase import AirbaseSession
with AirbaseSession(country=["NL", "DE"], pollutant="NO3", year_from=2015) as session:
session.download_to_directory(dir="data", skip_existing=True)
Generating CSV download links...
100%|██████████| 2/2 [00:03<00:00, 2.03s/it]
Generated 12 CSV links ready for downloading
Downloading CSVs to data...
100%|██████████| 12/12 [00:01<00:00, 8.44it/s]
The context manager will help with clean up the asyncio loop of unfinished tasks after receiving an KeyboardInterrupt
.
Ah I hadn't thought about the unfinished tasks now that it's async. What I had in mind was basically just providing top-level functions corresponding to the methods of the Client, and instantiating a Client as needed in the background (now that it doesn't take any arguments anyway), so that users don't need to bother with the Client at all. They would just get Request objects directly that they can download however they would like. This is because scientific users often prefer the minimum of code/complexity and just want to get things done :)
I think given that, the ContextManager doesn't really make it clearer what's going on. And tbh having one line instantiating the client isn't so much of a burden anyway, so maybe it's best to just leave it as is?
Like
requests
, create a new api that basically bypasses the client (by handling it internally) so that users can jump directly todownload_*
ing the data.