Python exports the gitlab project

Python export gitlab project

  1. install python-gitlab module
    pip install python-gitlab
    pip3 install python-gitlab
  2. gitlab application API access token
    path User Settings -> Access Tokens
  3. configure pythongitlab.cfg and place

    in the same directory

     default = username
     ssh_verify = False
     timeout = 8
     url =
     private_token = xxxxxxxxxxxx


    对于API v4使用url,如果您使用API v3使用url




import gitlab
gl = gitlab.Gitlab.from_config('username', ['python-gitlab.cfg'])
projects = gl.projects.list()
  • or use the following code to get the group project
    import gitlab
    class GitlabAPI(object):
        def __init__(self, *args, **kwargs):
   = gitlab.Gitlab('', private_token='xxxxxxxxxxxxx', api_version='4')
        # 可行 先获取所有group ID, 然后根据group ID 获取项目地址
        def get_all_group(self):
        def get_group_by_id(self, groupID):
            group =
            projects = group.projects.list(all=True)
            result_list = []
            for project in projects:
            return result_list
    apiObject = GitlabAPI()
    groupProjects = apiObject.get_group_by_id(填写获取到的groupID)

Read More: