Search code examples
gitgithubgitlabpygithubpython-gitlab

Accessing private instances of Github and Gitlab through their respective Python APIs


Can I access private instances of Github and Gitlab through API wrappers in python such as pygithub and python-gitlab. For example, if I want to access my company's private server of Github and Gitlab, is it possible? Any help on the matter would be really appreciated!


Solution

  • When using python-gitlab, use:

    import gitlab
    gl = gitlab.Gitlab('http://your_gitlab_instance_url.com', private_token='token')
    

    Mentioning the url of the private instance does the job. The method may fail though, if there is some other secondary forms of security authenticators.

    When using pygithub, use:

    from github import Github
    g = Github(base_url="https://{hostname}/api/v3", login_or_token="access_token")
    

    Works fine with the Rest API for github api v3