Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dddf16d
Added proposal for sync
MarcelGeo May 27, 2025
9dbc582
added push an dpull using client.
MarcelGeo May 27, 2025
cb8807a
add user management example
fernandinand May 27, 2025
103e36c
Fix users creation from CSV section
fernandinand May 30, 2025
f892757
Add scenario for projects management
fernandinand May 30, 2025
9a4b8bf
Fix project version/status entry.
fernandinand May 30, 2025
3781d4c
some tnning and cleanup for 1. and 3. scenario
MarcelGeo Jun 9, 2025
cf73378
small tweaks
MarcelGeo Jun 9, 2025
a1c12e6
make images smaller
MarcelGeo Jun 9, 2025
b39e6bb
AB tteams tweaks
MarcelGeo Jun 9, 2025
90d582d
Add README with some basic info
fernandinand Jun 11, 2025
07218d5
Merge remote-tracking branch 'origin/master' into notebooks-examples
MarcelGeo Jun 12, 2025
df732ce
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
8ab9a87
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
180cc6a
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
efde843
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
7fd7581
Update examples/README.md
MarcelGeo Jun 16, 2025
c8258f3
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
7133736
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
7f8396c
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
5c0f5a9
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
3929c1b
Update examples/03_projects.ipynb
MarcelGeo Jun 16, 2025
c0378f4
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
ccedfe6
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
7056aed
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
0b3e6ce
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
9499c1f
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
96ee0a6
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
c566a27
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
55b743a
Update examples/02_sync.ipynb
MarcelGeo Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions examples/01_users.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"metadata": {
"kernelspec": {
"name": "python",
"display_name": "Python (Pyodide)",
"language": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
},
"colab": {
"provenance": [],
"collapsed_sections": [
"x8IVfy9K5Z4l",
"7VMIPQo2yTmQ"
],
"authorship_tag": "ABX9TyPXXcFNdfLOsA7CkWfkKXfJ"
}
},
"nbformat_minor": 4,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"source": "# Mergin Maps Users Management",
"metadata": {
"id": "ngTJ3YbHlb8s"
}
},
{
"cell_type": "markdown",
"source": "Mergin Maps API allows you to fully manage your workspace users, it's roles and project permissions.",
"metadata": {
"id": "q0eLjSMzlwdx"
}
},
{
"cell_type": "markdown",
"source": "First let's install mergin maps client",
"metadata": {
"id": "IKmFEjG-mmL6"
}
},
{
"cell_type": "code",
"source": "!pip install mergin-client",
"metadata": {
"id": "I_vpP6NnmqV7"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Login to Mergin Maps using your workspace user with `Owner` permission.",
"metadata": {
"id": "u05lxbRQm2VF"
}
},
{
"cell_type": "code",
"source": "# Use here your login username and password\nLOGIN=\"\"\nPASSW=\"\"\n\nimport mergin\n\nclient = mergin.MerginClient(login=LOGIN, password=PASSW)",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "dWQorVqZnRNl",
"executionInfo": {
"status": "ok",
"timestamp": 1748364457967,
"user_tz": -60,
"elapsed": 1822,
"user": {
"displayName": "Fernando Ribeiro",
"userId": "15488710231554262191"
}
},
"outputId": "778487c5-b0b5-4a7f-a024-33122e49b6fb",
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Let's create a dummy workspace and project as base for our users management example.\n\nChange the variable `WORKSPACE`with your desired workspace name and `PROJECT` with project name.",
"metadata": {
"id": "gFN3jXIjntwf"
}
},
{
"cell_type": "code",
"source": "# Add here your existing workspace name and the new project name\nWORKSPACE=\"\"\nPROJECT=\"\"\n\n# Create new workspace\n#INFO: Only uncomment if you are able to create a new workspace. Mergin Maps free tier only allows for 1 workspace per user. In this case use your existing workspace.\n#client.create_workspace(WORKSPACE) \n\n# Create new dummy project (public accessible)\nclient.create_project(project_name=PROJECT, namespace=WORKSPACE, is_public=True)",
"metadata": {
"id": "27rA4VfgoJjy",
"executionInfo": {
"status": "ok",
"timestamp": 1748364795430,
"user_tz": -60,
"elapsed": 745,
"user": {
"displayName": "Fernando Ribeiro",
"userId": "15488710231554262191"
}
}
},
"outputs": [],
"execution_count": 3
},
{
"cell_type": "markdown",
"source": "Create some users on your Mergin Maps example workspace from the provided example file in `01_users_assets/users.csv` with random permissions.",
"metadata": {
"id": "SXimIDIDqb9J"
}
},
{
"cell_type": "code",
"source": "import csv\nimport string\nimport random\n\nfrom mergin.common import WorkspaceRole\n\npermissions = [WorkspaceRole.EDITOR,\n WorkspaceRole.READER,\n WorkspaceRole.WRITER]\n\n\ntry:\n with open('01_users_assets/users.csv', mode='r', newline='', encoding='utf-8') as csvfile:\n reader = csv.reader(csvfile)\n header = next(reader) # Skip header\n first_data_row = next(reader) # Get first data row\n if len(first_data_row) >= 2: # Check if there are at least two columns\n username = first_data_row[0]\n email = first_data_row[1]\n # add new mergin maps user\n client.create_user(username=username, password=random.choices(string.ascii_uppercase + string.digits, k=12), email=email, workspace_id=WORKSPACE, workspace_role=random.choice(permissions))\n print(f\"User '{username}' created successfully.\")\n else:\n print(\"First data row does not have enough columns.\")\nexcept FileNotFoundError:\n print(f\"File '{filename}' not found for processing example.\")\nexcept StopIteration:\n print(f\"File '{filename}' does not contain enough data rows for processing example.\")\nexcept Exception as e:\n print(f\"An error occurred during processing example: {e}\")\n",
"metadata": {
"id": "Lp351dFYquVs"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Let's change permission level for a specific user to `READER`.",
"metadata": {
"id": "OoCFI9u7uClQ"
}
},
{
"cell_type": "code",
"source": "client.update_workspace_member(username='agreen', workspace_id=WORKSPACE, workspace_role=WorkspaceRole.READER)",
"metadata": {
"id": "6QG8Smj2uI2l"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Remove the same user from our dummy example project",
"metadata": {
"id": "PpSxZfRfujj7"
}
},
{
"cell_type": "code",
"source": "client.remove_project_collaborator(project_path='{workspace}/{project}'.format(workspace=WORKSPACE, project=PROJECT), username='agreen')",
"metadata": {
"id": "5_7lhNhVuukI"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Remove a user from an workspace",
"metadata": {}
},
{
"cell_type": "code",
"source": "client.remove_workspace_member(username='agreen', workspace_id=WORKSPACE)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
}
21 changes: 21 additions & 0 deletions examples/01_users_assets/users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
username,email
agreen,agreen@example.com
bsmith,bsmith@example.com
cjones,cjones@example.com
dwilliams,dwilliams@example.com
ebrown,ebrown@example.com
fdavis,fdavis@example.com
gmiller,gmiller@example.com
hwilson,hwilson@example.com
imoore,imoore@example.com
jtaylor,jtaylor@example.com
kanderson,kanderson@example.com
lthomas,lthomas@example.com
mjackson,mjackson@example.com
nwhite,nwhite@example.com
oharris,oharris@example.com
pmartin,pmartin@example.com
qthompson,qthompson@example.com
rgarcia,rgarcia@example.com
smartinez,smartinez@example.com
trobinson,trobinson@example.com
Loading
Loading