← 返回首页
Addded API for team access. by dekimsey · Pull Request #1 · python-gitlab/python-gitlab · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
52 changes: 52 additions & 0 deletions gitlab.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ def User(self, id=None, **kwargs):
"""
return self._getListOrObject(User, id, **kwargs)

def Team(self, id=None, **kwargs):
"""Creates/gets/lists team(s) known by the GitLab server.

If id is None, returns a list of teams.

If id is an integer, returns the matching project (or raise a
GitlabGetError if not found)

If id is a dict, create a new object using attributes provided. The
object is NOT saved on the server. Use the save() method on the object
to write it on the server.
"""
return self._getListOrObject(Team, id, **kwargs)


class GitlabObject(object):
_url = None
Expand Down Expand Up @@ -852,3 +866,41 @@ def Tag(self, id=None, **kwargs):
return self._getListOrObject(ProjectTag, id,
project_id=self.id,
**kwargs)


class TeamMember(GitlabObject):
_url = '/user_teams/%(team_id)s/members'
canUpdate = False
requiredCreateAttrs = ['team_id', 'user_id', 'access_level']
requiredDeleteAttrs = ['team_id']
requiredGetAttrs = ['team_id']
requiredListAttrs = ['team_id']
shortPrintAttr = 'username'


class TeamProject(GitlabObject):
_url = '/user_teams/%(team_id)s/projects'
_constructorTypes = {'owner': 'User', 'namespace': 'Group'}
canUpdate = False
requiredCreateAttrs = ['team_id', 'project_id', 'greatest_access_level']
requiredDeleteAttrs = ['team_id', 'project_id']
requiredGetAttrs = ['team_id']
requiredListAttrs = ['team_id']
shortPrintAttr = 'name'


class Team(GitlabObject):
_url = '/user_teams'
shortPrintAttr = 'name'
requiredCreateAttrs = ['name', 'path']
canUpdate = False

def Member(self, id=None, **kwargs):
return self._getListOrObject(TeamMember, id,
team_id=self.id,
**kwargs)

def Project(self, id=None, **kwargs):
return self._getListOrObject(TeamProject, id,
team_id=self.id,
**kwargs)
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.