| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 76e9b12 commit 186e11a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ Contents: | |||
| 14 | 14 | install | |
| 15 | 15 | cli | |
| 16 | 16 | api-usage | |
| 17 | + switching-to-v4 | ||
| 17 | 18 | api-objects | |
| 18 | 19 | api/modules | |
| 19 | 20 | release_notes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,125 @@ | |||
| 1 | + ########################## | ||
| 2 | + Switching to GtiLab API v4 | ||
| 3 | + ########################## | ||
| 4 | + | ||
| 5 | + GitLab provides a new API version (v4) since its 9.0 release. ``python-gitlab`` | ||
| 6 | + provides support for this new version, but the python API has been modified to | ||
| 7 | + solve some problems with the existing one. | ||
| 8 | + | ||
| 9 | + GitLab will stop supporting the v3 API soon, and you should consider switching | ||
| 10 | + to v4 if you use a recent version of GitLab (>= 9.0), or if you use | ||
| 11 | + http://gitlab.com. | ||
| 12 | + | ||
| 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 | + | ||
| 18 | + Using the v4 API | ||
| 19 | + ================ | ||
| 20 | + | ||
| 21 | + To use the new v4 API, explicitly use it in the ``Gitlab`` constructor: | ||
| 22 | + | ||
| 23 | + .. code-block:: python | ||
| 24 | + | ||
| 25 | + gl = gitlab.Gitlab(..., api_version=4) | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + If you use the configuration file, also explicitly define the version: | ||
| 29 | + | ||
| 30 | + .. code-block:: ini | ||
| 31 | + | ||
| 32 | + [my_gitlab] | ||
| 33 | + ... | ||
| 34 | + api_version = 4 | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + Changes between v3 and v4 API | ||
| 38 | + ============================= | ||
| 39 | + | ||
| 40 | + For a list of GtiLab (upstream) API changes, see | ||
| 41 | + https://docs.gitlab.com/ce/api/v3_to_v4.html. | ||
| 42 | + | ||
| 43 | + The ``python-gitlab`` API reflects these changes. But also consider the | ||
| 44 | + following important changes in the python API: | ||
| 45 | + | ||
| 46 | + * managers and objects don't inherit from ``GitlabObject`` and ``BaseManager`` | ||
| 47 | + anymore. They inherit from :class:`~gitlab.base.RESTManager` and | ||
| 48 | + :class:`~gitlab.base.RESTObject`. | ||
| 49 | + | ||
| 50 | + * You should only use the managers to perform CRUD operations. | ||
| 51 | + | ||
| 52 | + The following v3 code: | ||
| 53 | + | ||
| 54 | + .. code-block:: python | ||
| 55 | + | ||
| 56 | + gl = gitlab.Gitlab(...) | ||
| 57 | + p = Project(gl, project_id) | ||
| 58 | + | ||
| 59 | + Should be replaced with: | ||
| 60 | + | ||
| 61 | + .. code-block:: python | ||
| 62 | + | ||
| 63 | + gl = gitlab.Gitlab(...) | ||
| 64 | + p = gl.projects.get(project_id) | ||
| 65 | + | ||
| 66 | + * Listing methods (``manager.list()`` for instance) now return generators | ||
| 67 | + (:class:`~gitlab.base.RESTObjectList`). They handle the calls to the API when | ||
| 68 | + needed. | ||
| 69 | + | ||
| 70 | + If you need to get all the items at once, use the ``all=True`` parameter: | ||
| 71 | + | ||
| 72 | + .. code-block:: python | ||
| 73 | + | ||
| 74 | + all_projects = gl.projects.list(all=True) | ||
| 75 | + | ||
| 76 | + * The "nested" managers (for instance ``gl.project_issues`` or | ||
| 77 | + ``gl.group_members``) are not available anymore. Their goal was to provide a | ||
| 78 | + direct way to manage nested objects, and to limit the number of needed API | ||
| 79 | + calls. | ||
| 80 | + | ||
| 81 | + 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 | ||
| 83 | + managers. | ||
| 84 | + | ||
| 85 | + The following v3 code: | ||
| 86 | + | ||
| 87 | + .. code-block:: python | ||
| 88 | + | ||
| 89 | + issues = gl.project_issues.list(project_id=project_id) | ||
| 90 | + | ||
| 91 | + Should be replaced with: | ||
| 92 | + | ||
| 93 | + .. code-block:: python | ||
| 94 | + | ||
| 95 | + issues = gl.projects.get(project_id, lazy=True).issues.list() | ||
| 96 | + | ||
| 97 | + This will make only one API call, instead of two if ``lazy`` is not used. | ||
| 98 | + | ||
| 99 | + * The :class:`~gitlab.Gitlab` folowwing methods should not be used anymore for | ||
| 100 | + v4: | ||
| 101 | + | ||
| 102 | + + ``list()`` | ||
| 103 | + + ``get()`` | ||
| 104 | + + ``create()`` | ||
| 105 | + + ``update()`` | ||
| 106 | + + ``delete()`` | ||
| 107 | + | ||
| 108 | + * If you need to perform HTTP requests to the GitLab server (which you | ||
| 109 | + shouldn't), you can use the following :class:`~gitlab.Gitlab` methods: | ||
| 110 | + | ||
| 111 | + + :attr:`~gitlab.Gitlab.http_request` | ||
| 112 | + + :attr:`~gitlab.Gitlab.http_get` | ||
| 113 | + + :attr:`~gitlab.Gitlab.http_list` | ||
| 114 | + + :attr:`~gitlab.Gitlab.http_post` | ||
| 115 | + + :attr:`~gitlab.Gitlab.http_put` | ||
| 116 | + + :attr:`~gitlab.Gitlab.http_delete` | ||
| 117 | + | ||
| 118 | + | ||
| 119 | + Undergoing work | ||
| 120 | + =============== | ||
| 121 | + | ||
| 122 | + * The ``delete()`` method for objects is not yet available. For now you need to | ||
| 123 | + use ``manager.delete(obj.id)``. | ||
| 124 | + * The ``page`` and ``per_page`` arguments for listing don't behave as they used | ||
| 125 | + to. Their behavior will be restored. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments