| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0268fc9 commit 60efc83
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,15 +2,38 @@ | |||
| 2 | 2 | Getting started with the API | |
| 3 | 3 | ############################ | |
| 4 | 4 | ||
| 5 | - The ``gitlab`` package provides 3 base types: | ||
| 5 | + python-gitlab supports both GitLab v3 and v4 APIs. | ||
| 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 | + v3 is still the default API used by python-gitlab, for compatibility reasons.. | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + Base types | ||
| 14 | + ========== | ||
| 15 | + | ||
| 16 | + The ``gitlab`` package provides some base types. | ||
| 6 | 17 | ||
| 7 | 18 | * ``gitlab.Gitlab`` is the primary class, handling the HTTP requests. It holds | |
| 8 | 19 | the GitLab URL and authentication information. | |
| 9 | - * ``gitlab.GitlabObject`` is the base class for all the GitLab objects. These | ||
| 10 | - objects provide an abstraction for GitLab resources (projects, groups, and so | ||
| 11 | - on). | ||
| 12 | - * ``gitlab.BaseManager`` is the base class for objects managers, providing the | ||
| 13 | - API to manipulate the resources and their attributes. | ||
| 20 | + | ||
| 21 | + For v4 the following types are defined: | ||
| 22 | + | ||
| 23 | + * ``gitlab.base.RESTObject`` is the base class for all the GitLab v4 objects. | ||
| 24 | + These objects provide an abstraction for GitLab resources (projects, groups, | ||
| 25 | + and so on). | ||
| 26 | + * ``gitlab.base.RESTManager`` is the base class for v4 objects managers, | ||
| 27 | + providing the API to manipulate the resources and their attributes. | ||
| 28 | + | ||
| 29 | + For v3 the following types are defined: | ||
| 30 | + | ||
| 31 | + * ``gitlab.base.GitlabObject`` is the base class for all the GitLab v3 objects. | ||
| 32 | + These objects provide an abstraction for GitLab resources (projects, groups, | ||
| 33 | + and so on). | ||
| 34 | + * ``gitlab.base.BaseManager`` is the base class for v3 objects managers, | ||
| 35 | + providing the API to manipulate the resources and their attributes. | ||
| 36 | + | ||
| 14 | 37 | ||
| 15 | 38 | ``gitlab.Gitlab`` class | |
| 16 | 39 | ======================= | |
@@ -40,7 +63,9 @@ You can also use configuration files to create ``gitlab.Gitlab`` objects: | |||
| 40 | 63 | See the :ref:`cli_configuration` section for more information about | |
| 41 | 64 | configuration files. | |
| 42 | 65 | ||
| 43 | - **GitLab v4 support** | ||
| 66 | + | ||
| 67 | + API version | ||
| 68 | + =========== | ||
| 44 | 69 | ||
| 45 | 70 | ``python-gitlab`` uses the v3 GitLab API by default. Use the ``api_version`` | |
| 46 | 71 | parameter to switch to v4: | |
@@ -53,15 +78,17 @@ parameter to switch to v4: | |||
| 53 | 78 | ||
| 54 | 79 | .. warning:: | |
| 55 | 80 | ||
| 56 | - The v4 support is experimental. | ||
| 81 | + The python-gitlab API is not the same for v3 and v4. Make sure to read | ||
| 82 | + :ref:`switching_to_v4` before upgrading. | ||
| 83 | + | ||
| 84 | + v4 will become the default in python-gitlab. | ||
| 57 | 85 | ||
| 58 | 86 | Managers | |
| 59 | 87 | ======== | |
| 60 | 88 | ||
| 61 | 89 | The ``gitlab.Gitlab`` class provides managers to access the GitLab resources. | |
| 62 | 90 | Each manager provides a set of methods to act on the resources. The available | |
| 63 | - methods depend on the resource type. Resources are represented as | ||
| 64 | - ``gitlab.GitlabObject``-derived objects. | ||
| 91 | + methods depend on the resource type. | ||
| 65 | 92 | ||
| 66 | 93 | Examples: | |
| 67 | 94 | ||
@@ -84,17 +111,22 @@ Examples: | |||
| 84 | 111 | ||
| 85 | 112 | The attributes of objects are defined upon object creation, and depend on the | |
| 86 | 113 | GitLab API itself. To list the available information associated with an object | |
| 87 | - use the python introspection tools: | ||
| 114 | + use the python introspection tools for v3, or the ``attributes`` attribute for | ||
| 115 | + v4: | ||
| 88 | 116 | ||
| 89 | 117 | .. code-block:: python | |
| 90 | 118 | ||
| 91 | 119 | project = gl.projects.get(1) | |
| 120 | + | ||
| 121 | + # v3 | ||
| 92 | 122 | print(vars(project)) | |
| 93 | 123 | # or | |
| 94 | 124 | print(project.__dict__) | |
| 95 | 125 | ||
| 96 | - Some ``gitlab.GitlabObject`` classes also provide managers to access related | ||
| 97 | - GitLab resources: | ||
| 126 | + # v4 | ||
| 127 | + print(project.attributes) | ||
| 128 | + | ||
| 129 | + Some objects also provide managers to access related GitLab resources: | ||
| 98 | 130 | ||
| 99 | 131 | .. code-block:: python | |
| 100 | 132 | ||
@@ -105,7 +137,7 @@ GitLab resources: | |||
| 105 | 137 | Gitlab Objects | |
| 106 | 138 | ============== | |
| 107 | 139 | ||
| 108 | - You can update or delete an object when it exists as a ``GitlabObject`` object: | ||
| 140 | + You can update or delete a remote object when it exists locally: | ||
| 109 | 141 | ||
| 110 | 142 | .. code-block:: python | |
| 111 | 143 | ||
@@ -119,15 +151,31 @@ You can update or delete an object when it exists as a ``GitlabObject`` object: | |||
| 119 | 151 | project.delete() | |
| 120 | 152 | ||
| 121 | 153 | ||
| 122 | - Some ``GitlabObject``-derived classes provide additional methods, allowing more | ||
| 123 | - actions on the GitLab resources. For example: | ||
| 154 | + Some classes provide additional methods, allowing more actions on the GitLab | ||
| 155 | + resources. For example: | ||
| 124 | 156 | ||
| 125 | 157 | .. code-block:: python | |
| 126 | 158 | ||
| 127 | 159 | # star a git repository | |
| 128 | 160 | project = gl.projects.get(1) | |
| 129 | 161 | project.star() | |
| 130 | 162 | ||
| 163 | + Lazy objects (v4 only) | ||
| 164 | + ====================== | ||
| 165 | + | ||
| 166 | + To avoid useless calls to the server API, you can create lazy objects. These | ||
| 167 | + objects are created locally using a known ID, and give access to other managers | ||
| 168 | + and methods. | ||
| 169 | + | ||
| 170 | + The following exemple will only make one API call to the GitLab server to star | ||
| 171 | + a project: | ||
| 172 | + | ||
| 173 | + .. code-block:: python | ||
| 174 | + | ||
| 175 | + # star a git repository | ||
| 176 | + project = gl.projects.get(1, lazy=True) # no API call | ||
| 177 | + project.star() # API call | ||
| 178 | + | ||
| 131 | 179 | Pagination | |
| 132 | 180 | ========== | |
| 133 | 181 | ||
@@ -142,16 +190,15 @@ listing methods support the ``page`` and ``per_page`` parameters: | |||
| 142 | 190 | ||
| 143 | 191 | The first page is page 1, not page 0. | |
| 144 | 192 | ||
| 145 | - | ||
| 146 | - By default GitLab does not return the complete list of items. Use the ``all`` | ||
| 193 | + By default GitLab does not return the complete list of items. Use the ``all`` | ||
| 147 | 194 | parameter to get all the items when using listing methods: | |
| 148 | 195 | ||
| 149 | 196 | .. code-block:: python | |
| 150 | 197 | ||
| 151 | 198 | all_groups = gl.groups.list(all=True) | |
| 152 | 199 | all_owned_projects = gl.projects.owned(all=True) | |
| 153 | 200 | ||
| 154 | - .. note:: | ||
| 201 | + .. warning:: | ||
| 155 | 202 | ||
| 156 | 203 | python-gitlab will iterate over the list by calling the corresponding API | |
| 157 | 204 | multiple times. This might take some time if you have a lot of items to | |
@@ -160,6 +207,15 @@ parameter to get all the items when using listing methods: | |||
| 160 | 207 | use ``safe_all=True`` instead to stop pagination automatically if the | |
| 161 | 208 | recursion limit is hit. | |
| 162 | 209 | ||
| 210 | + With v4, ``list()`` methods can also return a generator object which will | ||
| 211 | + handle the next calls to the API when required: | ||
| 212 | + | ||
| 213 | + .. code-block:: python | ||
| 214 | + | ||
| 215 | + items = gl.groups.list(as_list=False) | ||
| 216 | + for item in items: | ||
| 217 | + print(item.attributes) | ||
| 218 | + | ||
| 163 | 219 | Sudo | |
| 164 | 220 | ==== | |
| 165 | 221 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,8 @@ Content | |||
| 28 | 28 | ------- | |
| 29 | 29 | ||
| 30 | 30 | The configuration file uses the ``INI`` format. It contains at least a | |
| 31 | - ``[global]`` section, and a new section for each GitLab server. For example: | ||
| 31 | + ``[global]`` section, and a specific section for each GitLab server. For | ||
| 32 | + example: | ||
| 32 | 33 | ||
| 33 | 34 | .. code-block:: ini | |
| 34 | 35 | ||
@@ -98,7 +99,7 @@ CLI | |||
| 98 | 99 | Objects and actions | |
| 99 | 100 | ------------------- | |
| 100 | 101 | ||
| 101 | - The ``gitlab`` command expects two mandatory arguments. This first one is the | ||
| 102 | + The ``gitlab`` command expects two mandatory arguments. The first one is the | ||
| 102 | 103 | type of object that you want to manipulate. The second is the action that you | |
| 103 | 104 | want to perform. For example: | |
| 104 | 105 | ||
@@ -140,8 +141,8 @@ These options must be defined before the mandatory arguments. | |||
| 140 | 141 | Output format. Defaults to a custom format. Can also be ``yaml`` or ``json``. | |
| 141 | 142 | ||
| 142 | 143 | ``--fields``, ``-f`` | |
| 143 | - Comma-separated list of fields to display (``yaml`` and ``json`` formats | ||
| 144 | - only). If not used, all the object fields are displayed. | ||
| 144 | + Comma-separated list of fields to display (``yaml`` and ``json`` output | ||
| 145 | + formats only). If not used, all the object fields are displayed. | ||
| 145 | 146 | ||
| 146 | 147 | Example: | |
| 147 | 148 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + .. _switching_to_v4: | ||
| 2 | + | ||
| 1 | 3 | ########################## | |
| 2 | 4 | Switching to GtiLab API v4 | |
| 3 | 5 | ########################## | |
@@ -10,15 +12,12 @@ GitLab will stop supporting the v3 API soon, and you should consider switching | |||
| 10 | 12 | to v4 if you use a recent version of GitLab (>= 9.0), or if you use | |
| 11 | 13 | http://gitlab.com. | |
| 12 | 14 | ||
| 13 | - The new v4 API is available in the `rework_api branch on github | ||
| 14 | - <https://github.com/python-gitlab/python-gitlab/tree/rework_api>`_, and will be | ||
| 15 | - released soon. | ||
| 16 | - | ||
| 17 | 15 | ||
| 18 | 16 | Using the v4 API | |
| 19 | 17 | ================ | |
| 20 | 18 | ||
| 21 | - To use the new v4 API, explicitly use it in the ``Gitlab`` constructor: | ||
| 19 | + To use the new v4 API, explicitly define ``api_version` `in the ``Gitlab`` | ||
| 20 | + constructor: | ||
| 22 | 21 | ||
| 23 | 22 | .. code-block:: python | |
| 24 | 23 | ||
@@ -79,7 +78,7 @@ following important changes in the python API: | |||
| 79 | 78 | calls. | |
| 80 | 79 | ||
| 81 | 80 | To limit the number of API calls, you can now use ``get()`` methods with the | |
| 82 | - ``lazy=True`` parameter. This creates shallow objects that provide usual | ||
| 81 | + ``lazy=True`` parameter. This creates shallow objects that provide usual | ||
| 83 | 82 | managers. | |
| 84 | 83 | ||
| 85 | 84 | The following v3 code: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments