|
1 |
| -# Integrate Mergin Maps |
| 1 | +--- |
| 2 | +outline: deep |
| 3 | +--- |
| 4 | + |
| 5 | +# Python API Client |
2 | 6 | [[toc]]
|
3 | 7 |
|
4 | 8 | Do you want to integrate <MainPlatformNameLink />? <MainPlatformName /> is an open platform that aims to be developer friendly and it has been designed to allow easy integration with other software.
|
5 | 9 |
|
6 |
| - |
7 |
| -## Python client module |
8 |
| -The Python client module is the easiest way to programmatically use <MainPlatformNameLink />. You can use Python API or a command-line tool to easily work with <MainPlatformName /> projects, such as to get project status, push and pull changes, or to download, create and delete projects. |
9 |
| - |
10 |
| -The <GitHubRepo id="MerginMaps/python-api-client" /> repository contains the source code of the Python client module and more information on how to use it. |
| 10 | +## Installation |
| 11 | +The Python client module is the easiest way to programmatically use <MainPlatformNameLink />. You can use Python API or a command-line tool to easily work with your projects, such as to get project status, push and pull changes. You can also create user accounts and manage their roles. |
11 | 12 |
|
12 | 13 | Python client is available in the PyPI repository and can be installed with `pip`:
|
13 | 14 |
|
14 | 15 | ```
|
15 | 16 | pip3 install mergin-client
|
16 | 17 | ```
|
17 | 18 |
|
18 |
| -### Python module |
| 19 | +## Command line interface |
| 20 | +For those who prefer using terminal, there is `mergin` command line tool shipped with the Python client. With several built-in commands, it is possible to download <MainPlatformName /> projects, push/pull changes, create or delete projects and more. |
| 21 | + |
| 22 | +For example, to download a <MainPlatformName /> project to a local folder: |
| 23 | +``` |
| 24 | +mergin download john/project1 ~/mergin/project1 |
| 25 | +``` |
| 26 | +For more details, visit <GitHubRepo id="MerginMaps/python-api-client" />. |
| 27 | + |
| 28 | +## Python module |
19 | 29 | To use <MainPlatformNameLink /> from Python, just create `MerginClient` object and then use it. Here, for instance, to download a project:
|
20 | 30 |
|
21 | 31 | ```python
|
22 | 32 | import mergin
|
23 | 33 |
|
24 |
| -client = mergin.MerginClient(login='john', password='topsecret') |
| 34 | +client = mergin.MerginClient(login='john', password='T0p_secret') |
25 | 35 | client.download_project('lutraconsulting/Basic survey', '/tmp/basic-survey')
|
26 | 36 | ```
|
27 | 37 | If you have <QGISPluginName /> installed and you want to use it from the QGIS' Python console
|
28 | 38 |
|
29 | 39 | ```python
|
30 | 40 | import Mergin.mergin as mergin
|
31 |
| -client = mergin.MerginClient(login='john', password='topsecret') |
| 41 | +client = mergin.MerginClient(login='john', password='T0p_secret') |
32 | 42 | ```
|
33 | 43 |
|
34 |
| -### Python command line interface |
35 |
| -For those who prefer using terminal, there is `mergin` command line tool shipped with the Python client. With several built-in commands, it is possible to download <MainPlatformName /> projects, push/pull changes, create or delete projects and more. |
| 44 | +## API reference - users |
36 | 45 |
|
37 |
| -For example, to download a <MainPlatformName /> project to a local folder: |
| 46 | +You can create new users and manage their roles using the following methods. |
| 47 | + |
| 48 | +::: warning API availability |
| 49 | +The following methods are available for Python API Client versions `0.10.0` or higher, using server versions `2025.2.0` or higher. |
| 50 | +::: |
| 51 | + |
| 52 | +### Create a user |
| 53 | + |
| 54 | +```python |
| 55 | +client.create_user(<email>, <password>, <workspace_id>, <workspace_role>, [username], [notify_user]) |
38 | 56 | ```
|
39 |
| -mergin download john/project1 ~/mergin/project1 |
| 57 | + |
| 58 | +The caller must be a workspace admin, owner or server administrator. |
| 59 | + |
| 60 | +Arguments: |
| 61 | + |
| 62 | +`email` (string): Must be a unique email. |
| 63 | + |
| 64 | +`password` (string): Must meet security requirements. |
| 65 | + |
| 66 | +`workspace_id` (int) <span title="Ignored on Community edition servers">:information_source:</span> : The workspace ID where the user will be added. |
| 67 | + |
| 68 | +`workspace_role` (string) <span title="Ignored on Community edition servers">:information_source:</span> : The user’s role in the workspace. [See the roles options](../../manage/permissions/index.md#workspace-member-roles-overview). |
| 69 | + |
| 70 | +`username` (string, optional): If not provided, it will be automatically generated from the email address. |
| 71 | + |
| 72 | +`notify_user` (Boolean, optional): If true, confirmation email and other email communication will be sent to the email address (invitations, access requests etc.). Default is `False`. |
| 73 | + |
| 74 | +Example: |
| 75 | +```python |
| 76 | +client.create_user( "[email protected]", "T0p_secret", 1, "editor", notify_user=True) |
40 | 77 | ```
|
41 |
| -For more details, visit <GitHubRepo id="MerginMaps/python-api-client" />. |
42 | 78 |
|
43 |
| -## C++ standalone client |
44 |
| -C++ Client has advantage over Python that it is completely without any dependencies. |
| 79 | +> :information_source: `workspace_id` and `workspace_role` arguments are ignored on Community edition servers. |
| 80 | +
|
| 81 | +--- |
| 82 | + |
| 83 | +### Workspace members methods |
| 84 | + |
| 85 | +These methods are available for Cloud and Enterprise edition servers. |
| 86 | + |
| 87 | +::: warning API availability |
| 88 | +The following methods are available for Python API Client versions `0.10.0` or higher, using server versions `2025.2.0` or higher. |
| 89 | +::: |
45 | 90 |
|
46 |
| -To install the C++ client, just download the binary for your platform from <GitHubRepo id="MerginMaps/cpp-api-client/releases"/> and use it from the command line. |
| 91 | +The caller of the following methods must be a workspace admin, owner or server administrator. |
47 | 92 |
|
48 |
| -Go to <GitHubRepo id="MerginMaps/cpp-api-client" /> repository for more information on how to use it. |
| 93 | +#### List members |
49 | 94 |
|
50 |
| -### C++ Command line tool |
51 |
| -When the client is installed, it comes with `mergin` command line tool. |
| 95 | +```python |
| 96 | +client.list_workspace_members(<workspace_id>) |
| 97 | +``` |
| 98 | +Arguments: |
52 | 99 |
|
53 |
| -```bash |
54 |
| -$ mergin --help |
55 |
| -Usage: mergin [OPTIONS] COMMAND [ARGS]... |
| 100 | +`workspace_id` (int): ID of the workspace. |
56 | 101 |
|
57 |
| -Options: |
58 |
| - --help Show this message and exit. |
59 |
| - --version Show the version information. |
60 |
| - --username Mergin username (or MERGIN_USERNAME env. variable) |
61 |
| - --password Mergin password (or MERGIN_PASSWORD env. variable) |
62 |
| - --url Mergin url (defaults to app.merginmaps.com) |
| 102 | +#### Get member detail |
63 | 103 |
|
64 |
| -Commands: |
65 |
| - create Create a new project on Mergin server |
66 |
| - download Download last version of mergin project |
67 |
| - sync Pull&Push the changes |
68 |
| - remove Remove project from server. |
| 104 | +```python |
| 105 | +client.get_workspace_member(<workspace_id>, <user_id>) |
69 | 106 | ```
|
| 107 | +Arguments: |
| 108 | + |
| 109 | +`workspace_id` (int): ID of the workspace. |
| 110 | + |
| 111 | +`user_id` (int): ID of the user. |
| 112 | + |
| 113 | +#### Update member role |
| 114 | + |
| 115 | +```python |
| 116 | +client.update_workspace_member(<workspace_id>, <user_id>, <workspace_role>, [reset_projects_roles]) |
| 117 | +``` |
| 118 | +Arguments: |
| 119 | + |
| 120 | +`workspace_id` (int): ID of the workspace. |
| 121 | + |
| 122 | +`user_id` (int): ID of the user. |
| 123 | + |
| 124 | +`workspace_role` (string): New role. [See the roles options](../../manage/permissions/index.md#workspace-member-roles-overview). |
| 125 | + |
| 126 | +`reset_projects_roles` (Boolean, optional): If true, overridden project roles (explicitly shared projects access) will be reset. Default is `False`. |
| 127 | + |
| 128 | +#### Remove member |
| 129 | + |
| 130 | +```python |
| 131 | +client.remove_workspace_member(<workspace_id>, <user_id>) |
| 132 | +``` |
| 133 | +Arguments: |
| 134 | + |
| 135 | +`workspace_id` (int): ID of the workspace. |
| 136 | + |
| 137 | +`user_id` (int): ID of the user. |
| 138 | + |
| 139 | +> The user account is not removed. This method only removes their access to the workspace. |
| 140 | +
|
| 141 | +--- |
| 142 | + |
| 143 | +### Project collaborators methods |
| 144 | + |
| 145 | +These methods are available for all server types. |
| 146 | + |
| 147 | +::: warning API availability |
| 148 | +The following methods are available for Python API Client versions `0.10.0` or higher, using server versions `2025.2.0` or higher. |
| 149 | +::: |
| 150 | + |
| 151 | +The caller of the following methods must be a workspace admin, owner, project owner or server administrator. |
| 152 | + |
| 153 | +The following methods accept project ids (of type `uuid`). You can find project id via <GitHubRepo id="MerginMaps/python-api-client/blob/634237890afd9f28f03953e5a01376b56f5abf5c/mergin/client.py#L572" desc="projects_list" /> and <GitHubRepo id="MerginMaps/python-api-client/blob/634237890afd9f28f03953e5a01376b56f5abf5c/mergin/client.py#L641" desc="project_info" /> methods. |
| 154 | + |
| 155 | +#### List project collaborators |
| 156 | + |
| 157 | +```python |
| 158 | +client.list_project_collaborators(<project_id>) |
| 159 | +``` |
| 160 | +Arguments: |
| 161 | + |
| 162 | +`project_id` (string): ID of the project. |
| 163 | + |
| 164 | +#### Add project collaborator |
| 165 | + |
| 166 | +Adds a user as project collaborator. This method is good for sharing projects with guests or upgrading roles of members for specific projects. |
| 167 | +On Cloud, the user must be a in the workspace where the project belongs. |
| 168 | + |
| 169 | +```python |
| 170 | +client.add_project_collaborator(<project_id>, <user>, <project_role>) |
| 171 | +``` |
| 172 | +Arguments: |
| 173 | + |
| 174 | +`project_id` (string): ID of the project. |
| 175 | + |
| 176 | +`user` (string): Email or username of the user to be added to the project. |
| 177 | + |
| 178 | +`project_role`: (string): Role of the user in the project. [See the roles options](../../manage/permissions/index.md#project-permissions-overview) |
| 179 | + |
| 180 | +#### Update project collaborator role |
| 181 | + |
| 182 | +```python |
| 183 | +client.update_project_collaborator(<project_id>, <user_id>, <project_role>) |
| 184 | +``` |
| 185 | +Arguments: |
| 186 | + |
| 187 | +`project_id` (string): ID of the project. |
| 188 | + |
| 189 | +`user_id` (int): ID of the user. |
| 190 | + |
| 191 | +`project_role`: (string): New role. [See the roles options](../../manage/permissions/index.md#project-permissions-overview) |
| 192 | + |
| 193 | +> The user must be first added to the project (via [Add project collaborator](./index.md#add-project-collaborator)) before calling this method, even if he/she is already a workspace member or guest. |
| 194 | +
|
| 195 | +#### Remove project collaborator |
| 196 | + |
| 197 | +```python |
| 198 | +client.remove_project_collaborator(<project_id>, <user_id>) |
| 199 | +``` |
| 200 | +Arguments: |
| 201 | + |
| 202 | +`project_id` (string): ID of the project. |
| 203 | + |
| 204 | +`user_id` (int): ID of the user. |
| 205 | + |
| 206 | +> The user account is not removed, only the project access. |
70 | 207 |
|
71 |
| -### C++ Mergin Maps API core library |
| 208 | +## Further details |
72 | 209 |
|
73 |
| -Client is based on the Qt-based <GitHubRepo id="MerginMaps/mobile/tree/master/core" desc="Mergin Maps API core library" /> used by the <MainDomainNameLink desc="Mergin Maps mobile app" /> to sync the projects in the mobile application. |
| 210 | +The <GitHubRepo id="MerginMaps/python-api-client" /> repository contains the source code and more information on how to use it. |
0 commit comments