This sample notebook automates the task of creating groups in a Portal for ArcGIS or ArcGIS Online organization. A similar script can be used for creating or updating users and content.
Note: To run this sample, you need the pandas
library in your conda environment. If you don't have the library, install it by running the following command from cmd.exe or your shell
conda install pandas```
from arcgis.gis import GIS
from IPython.display import display
import pandas as pd
Data preparation
In this sample, a list of groups to be created is read from a .csv file along with the properties and thumbnails to be used for creating the groups.
groups_df = pd.read_csv('data/groups.csv')
groups_df[:3]
access | description | isFav | isInvitationOnly | isViewOnly | phone | snippet | sortField | sortOrder | tags | thumbnail | title | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | public | This group includes a complete list of basemap... | False | True | True | NaN | Standard basemaps for our organizations. | title | asc | Maps,Base,Basemap,Basemaps | data/Icons/Basemaps.png | Basemaps |
1 | org | This Group contains an inventory of map servic... | False | False | False | NaN | The authoritative service catalog. | title | asc | Services,Maps,Data | data/Icons/CentralServices.png | Central Services |
2 | org | A group dealing with government and industry a... | False | False | False | NaN | Regulatory compliance tracking & reporting. | modified | asc | Regulatory,Compliance | data/Icons/RegCompliance.png | Compliance |
gis = GIS("https://pythonapi.playground.esri.com/portal", "arcgis_python", "amazing_arcgis_123")
Before we proceed, we will verify if these groups do not exist in our organization. If they exist, we will delete them so that we can re-create as part of the process that follows.
for group_name in groups_df['title']:
g = gis.groups.search(query='title:'+group_name)
#if group exists with the title, delete it
if len(g)>0:
g[0].delete()
The thumbnails are extracted from an Icons.zip file.
import zipfile
with zipfile.ZipFile("data/Icons.zip") as z:
z.extractall("data")
The code below reads the csv file line by line and creates groups in the portal using the specified parameters and thumbnails.
import csv
groups = []
with open('data/groups.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
group = gis.groups.create_from_dict(row)
groups.append(group)
To verify, we can display the newly created groups:
for group in groups:
display(group)