'Download GitLab file with gitlab-python

I am trying to download a file or folder from my gitlab repository, but they only way I have seen to do it is using CURL and command line. Is there any way to download files from the repository with just the python-gitlab API? I have read through the API and have not found anything, but other posts said it was possible, just gave no solution.



Solution 1:[1]

You can do like this:

import requests
response = requests.get('https://<your_path>/file.txt')
data = response.text

and then save the contents (data) as file...

Otherwise use the API:

f = project.files.get(path='<folder>/file.txt',ref='<branch or commit>')

and then decode using:

import base64
content = base64.b64decode(f.content)

and then save content as file...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ulrik Larsen