You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to get the response iterator directly when downloading artifacts? #1955
Description of the problem, including code/CLI snippet
The artifact downloads support a streaming mode which wraps the iterator provided by the requests library and allows the user to provide an action callable that is called with the chunks provided by the iterator as arguments.
I would like to be able to access the response.iter_content() iterator directly.
( In my real project do_things_with_iterator is actually a fastapi StreamingResponse which takes an iterator or generator. This would allow downloads of artifacts without first having to download the entire file server side and then forwarding it to the client)
Actual Behavior
As far as I can tell this is currently not possible.
I thought this would be relatively simple to implement, so I adapted the response_content function in utils.py to
But I ran into issues adapting the type annotations in other places, as some functions are not designed to handle iterators and will only handle bytes. I did not have a lot of time to spend on figuring this out though so if it seems worth the effort I can look into this further and create a pull request later.
In the meantime I found a (slightly ugly) workaround to get the desired behavior from python-gitlab 3.2.0 and fastapi. It needs a supporting class that python-gitlab can write the chunks to in a different thread, which gets wrapped in a generator that fastapi can use.
Activity
TCatshoek commentedon Mar 30, 2022
Created a pull request #1956
Please close if there's a better way to do this that I missed.
TCatshoek commentedon Mar 31, 2022
In the meantime I found a (slightly ugly) workaround to get the desired behavior from python-gitlab 3.2.0 and fastapi. It needs a supporting class that python-gitlab can write the chunks to in a different thread, which gets wrapped in a generator that fastapi can use.
And then we can read and write in our route:
Please use with caution, it seems to work fine for me but I have not exhaustively tested it. Performance could probably be improved too.
nejch commentedon Jun 26, 2022
Done with #1956.