2
2
Getting started with the API
3
3
############################
4
4
5
- python-gitlab supports both GitLab v3 and v4 APIs.
5
+ python-gitlab supports both GitLab v3 and v4 APIs. To use the v3 make sure to
6
6
7
- v3 being deprecated by GitLab, its support in python-gitlab will be minimal.
8
- The development team will focus on v4.
9
-
10
- v4 is the default API used by python-gitlab since version 1.3.0.
7
+ .. note ::
11
8
9
+ To use the v3 make sure to install python-gitlab 1.4. Only the v4 API is
10
+ documented here. See the documentation of earlier version for the v3 API.
12
11
13
12
``gitlab.Gitlab `` class
14
13
=======================
@@ -60,23 +59,6 @@ https://gist.github.com/gpocentek/bd4c3fbf8a6ce226ebddc4aad6b46c0a.
60
59
See `issue 380 <https://github.com/python-gitlab/python-gitlab/issues/380 >`_
61
60
for a detailed discussion.
62
61
63
- API version
64
- ===========
65
-
66
- ``python-gitlab `` uses the v4 GitLab API by default. Use the ``api_version ``
67
- parameter to switch to v3:
68
-
69
- .. code-block :: python
70
-
71
- import gitlab
72
-
73
- gl = gitlab.Gitlab(' http://10.0.0.1' , ' JVNSESs8EwWRx5yDxM5q' , api_version = 3 )
74
-
75
- .. warning ::
76
-
77
- The python-gitlab API is not the same for v3 and v4. Make sure to read
78
- :ref: `switching_to_v4 ` if you are upgrading from v3.
79
-
80
62
Managers
81
63
========
82
64
@@ -103,10 +85,10 @@ Examples:
103
85
user = gl.users.create(user_data)
104
86
print (user)
105
87
106
- You can list the mandatory and optional attributes for object creation
107
- with the manager's ``get_create_attrs() `` method. It returns 2 tuples, the
108
- first one is the list of mandatory attributes , the second one the list of
109
- optional attribute:
88
+ You can list the mandatory and optional attributes for object creation and
89
+ update with the manager's ``get_create_attrs() `` and `` get_update_attrs() ``
90
+ methods. They return 2 tuples , the first one is the list of mandatory
91
+ attributes, the second one the list of optional attribute:
110
92
111
93
.. code-block :: python
112
94
@@ -116,19 +98,11 @@ optional attribute:
116
98
117
99
The attributes of objects are defined upon object creation, and depend on the
118
100
GitLab API itself. To list the available information associated with an object
119
- use the python introspection tools for v3, or the ``attributes `` attribute for
120
- v4:
101
+ use the ``attributes `` attribute:
121
102
122
103
.. code-block :: python
123
104
124
105
project = gl.projects.get(1 )
125
-
126
- # v3
127
- print (vars (project))
128
- # or
129
- print (project.__dict__ )
130
-
131
- # v4
132
106
print (project.attributes)
133
107
134
108
Some objects also provide managers to access related GitLab resources:
@@ -171,32 +145,21 @@ The ``gitlab`` package provides some base types.
171
145
172
146
* ``gitlab.Gitlab `` is the primary class, handling the HTTP requests. It holds
173
147
the GitLab URL and authentication information.
174
-
175
- For v4 the following types are defined:
176
-
177
148
* ``gitlab.base.RESTObject `` is the base class for all the GitLab v4 objects.
178
149
These objects provide an abstraction for GitLab resources (projects, groups,
179
150
and so on).
180
151
* ``gitlab.base.RESTManager `` is the base class for v4 objects managers,
181
152
providing the API to manipulate the resources and their attributes.
182
153
183
- For v3 the following types are defined:
184
-
185
- * ``gitlab.base.GitlabObject `` is the base class for all the GitLab v3 objects.
186
- These objects provide an abstraction for GitLab resources (projects, groups,
187
- and so on).
188
- * ``gitlab.base.BaseManager `` is the base class for v3 objects managers,
189
- providing the API to manipulate the resources and their attributes.
154
+ Lazy objects
155
+ ============
190
156
191
- Lazy objects (v4 only)
192
- ======================
193
-
194
- To avoid useless calls to the server API, you can create lazy objects. These
157
+ To avoid useless API calls to the server you can create lazy objects. These
195
158
objects are created locally using a known ID, and give access to other managers
196
159
and methods.
197
160
198
161
The following example will only make one API call to the GitLab server to star
199
- a project:
162
+ a project (the previous example used 2 API calls) :
200
163
201
164
.. code-block :: python
202
165
@@ -214,9 +177,9 @@ listing methods support the ``page`` and ``per_page`` parameters:
214
177
215
178
ten_first_groups = gl.groups.list(page = 1 , per_page = 10 )
216
179
217
- .. note ::
180
+ .. warning ::
218
181
219
- The first page is page 1, not page 0, except for project commits in v3 API .
182
+ The first page is page 1, not page 0.
220
183
221
184
By default GitLab does not return the complete list of items. Use the ``all ``
222
185
parameter to get all the items when using listing methods:
@@ -226,18 +189,9 @@ parameter to get all the items when using listing methods:
226
189
all_groups = gl.groups.list(all = True )
227
190
all_owned_projects = gl.projects.owned(all = True )
228
191
229
- .. warning ::
230
-
231
- With API v3 python-gitlab will iterate over the list by calling the
232
- corresponding API multiple times. This might take some time if you have a
233
- lot of items to retrieve. This might also consume a lot of memory as all the
234
- items will be stored in RAM. If you're encountering the python recursion
235
- limit exception, use ``safe_all=True `` to stop pagination automatically if
236
- the recursion limit is hit.
237
-
238
- With API v4, ``list() `` methods can also return a generator object which will
239
- handle the next calls to the API when required. This is the recommended way to
240
- iterate through a large number of items:
192
+ ``list() `` methods can also return a generator object which will handle the
193
+ next calls to the API when required. This is the recommended way to iterate
194
+ through a large number of items:
241
195
242
196
.. code-block :: python
243
197
@@ -331,12 +285,12 @@ http://docs.python-requests.org/en/master/user/advanced/#client-side-certificate
331
285
Rate limits
332
286
-----------
333
287
334
- python-gitlab will obey the rate limit of the GitLab server by default.
335
- On receiving a 429 response (Too Many Requests), python-gitlab will sleep for the amount of time
336
- in the Retry-After header, that GitLab sends back.
288
+ python-gitlab obeys the rate limit of the GitLab server by default. On
289
+ receiving a 429 response (Too Many Requests), python-gitlab sleeps for the
290
+ amount of time in the Retry-After header that GitLab sends back.
337
291
338
- If you don't want to wait, you can disable the rate-limiting feature, by supplying the
339
- ``obey_rate_limit `` argument.
292
+ If you don't want to wait, you can disable the rate-limiting feature, by
293
+ supplying the ``obey_rate_limit `` argument.
340
294
341
295
.. code-block :: python
342
296
0 commit comments