- Notifications
You must be signed in to change notification settings - Fork25
Python wrapper for the entire GitLab API
License
doctormo/python-gitlab3
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Martin Owens (@doctormo) has kindly taken over maintenance of this project.
A Python wrapper for GitLab API v3.
There are existing python wrappers (notably,http://github.com/gpocentek/python-gitlab andhttp://github.com/Itxaka/python-gitlab), but I'm not fond of their interface/usage. In addition, this provides complete coverage of the GitLab API (and is easily maintainable).
$ sudo pip install gitlab3
Seehttp://alexvh.github.io/python-gitlab3/ for complete API information (also contained in thedoc
directory). Ancient-looking, Epydoc-generated html since it organizes this project more clearly than Sphinx does.
importgitlab3gl=gitlab3.GitLab('http://example.com/','token')# Alternatively:gl=gitlab3.GitLab('http://example.com/')ifnotgl.login('username_or_email','password'):print"Login failed"## Example usage involving listing objects#forprojectingl.projects():# all of the current user's projectsprintproject.nameforeventingl.project(1).events(limit=10):# 10 most recent eventsprintevent.action_nameforprojectingl.projects(page=1,per_page=10):# paginationprintproject.issues(limit=1)[0].title# (assume issue[0] exists...)## Sudo usage examples (GitLab v6.1+)# All functions accept an optional, undocumented, 'sudo' argument# specifiying a username or user id to act as.#gl.get_current_user(sudo='other_user')# => 'other_user' CurrentUser objectgl.projects(sudo=2)# => list of user 2's projects# Alternatively, a 'with' statement can be used as follows:withgl.sudo('other_user'):gl.get_current_user()# => 'other_user' CurrentUser objectgl.projects()# => list of 'other_users's projects## Example usage involving users#user=gl.add_user('user@example.com','passwd','username','real name',project_limit=50,bio='bio')printtype(user)# => '<class 'gitlab3.User'>'printtype(user.created_at)# => '<type 'datetime.datetime'>'user=gl.user(1)# or gl.get_user(1) - get_<name>() aliases <name>()user.email='change@example.com'user.save()# or gl.update_user(user)user.delete()# or gl.delete_user(user)## Example usage involving projects#project=gl.project(1)# or gl.get_project(1)printproject.descriptionproject.events(limit=10)# Adding projectsgl.add_project('my project',description='description',public=True)gl.add_project_for_user('user_id','test project',description='description')# Branches and tagsbranch=project.branch('master')branch.protect()project.unprotect_branch('master')tags=project.tags()# Membersmember=project.add_member('user_id',gitlab3.ACCESS_LEVEL_GUEST)member.access_level=gitlab3.ACCESS_LEVEL_DEVELOPERmember.save()# or project.update_member(member)project.delete_member(member)# Issuesissues=project.issues(limit=10)issue=project.add_issue('title',description='description')issue.add_note('note body')issue.close()issue.reopen()# Snippetssnippet=project.add_snippet('title','file_name','code')snippet.delete()# or project.delete_snippet(snippet)snippet=project.snippet(1)snippet_notes=snippet.notes()# Files and commitsproject.commits()# list of commits in master branchproject.files()# list of files in master branchproject.files(ref_name='other_branch')readme_contents=project.get_blob('master','README')## Example usage involving user teams#teams=gl.teams()team=gl.add_team('team name','path')team.add_member('user_id',gitlab3.ACCESS_LEVEL_GUEST)team.add_project('project_id',gitlab3.ACCESS_LEVEL_MASTER)## Find function examples# All objects that can be listed and obtained by an id have find functions.## The find functions are simple, o(n), mostly unoptimized, and will request a# listing of objects on every call unless given a cached list.#gl.find_project(name='python-gitlab3')# params can be any property of objectprojects=gl.projects()gl.find_project(cached=projects,name='python-gitlab3')gl.find_project(cached=projects,find_all=True,public=True)# public projectsgl.find_project(cached=projects,find_all=True,public=True,wiki_enabled=True)# public projects with wikisgl.find_user(email='user@example.com')project=gl.project(1)project.find_member(username='user')# The GitLab API has support for more efficient searching of projects by name:gl.find_projects_by_name('name_query')# Server-side search
About
Python wrapper for the entire GitLab API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.