arcgis.gis module¶
The gis module provides an information model for GIS hosted within ArcGIS Online or ArcGIS Enterprise. This module provides functionality to manage (create, read, update and delete) GIS users, groups and content. This module is the most important and provides the entry point into the GIS.
GIS¶
-
class
arcgis.gis.
GIS
(url=None, username=None, password=None, key_file=None, cert_file=None, verify_cert=True, set_active=True, client_id=None, profile=None, **kwargs)¶ A GIS is representative of ArcGIS Online or ArcGIS Enterprise. The GIS object provides helper objects to manage (search, create, retrieve) GIS resources such as content, users, and groups.
Additionally, the GIS object has properties to query it’s state, accessible using the properties attribute.
The GIS provides a mapping widget that can be used in the Jupyter notebook environment for visualizing GIS content as well as the results of your analysis. To create a new map, call the map() method.
Constructs a GIS object given a url and user credentials to ArcGIS Online or an ArcGIS Portal. User credentials can be passed in using username/password pair, or key_file/cert_file pair (in case of PKI). Supports built-in users, LDAP, PKI, Integrated Windows Authentication (using NTLM and Kerberos) and Anonymous access.
If no url is provided, ArcGIS Online is used. If username/password or key/cert files are not provided, logged in user credentials (IWA) or anonymous access is used.
A persisted profile for the GIS can be created by giving the GIS and it’s authorization credentials and specifying a profile name. The profile is stored in the users home directory in a config file named .arcgisprofile The profile is NOT ENCRYPTED and you need to take care to protect the saved profile using operating system security or other means. Once a profile has been saved, passing the profile parameter by itself uses the authorization credentials saved in the configuration file by that profile name.
See https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/ for examples.
Argument
Description
url
optional string, if URL is None, then the URL will be ArcGIS Online. This should be a web address to either a local portal or to ArcGIS Online in the form: For Portal Example: <scheme>://<host>/<web_adatpor>
username
optional string, login user name (case sensative)
password
optional string, if a username is provided, a password is expected. This is case sensative. If the password is not provided, user is prompted.
key_file
optional string, file path to a user’s key certificate
cert_file
optional string, file path to a user’s key certificate
verify_cert
optional boolean, if a site has an invalid certificate, set the value to False. This will ensure that all SSL certification are ignore. The default is True. warning setting the value to False can be a security risk.
set_active
optional boolean, the default is True. If True, the GIS object will be used as the default GIS object throughout the whole scripting session.
client_id
optional string, used for OAuth athentication. This is the client ID value.
profile
optional string, if set the profile contains login information for a given site.
In addition to explicitly named variable, the GIS object supports optional key word arguments
kwargs
Description
proxy_host
optional string, host name of the proxy server
proxy_port
optional integer, proxy host port. The default is 80.
Usage Example 1: Anonymous Login to ArcGIS Online:
gis = GIS()
Usage Example 2: Built-in Login to ArcGIS Online:
gis = GIS(username=”someuser”, password=”secret1234”)
Usage Example 3: Built-in Login to ArcGIS Enterprise
- gis = GIS(url=”http://pythonplayground.esri.com/portal”,
username=”user1”, password=”password1”)
Usage Example 4: Built-in Login to ArcGIS Enterprise, ignoring SSL errors
- gis = GIS(url=”http://pythonplayground.esri.com/portal”,
username=”user1”, password=”password1”, verify_cert=False)
Usage Example 5: Anonymous ArcGIS Online Login with Proxy
gis = GIS(proxy_host=’127.0.0.1’, proxy_port=8888)
-
property
content
¶
-
property
groups
¶
-
map
(location=None, zoomlevel=None)¶ Creates a map widget centered at the location (Address or (lat, long) tuple) with the specified zoom-level(integer). If an Address is provided, it is geocoded using the GIS’s configured geocoders and if a match is found, the geographic extent of the matched address is used as the map extent. If a zoomlevel is also provided, the map is centered at the matched address instead and the map is zoomed to the specified zoomlevel.
Note: The map widget is only supported within Jupyter Notebook.
-
property
properties
¶
-
update_properties
(properties_dict)¶ Updates the GIS’s properties from those in properties_dict.
Argument
Description
item_properties
Required dictionary.
- Returns
The item if successfully added, None if unsuccessful.
-
property
users
¶
Item¶
-
class
arcgis.gis.
Item
(gis, itemid, itemdict=None)¶ Bases:
dict
An item (a unit of content) in the GIS. Each item has a unique identifier and a well known URL that is independent of the user owning the item. An item can have associated binary or textual data that’s available via the item data resource. For example, an item of type Map Package returns the actual bits corresponding to the map package via the item data resource.
Items that have layers (eg FeatureLayerCollection items and ImageryLayer items) and tables have the dynamic layers and tables properties to get to the individual layers/tables in this item.
-
add_comment
(comment)¶ Adds a comment to an item. Available only to authenticated users who have access to the item.
Argument
Description
comment
Required string. Text to be added as a comment to a specific item.
- Returns
Comment ID if successful, None on failure.
-
add_relationship
(rel_item, rel_type)¶ Adds a relationship from this item to rel_item.
Note
Relationships are not tied to an item. They are directional links from an origin item to a destination item and have a type. The type defines the valid origin and destination item types as well as some rules. See Relationship types in REST API help for more information. Users don’t have to own the items they relate unless so defined by the rules of the relationship type.
Users can only delete relationships they create.
Relationships are deleted automatically if one of the two items is deleted.
Argument
Description
rel_item
Required string. The related item ID.
rel_type
Required string. The type of the related item; is one of [‘Map2Service’, ‘WMA2Code’, ‘Map2FeatureCollection’, ‘MobileApp2Code’, ‘Service2Data’, ‘Service2Service’]. See Relationship types in REST API help for more information on this parameter.
- Returns
Returns True if the relationship was added, False if the add failed.
-
property
comments
¶ Returns a list of comments for a given item.
-
copy_feature_layer_collection
(service_name, layers=None, tables=None, folder=None, description=None, snippet=None, owner=None)¶ This operation allows users to copy existing Feature Layer Collections and select the layers/tables that the user wants in the service.
Argument
Description
service_name
Required string. It is the name of the service.
layers
Optional list/string. This is a either a list of integers or a comma seperated list of integers as a string. Each index value represents a layer in the feature layer collection.
tables
Optional list/string. This is a either a list of integers or a comma seperated list of integers as a string. Each index value represents a table in the feature layer collection.
folder
Optional string. This is the name of the folder to place in. The default is None, which means the root folder.
description
Optional string. This is the Item description of the service.
snippet
Optional string. This is the Item’s snippet of the service. It is no longer than 250 characters.
owner
Optional string/User. The default is the current user, but if you want the service to be owned by another user, pass in this value.
- Returns
Item on success. None on failure
-
create_tile_service
(title, min_scale, max_scale, cache_info=None, build_cache=False)¶ Allows publishers and administrators to publish hosted feature layers and hosted feature layer views as a tile service.
Argument
Description
title
Required string. The name of the new service. Example: “SeasideHeightsNJTiles”
min_scale
Required float. The smallest scale at which to view data. Example: 577790.0
max_scale
Required float. The largest scale at which to view data. Example: 80000.0
cache_info
Optional dictionary. If not none, administrator provides the tile cache info for the service. The default is the AGOL scheme.
build_cache
Optional boolean. Default is False; if True, the cache will be built at publishing time. This will increase the time it takes to publish the service.
- Returns
The item if successfully added, None if unsuccessful.
-
delete
()¶ Deletes an item.
- Returns
A boolean indicating success (True) or failure (False).
-
delete_rating
()¶ Removes the rating the calling user added for the specified item.
-
delete_relationship
(rel_item, rel_type)¶ Deletes a relationship between this item and the rel_item.
Argument
Description
rel_item
Required string. The related item ID.
rel_type
Required string. The type of the related item; is one of [‘Map2Service’, ‘WMA2Code’, ‘Map2FeatureCollection’, ‘MobileApp2Code’, ‘Service2Data’, ‘Service2Service’]. See Relationship types in REST API help for more information on this parameter.
- Returns
Returns True if the relationship was deleted, False if the deletion failed.
-
dependent_to
()¶ Returns items, urls, etc that are dependent to this item.
-
dependent_upon
()¶ Returns items, urls, etc that this item is dependent on.
-
download
(save_path=None)¶ Downloads the data to the specified folder or a temporary folder if a folder is not provided.
Argument
Description
save_path
Optional string. Folder location to download the file to.
- Returns
The download path if data was available, otherwise None.
-
download_metadata
(save_folder=None)¶ Downloads the item metadata for the specified item id. Items with metadata have ‘Metadata’ in their typeKeywords.
Argument
Description
save_folder
Optional string. Folder location to download the item’s metadata to.
- Returns
For a successful download of metadata, a file path. None if the item does not have metadata.
-
download_thumbnail
(save_folder=None)¶ Downloads the thumbnail for this item.
Argument
Description
save_folder
Optional string. Folder location to download the item’s thumbnail to.
- Returns
For a successful download of the thumbnail, a file path. None if the item does not have a thumbnail.
-
export
(title, export_format, parameters=None, wait=True)¶ Exports a service item to the specified export format. Available only to users with an organizational subscription. Invokable only by the service item owner or an administrator. This is useful for long running exports that could hold up a script.
Argument
Description
title
Required string. The desired name of the exported service item.
export_format
Required string. The format to export the data to. Allowed types: ‘Shapefile’, ‘CSV’, ‘File Geodatabase’, ‘Feature Collection’, ‘GeoJson’, ‘Scene Package’, ‘KML’
parameters
Optional string. A JSON object describing the layers to be exported and the export parameters for each layer. See http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Item/02r30000008s000000/ for guidance.
wait
Optional boolean. Default is True, which forces a wait for the export to complete; use False for when it is okay to proceed while the export continues to completion.
- Returns
Item or dictionary. Item is returned when wait=True. A dictionary describing the status of the item is returned when wait=False.
-
get_data
(try_json=True)¶ Retrieves the data component of an item and returns the data associated with an item.
Argument
Description
try_json
Optional string. Default is True. For JSON/text files, if try_json is True, the method tries to convert the data to a Python dictionary (use json.dumps(data) to convert the dictionary to a string), otherwise the data is returned as a string.
- Returns
Dependent on the content type of the data. For non-JSON/text data, binary files are returned and the path to the downloaded file. For JSON/text files, a Python dictionary or a string. All others will be a byte array, that can be converted to string using data.decode(‘utf-8’). Zero byte files will return None.
-
get_thumbnail
()¶ Retrieves the bytes that make up the thumbnail for this item.
- Returns
Bytes that represent the item.
Example
response = item.get_thumbnail() f = open(filename, 'wb') f.write(response)
-
get_thumbnail_link
()¶ URL to the thumbnail image.
-
property
homepage
¶ Returns the URL to the HTML page for the item.
-
property
metadata
¶ Retrieves the item metadata for the specified item. Returns None if the item does not have metadata. Items with metadata have ‘Metadata’ in their typeKeywords.
-
move
(folder, owner=None)¶ Moves this item to the folder with the given name.
Argument
Description
folder
Required string. The name of the folder to move the item to. Use ‘/’ for the root folder. For other folders, pass in the folder name as a string, or a dictionary containing the folder ID, such as the dictionary obtained from the folders property.
owner
Optional string or Owner object. The name of the user to move to.
- Returns
A json object like the following: {“success”: true | false,
”itemId”: “<item id>”, “owner”: “<owner username>”, “folder”: “<folder id>”}
-
protect
(enable=True)¶ Enables or disables delete protection on this item.
Argument
Description
enable
Optional boolean. Default is True which enables delete protection, False to disable delete protection.
- Returns
A json object like the following: {“success”: true | false}
-
property
proxies
¶ All ArcGIS Online hosted proxy services set on a registered app item with the Registered App type keyword. This resource is only available to the item owner and the organization administrator.
-
publish
(publish_parameters=None, address_fields=None, output_type=None, overwrite=False, file_type=None)¶ Publishes a hosted service based on an existing source item (this item). Publishers can create feature, tiled map, vector tile and scene services.
Feature services can be created using input files of type csv, shapefile, serviceDefinition, featureCollection, and fileGeodatabase. CSV files that contain location fields (i.e. address fields or XY fields) are spatially enabled during the process of publishing. Shapefiles and file geodatabases should be packaged as *.zip files.
Tiled map services can be created from service definition (*.sd) files, tile packages, and existing feature services.
Vector tile services can be created from vector tile package (*.vtpk) files.
Scene services can be created from scene layer package (*.spk, *.slpk) files.
Service definitions are authored in ArcGIS for Desktop and contain both the cartographic definition for a map as well as its packaged data together with the definition of the geo-service to be created.
Note
ArcGIS does not permit overwriting if you published multiple hosted feature layers from the same data item.
Argument
Description
publish_parameters
Optional dictionary. containing publish instructions and customizations. Cannot be combined with overwrite. See http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Publish_Item/02r300000080000000/ for details.
address_fields
Optional dictionary. containing mapping of df columns to address fields, eg: { “CountryCode” : “Country”} or { “Address” : “Address” }
output_type
Optional string. Only used when a feature service is published as a tile service. eg: output_type=’Tiles’
overwrite
Optional boolean. If True, the hosted feature service is overwritten. Only available in ArcGIS Online and Portal for ArcGIS 10.5 or later.
file_type
Optional string. Some formats are not automatically detected, when this occurs, the file_type can be specified: serviceDefinition,shapefile,csv, tilePackage, featureService, featureCollection, fileGeodatabase, geojson, scenepackage, vectortilepackage, imageCollection, mapService, and sqliteGeodatabase are valid entries. This is an optional parameter.
- Returns
An arcgis.gis.Item object corresponding to the published web layer.
For publish_parameters, see http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Publish_Item/02r300000080000000/
-
property
rating
¶ - Returns
Returns the rating given by the current user to the item, if any.
-
reassign_to
(target_owner, target_folder=None)¶ Allows the administrator to reassign a single item from one user to another.
Note
If you wish to move all of a user’s items (and groups) to another user then use the user.reassign_to() method. This method only moves one item at a time.
Argument
Description
item_id
Required string. The unique identifier for the item.
target_owner
Required string. The new desired owner of the item.
target_folder
Optional string. The folder to move the item to.
- Returns
A boolean indicating success (True) with the ID of the reassigned item, or failure (False).
Retrieves the items related to this item. Relationsships can be added and deleted using item.add_relationship() and item.delete_relationship(), respectively.
Argument
Description
rel_type
Required string. The type of the related item; is one of [‘Map2Service’, ‘WMA2Code’, ‘Map2FeatureCollection’, ‘MobileApp2Code’, ‘Service2Data’, ‘Service2Service’]. See Relationship types in REST API help for more information on this parameter.
direction
Required string. One of [‘forward’, ‘reverse’]
- Returns
The list of related items.
Shares an item with the specified list of groups.
Argument
Description
everyone
Optional boolean. Default is False, don’t share with everyone.
org
Optional boolean. Default is False, don’t share with the organization.
groups
Optional list of group names as strings, or a list of arcgis.gis.Group objects, or a comma-separated list of group IDs.
allow_members_to_edit
Optional boolean. Default is False, to allow item to be shared with groups that allow shared update
- Returns
A dictionary with key “notSharedWith” containing array of groups with which the item could not be shared.
-
status
(job_id=None, job_type=None)¶ Provides the status when publishing an item, adding an item in async mode, or adding with a multipart upload. “Partial” is available for Add Item Multipart, when only a part is uploaded and the item is not committed.
Argument
Description
job_id
Optional string. The job ID returned during publish, generateFeatures, export, and createService calls.
job_type
Optional string. The type of asynchronous job for which the status has to be checked. Default is none, which checks the item’s status. This parameter is optional unless used with the operations listed below. Values: publish, generateFeatures, export, and createService
- Returns
The status of a publishing item.
Stops sharing of the item with the specified list of groups.
Argument
Description
groups
Optional list of group names as strings, or a list of arcgis.gis.Group objects, or a comma-separated list of group IDs.
- Returns
Dictionary with key “notUnsharedFrom” containing array of groups from which the item could not be unshared.
-
update
(item_properties=None, data=None, thumbnail=None, metadata=None)¶ Updates an item in a Portal.
Note
Content can be a file (such as a layer package, geoprocessing package, map package) or a URL (to an ArcGIS Server service, WMS service, or an application).
To upload a package or other file, provide a path or URL to the file in the data argument.
For item_properties, pass in arguments for only the properties you want to be updated. All other properties will be untouched. For example, if you want to update only the item’s description, then only provide the description argument in item_properties.
Argument
Description
item_properties
Required dictionary. See table below for the keys and values.
data
Optional string. Either a path or URL to the data.
thumbnail
Optional string. Either a path or URL to a thumbnail image.
metadata
Optional string. Either a path or URL to the metadata.
Key:Value Dictionary Options for Argument item_properties
Key
Value
type
Optional string. Indicates type of item, see URL 1 below for valid values.
typeKeywords
Optional string. Provide a lists all sub-types, see URL 1 below for valid values.
description
Optional string. Description of the item.
title
Optional string. Name label of the item.
url
Optional string. URL to item that are based on URLs.
tags
Optional string. Tags listed as comma-separated values, or a list of strings. Used for searches on items.
snippet
Optional string. Provide a short summary (limit to max 250 characters) of the what the item is.
extent
Optional string. Provide comma-separated values for min x, min y, max x, max y.
spatialReference
Optional string. Coordinate system that the item is in.
accessInformation
Optional string. Information on the source of the content.
licenseInfo
Optional string. Any license information or restrictions regarding the content.
culture
Optional string. Locale, country and language information.
access
Optional string. Valid values are private, shared, org, or public.
commentsEnabled
Optional boolean. Default is true, controls whether comments are allowed (true) or not allowed (false).
URL 1: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000000ms000000
- Returns
A boolean indicating success (True) or failure (False).
-
User¶
-
class
arcgis.gis.
User
(gis, username, userdict=None)¶ Bases:
dict
Represents a registered user of the GIS (ArcGIS Online, or Portal for ArcGIS).
-
delete
(reassign_to=None)¶ Deletes this user from the portal, optionally deleting or reassigning groups and items.
Note
You can not delete a user in Portal if that user owns groups or items. If you specify someone in the reassign_to argument then items and groups will be transferred to that user. If that argument is not set then the method will fail if the user has items or groups that need to be reassigned.
Argument
Description
reassign_to
optional string or User, new owner of items and groups
- Returns
a boolean indicating whether the operation succeeded or failed.
-
disable
()¶ The Disable operation (POST only) disables login access for the user. It is only available to the administrator of the organization
-
download_thumbnail
(save_folder=None)¶ Downloads the item thumbnail for this user, returns file path.
-
enable
()¶ The Disable operation (POST only) disables login access for the user. It is only available to the administrator of the organization
-
property
folders
¶ list of the user’s folders
-
get_thumbnail
()¶ Returns the bytes that make up the thumbnail for this user.
- Arguments
None.
- Returns
bytes that represent the image.
Example
response = user.get_thumbnail() f = open(filename, 'wb') f.write(response)
-
get_thumbnail_link
()¶ URL to the thumbnail image
-
items
(folder=None, max_items=100)¶ Returns a list of items in the specified folder.
For content in the root folder, use the default value of None for the folder.
For other folders, pass in the folder name as a string, or a dict containing the folder ‘id’, such as the dict obtained from the folders property.
-
property
notifications
¶ The list of notifications available for the given user.
-
reassign_to
(target_username)¶ Reassigns all of this user’s items and groups to another user.
Items are transferred to the target user into a folder named <user>_<folder> where user corresponds to the user whose items were moved and folder corresponds to the folder that was moved.
Note
This method must be executed as an administrator. This method also can not be undone. The changes are immediately made and permanent.
Argument
Description
target_username
required string or User, user who will own items/groups after this.
- Returns
a boolean indicating success
-
reset
(password, new_password=None, new_security_question=None, new_security_answer=None)¶ Resets a user’s password, security question, and/or security answer.
Note
This function does not apply to those using enterprise accounts that come from an enterprise such as ActiveDirectory, LDAP, or SAML. It only has an effect on built-in users.
If a new security question is specified, a new security answer should be provided.
Argument
Description
password
required string, current password
new_password
optional string, new password if resetting password
new_security_question
optional int, new security question if desired
new_security_answer
optional string, new security question answer if desired
- Returns
a boolean, indicating success
-
update
(access=None, preferred_view=None, description=None, tags=None, thumbnail=None, fullname=None, email=None, culture=None, region=None)¶ Updates this user’s properties.
Note
Only pass in arguments for properties you want to update. All other properties will be left as they are. If you want to update description, then only provide the description argument.
Argument
Description
access
optional string, values: private, org, public
preferred_view
optional string, values: Web, GIS, null
description
optional string, a description of the user.
tags
optional string (comma-separated tags) or list of tags
thumbnail
optional string, path or url to a file. can be PNG, GIF, JPEG, max size 1 MB
fullname
optional string, name of the user, only for built-in users
email
optional string, email address, only for built-in users
culture
optional string, two-letter language code, fr for example
region
optional string, two-letter country code, FR for example
- Returns
a boolean indicating success
-
update_role
(role)¶ Updates this user’s role to org_user, org_publisher, org_admin or a custom role
Note
There are four types of roles in Portal - user, publisher, administrator and custom roles A user can share items, create maps, create groups, etc. A publisher can do everything a user can do and create hosted services. An administrator can do everything that is possible in Portal. A custom roles privileges can be customized
Argument
Description
role
required string, one of these values org_user, org_publisher, org_admin OR Role object (from gis.users.roles)
- Returns
a boolean, that indicates success
-
Group¶
-
class
arcgis.gis.
Group
(gis, groupid, groupdict=None)¶ Bases:
dict
Represents a group (for example, San Bernardino Fires) within the GIS (ArcGIS Online or Portal for ArcGIS)
-
add_users
(usernames)¶ Adds users to this group. .. note:
This method will only work if the user for the Portal object is either an administrator for the entire Portal or the owner of the group.
Argument
Description
usernames
list of usernames
- Returns
A dictionary with a key of “not_added” which contains the users that were not added to the group.
-
property
applications
¶ Lists the group applications for the given group. Available to administrators of the group or administrators of an organization if the group is part of one.
-
content
(max_items=1000)¶ Returns a list of items shared with this group.
-
delete
()¶ Deletes this group.
- Returns
a boolean indicating whether it was successful.
-
download_thumbnail
(save_folder=None)¶ Downloads the group thumbnail for this group, returns file path.
-
get_members
()¶ Returns members of this group.
- Arguments
None.
- Returns
a dictionary with keys: owner, admins, and users.
Key
Value
owner
string value, the group’s owner
admins
list of strings, typically this is the same as the owner
users
list of strings, the members of the group
Example (to print users in a group)
response = group.get_members() for user in response['users'] : print user
-
get_thumbnail
()¶ Returns the bytes that make up the thumbnail for this group.
- Arguments
None
- Returns
bytes that represent the image.
Example
response = group.get_thumbnail() f = open(filename, 'wb') f.write(response)
-
get_thumbnail_link
()¶ URL to the thumbnail image
-
invite_users
(usernames, role='group_member', expiration=10080)¶ Invites users to this group.
Note
A user who is invited to this group will see a list of invitations in the “Groups” tab of portal listing invitations. The user can either accept or reject the invitation.
- Requires
The user executing the command must be group owner
Argument
Description
usernames:
a required string list of users to invite
role:
an optional string, either group_member or group_admin
expiration:
an optional int, specifies how long the invitation is valid for in minutes.
- Returns
a boolean that indicates whether the call succeeded.
-
join
()¶ Users apply to join a group using the Join Group operation. This creates a new group application, which the group administrators accept or decline. This operation also creates a notification for the user indicating that they have applied to join this group. Available only to authenticated users. Users can only apply to join groups to which they have access. If the group is private, users will not be able to find it to ask to join it. Information pertaining to the applying user, such as their full name and username, can be sent as part of the group application.
-
leave
()¶ Removes the logged in user from the specified group.
- Requires:
User must be logged in.
- Arguments:
None.
- Returns
a boolean indicating whether the operation was successful.
-
reassign_to
(target_owner)¶ Reassigns this group to another owner.
Argument
Description
target_owner
required string, username of new group owner
- Returns
a boolean, indicating success
-
remove_users
(usernames)¶ Remove users from this group.
Argument
Description
usernames
required string, comma-separated list of users
- Returns
a dictionary with a key notRemoved that is a list of users not removed.
-
update
(title=None, tags=None, description=None, snippet=None, access=None, is_invitation_only=None, sort_field=None, sort_order=None, is_view_only=None, thumbnail=None)¶ Updates this group.
Note
Only provide the values for the arguments you wish to update.
Argument
Description
title
optional string, name of the group
tags
optional string (comma-delimited list of tags) or list of tags as strings
description
optional string, describes group in detail
snippet
optional string, <250 characters summarizes group
access
optional string, can be private, public, or org
thumbnail
optional string, URL or file location to group image
is_invitation_only
optional boolean, defines whether users can join by request.
sort_field
optional string, specifies how shared items with the group are sorted.
sort_order
optional string, asc or desc for ascending or descending.
is_view_only
optional boolean, defines whether the group is searchable
- Returns
a boolean indicating success
-
Datastore¶
-
class
arcgis.gis.
Datastore
(datastore, path)¶ Bases:
dict
Represents a datastore (folder, database or bigdata fileshare) within the GIS’s data store.
-
property
datasets
¶ Returns the datasets in the data store (currently implemented for big data file shares.)
-
delete
()¶ Unregisters this data item from the data store.
-
property
manifest
¶ The manifest resource for bigdata fileshares.
-
property
ref_count
¶ The total number of references to this data item that exist on the server. You can use this property to determine if this data item can be safely deleted (or taken down for maintenance).
-
update
(item)¶ Edits this data item to update its connection information.
Argument
Description
item
Required dictionary. The representation of the updated item.
- Returns
True if successful.
-
validate
()¶ Validates that this data item’s path (for file shares) or connection string (for databases) is accessible to every server node in the site.
- Returns
True if successful.
-
property
Role¶
-
class
arcgis.gis.
Role
(gis, role_id, role)¶ Bases:
object
A custom role in the GIS
-
delete
()¶ Deletes this role and returns True if the operation was successful
-
property
description
¶ Description of the custom role
-
property
name
¶ Name of the custom role
-
property
privileges
¶ Privileges for the custom role as a list of strings
Supported privileges with predefined permissions are: Administrative Privileges:
Members
portal:admin:viewUsers: grants the ability to view full member account information within organization.
portal:admin:updateUsers: grants the ability to update member account information within organization.
portal:admin:deleteUsers: grants the ability to delete member accounts within organization.
portal:admin:inviteUsers: grants the ability to invite members to organization. (This privilege is only applicable to ArcGIS Online.)
portal:admin:disableUsers: grants the ability to enable and disable member accounts within organization.
portal:admin:changeUserRoles: grants the ability to change the role a member is assigned within organization; however, it does not grant the ability to promote a member to, or demote a member from, the Administrator role. That privilege is reserved for the Administrator role alone.
portal:admin:manageLicenses: grants the ability to assign licenses to members of organization.
portal:admin:reassignUsers: grants the ability to assign all groups and content of a member to another within organization.
Groups
portal:admin:viewGroups: grants the ability to view all groups within organization.
portal:admin:updateGroups: grants the ability to update groups within organization.
portal:admin:deleteGroups: grants the ability to delete groups within organization.
portal:admin:reassignGroups: grants the ability to reassign groups to other members within organization.
portal:admin:assignToGroups: grants the ability to assign members to, and remove members from, groups within organization.
portal:admin:manageEnterpriseGroups: grants the ability to link group membership to an enterprise group. (This privilege is only applicable to Portal for ArcGIS.)
Content
portal:admin:viewItems: grants the ability to view all content within organization.
portal:admin:updateItems: grants the ability to update content within organization.
portal:admin:deleteItems: grants the ability to delete content within organization.
portal:admin:reassignItems: grants the ability to reassign content to other members within organization.
portal:admin:shareToGroup: grants the ability to share other member’s content to groups the user belongs to.
portal:admin:shareToOrg: grants the ability to share other member’s content to organization.
portal:admin:shareToPublic: grants the ability to share other member’s content to all users of the portal.
ArcGIS Marketplace Subscriptions
marketplace:admin:purchase: grants the ability to request purchase information about apps and data in ArcGIS Marketplace. (This privilege is only applicable to ArcGIS Online.)
marketplace:admin:startTrial: grants the ability to start trial subscriptions in ArcGIS Marketplace. (This privilege is only applicable to ArcGIS Online.)
marketplace:admin:manage: grants the ability to create listings, list items and manage subscriptions in ArcGIS Marketplace. (This privilege is only applicable to ArcGIS Online.)
Publisher Privileges:
Content
portal:publisher:publishFeatures: grants the ability to publish hosted feature layers from shapefiles, CSVs, etc.
portal:publisher:publishTiles: grants the ability to publish hosted tile layers from tile packages, features, etc.
portal:publisher:publishScenes: grants the ability to publish hosted scene layers.
User Privileges:
Groups
portal:user:createGroup: grants the ability for a member to create, edit, and delete their own groups.
portal:user:joinGroup: grants the ability to join groups within organization.
portal:user:joinNonOrgGroup: grants the ability to join groups external to the organization. (This privilege is only applicable to ArcGIS Online.)
Content
portal:user:createItem: grants the ability for a member to create, edit, and delete their own content.
Sharing
portal:user:shareToGroup: grants the ability to share content to groups.
portal:user:shareToOrg: grants the ability to share content to organization.
portal:user:shareToPublic: grants the ability to share content to all users of portal.
portal:user:shareGroupToOrg: grants the ability to make groups discoverable by the organization.
portal:user:shareGroupToPublic: grants the ability to make groups discoverable by all users of portal.
Premium Content
premium:user:geocode: grants the ability to perform large-volume geocoding tasks with the Esri World Geocoder such as publishing a CSV of addresses as hosted feature layer.
premium:user:networkanalysis: grants the ability to perform network analysis tasks such as routing and drive-time areas.
premium:user:geoenrichment: grants the ability to geoenrich features.
premium:user:demographics: grants the ability to make use of premium demographic data.
premium:user:spatialanalysis: grants the ability to perform spatial analysis tasks.
premium:user:elevation: grants the ability to perform analytical tasks on elevation data.
Features
features:user:edit: grants the ability to edit features in editable layers, according to the edit options enabled on the layer.
features:user:fullEdit: grants the ability to add, delete, and update features in a hosted feature layer regardless of the editing options enabled on the layer.
Open Data
opendata:user:openDataAdmin: grants the ability to manage Open Data Sites for the organization. (This privilege is only applicable to ArcGIS Online.)
opendata:user:designateGroup: grants the ability to designate groups within organization as being available for use in Open Data. (This privilege is only applicable to ArcGIS Online.)
-
Layer¶
-
class
arcgis.gis.
Layer
(url, gis=None)¶ Bases:
arcgis.gis._GISResource
The layer is a primary concept for working with data in a GIS.
Users create, import, export, analyze, edit, and visualize layers.
Layers can be added to and visualized using maps. They act as inputs to and outputs from analysis tools.
Layers are created by publishing data to a GIS, and are exposed as a broader resource (Item) in the GIS. Layer objects can be obtained through the layers attribute on layer Items in the GIS.
-
classmethod
fromitem
(item, index=0)¶ returns the layer at the specified index from a layer item :param item: an item representing a layer :param index: optional, the index of the layer amongst the item’s layers :return: the layer at the specified index
-
classmethod
ContentManager¶
-
class
arcgis.gis.
ContentManager
(gis)¶ Helper class for managing content in ArcGIS Online or ArcGIS Enterprise. This class is not created by users directly. An instance of this class, called ‘content’, is available as a property of the GIS object. Users call methods on this ‘content’ object to manipulate (create, get, search, etc) items.
-
add
(item_properties, data=None, thumbnail=None, metadata=None, owner=None, folder=None)¶ Adds content to the GIS by creating an item.
Note
Content can be a file (such as a service definition, shapefile, CSV, layer package, file geodatabase, geoprocessing package, map package) or it can be a URL (to an ArcGIS Server service, WMS service, or an application).
If you are uploading a package or other file, provide a path or URL to the file in the data argument.
From a technical perspective, none of the item_properties (see table below Key:Value Dictionary Options for Argument item_properties) are required. However, it is strongly recommended that arguments title, type, typeKeywords, tags, snippet, and description be provided.
Argument
Description
item_properties
Required dictionary. See table below for the keys and values.
data
Optional string. Either a path or URL to the data.
thumbnail
Optional string. Either a path or URL to a thumbnail image.
metadata
Optional string. Either a path or URL to the metadata.
owner
Optional string. Defaults to the logged in user.
folder
Optional string. Name of the folder where placing item.
Key:Value Dictionary Options for Argument item_properties
Key
Value
type
Optional string. Indicates type of item, see URL 1 below for valid values.
typeKeywords
Optional string. Provide a lists all sub-types, see URL 1 below for valid values.
description
Optional string. Description of the item.
title
Optional string. Name label of the item.
url
Optional string. URL to item that are based on URLs.
text
Optional string. For text based items such as Feature Collections & WebMaps
tags
Optional string. Tags listed as comma-separated values, or a list of strings. Used for searches on items.
snippet
Optional string. Provide a short summary (limit to max 250 characters) of the what the item is.
extent
Optional string. Provide comma-separated values for min x, min y, max x, max y.
spatialReference
Optional string. Coordinate system that the item is in.
accessInformation
Optional string. Information on the source of the content.
licenseInfo
Optional string. Any license information or restrictions regarding the content.
culture
Optional string. Locale, country and language information.
access
Optional string. Valid values are private, shared, org, or public.
commentsEnabled
Optional boolean. Default is true, controls whether comments are allowed (true) or not allowed (false).
culture
Optional string. Language and country information.
URL 1: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000000ms000000
- Returns
The item if successfully added, None if unsuccessful.
-
create_folder
(folder, owner=None)¶ Creates a folder with the given folder name, for the given owner. Does nothing if the folder already exists. If owner is not specified, owner is set as the logged in user.
Argument
Description
folder
Required string. The name of the folder to create for the owner.
owner
Optional string. User, folder owner, None for logged in user.
- Returns
A json object like the following if the folder was created: {“username” : “portaladmin”,”id” : “bff13218991c4485a62c81db3512396f”,”title” : “testcreate”}; None otherwise.
-
create_service
(name, service_description='', has_static_data=False, max_record_count=1000, supported_query_formats='JSON', capabilities=None, description='', copyright_text='', wkid=102100, create_params=None, service_type='featureService', owner=None, folder=None, item_properties=None)¶ Creates a service in the Portal.
Argument
Description
name
Required string. The unique name of the service.
service_description
Optional string. Description of the service.
has_static_data
Optional boolean. Indicating whether the data can change. Default is True, data is not allowed to change.
max_record_count
Optional integer. Maximum number of records in query operations.
supported_query_formats
Optional string. Formats in which query results are returned.
capabilities
Optional string. Specify service capabilities. If left unspecified, ‘Image,Catalog,Metadata,Download,Pixels’ are used for image services, and ‘Query’ is used for feature services, and ‘Query’ otherwise
description
Optional string. A user-friendly description for the published dataset.
copyright_text
Optional string. The copyright information associated with the dataset.
wkid
Optional integer. The well known id (WKID) of the spatial reference for the service. All layers added to a hosted feature service need to have the same spatial reference defined for the feature service. When creating a new empty service without specifying its spatial reference, the spatial reference of the hosted feature service is set to the first layer added to that feature service.
create_params
Optional dictionary. Add all create_service parameters into a dictionary. If this parameter is used, all the parameters above are ignored.
service_type
Optional string. The type of service to be created. Currently the options are imageService or featureService.
owner
Optional string. The username of the owner of the service being created.
folder
Optional string. The name of folder in which to create the service.
item_properties
Optional dictionary. See below for the keys and values
Key:Value Dictionary Options for Argument item_properties
Key
Value
type
Optional string. Indicates type of item, see URL 1 below for valid values.
typeKeywords
Optional string. Provide a lists all sub-types, see URL 1 below for valid values.
description
Optional string. Description of the item.
title
Optional string. Name label of the item.
url
Optional string. URL to item that are based on URLs.
tags
Optional string. Tags listed as comma-separated values, or a list of strings. Used for searches on items.
snippet
Optional string. Provide a short summary (limit to max 250 characters) of the what the item is.
extent
Optional string. Provide comma-separated values for min x, min y, max x, max y.
spatialReference
Optional string. Coordinate system that the item is in.
accessInformation
Optional string. Information on the source of the content.
licenseInfo
Optional string. Any license information or restrictions regarding the content.
culture
Optional string. Locale, country and language information.
access
Optional string. Valid values are private, shared, org, or public.
commentsEnabled
Optional boolean. Default is true, controls whether comments are allowed (true) or not allowed (false).
culture
Optional string. Language and country information.
- Returns
The item for the service, if successfully created, None if unsuccessful.
-
delete_folder
(folder, owner=None)¶ Deletes a folder for the given owner (logged in user by default) with the given folder name.
Argument
Description
folder
Required string. The name of the folder to delete.
owner
Optional string. User, folder owner, None for logged in user is the default.
- Returns
True if folder deletion succeeded, False if folder deletion failed.
-
get
(itemid)¶ Returns the item object for the specified itemid.
Argument
Description
itemid
Required string. The item identifier.
- Returns
None if the item is not found, or returns an item object if the item is found.
-
import_data
(df, address_fields=None, **kwargs)¶ Imports a Pandas data frame (that has an address column), or an arcgis spatial dataframe into the GIS.
Spatial dataframes are imported into the GIS and published as feature layers. Pandas dataframes that have an address column are imported as an in-memory feature collection. Note: By default, there is a limit of 1,000 rows/features for Pandas dataframes. This limit isn’t there for spatial dataframes.
Argument
Description
df
Required string. Pandas dataframe or arcgis.SpatialDataFrame
address_fields
Optional dictionary. Dictionary containing mapping of df columns to address fields, eg: { “CountryCode” : “Country”} or { “Address” : “Address” }.
title
Optional string. Title of the item. This is used for spatial dataframe objects.
tags
Optional string. Tags listed as comma-separated values, or a list of strings. Provide tags when publishing a spatial dataframe to the the GIS.
- Returns
Feature collection or feature layer that can be used for analysis, visualization or published to the GIS as an item.
-
is_service_name_available
(service_name, service_type)¶ For a desired service name, determines if that service name is available for use or not.
Argument
Description
service_name
Required string. A desired service name.
service_type
Required string. The type of service to be created. Currently the options are imageService or featureService.
- Returns
True if the specified service_name is available for the specified service_type, False if the service_name is unavailable.
-
search
(query, item_type=None, sort_field='avgRating', sort_order='desc', max_items=10, outside_org=False)¶ Searches for portal items.
Note
A few things that will be helpful to know…
The query syntax has many features that can’t be adequately described here. The query syntax is available in ArcGIS Help. A short version of that URL is http://bitly.com/1fJ8q31.
Most of the time when searching for items, you’ll want to search within your organization in ArcGIS Online or within your Portal. As a convenience, the method automatically appends your organization id to the query by default. If you want content from outside your organization set outside_org to True.
Argument
Description
query
Required string. A query string. See notes above.
item_type
Optional string. Set type of item to search. http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000000ms000000
sort_field
Optional string. Valid values can be title, uploaded, type, owner, modified, avgRating, numRatings, numComments, and numViews.
sort_order
Optional string. Valid values are asc or desc.
max_items
Optional integer. Maximum number of items returned, default is 10.
outside_org
Optional boolean. Controls whether to search outside your org (default is False, do not search ourside your org).
- Returns
A list of items matching the specified query.
-
UserManager¶
-
class
arcgis.gis.
UserManager
(gis)¶ Bases:
object
Helper class for managing GIS users. This class is not created by users directly. An instance of this class, called ‘users’, is available as a property of the Gis object. Users call methods on this ‘users’ object to manipulate (create, get, search…) users.
-
create
(username, password, firstname, lastname, email, description=None, role='org_user', provider='arcgis', idp_username=None, level=2, thumbnail=None)¶ This operation is used to pre-create built-in or enterprise accounts within the portal, or built-in users in an ArcGIS Online organization account.
The provider parameter is used to indicate the type of user account. Only an administrator can call this method.
To create a viewer account, choose role=’org_viewer’ and level=1
Argument
Description
username
required string, must be unique in the Portal, >=6 characters, =<24 characters
password
required string, must be >= 8 characters. This is a required parameter only if the provider is arcgis; otherwise, the password parameter is ignored. If creating an account in an ArcGIS Online org, it can be set as None to let the user set their password by clicking on a link that is emailed to him/her.
firstname
required string, the first name for the user
lastname
required string, the last name for the user
email
required string, must be an email address
description
An optional description string for the user account.
thumbnail
An optional string, URL to user image
role
The role for the user account. The default value is org_user. Values: org_user | org_publisher | org_admin | org_viewer
provider
The provider for the account. The default value is arcgis. Values: arcgis | enterprise
idp_username
The name of the user as stored by the enterprise user store. This parameter is
only required if the provider parameter is enterprise.
level
The account level. See http://server.arcgis.com/en/portal/latest/administer/linux/roles.htm
- Returns
the user, if created, else None
-
get
(username)¶ Returns the user object for the specified username.
- Arguments
username required string, the username whose user object you want.
- Returns
None if the user is not found and returns a user object if the user is found
-
property
me
¶ Returns the logged in user
-
property
roles
¶ Helper object to manage custom roles for users
-
search
(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False)¶ Searches portal users.
Returns a list of users matching the specified query
Note
A few things that will be helpful to know.
The query syntax has quite a few features that can’t be adequately described here. The query syntax is available in ArcGIS help. A short version of that URL is http://bitly.com/1fJ8q31.
Searching without specifying a query parameter returns a list of all users in your organization.
Most of the time when searching users you want to search within your organization in ArcGIS Online or within your Portal. As a convenience, the method automatically appends your organization id to the query by default. If you don’t want the API to append to your query set outside_org to True. If you use this feature with an OR clause such as field=x or field=y you should put this into parenthesis when using outside_org.
Argument
Description
query
optional string, query string. See notes. pass None to get list of all users in the org
sort_field
optional string, valid values can be username or created
sort_order
optional string, valid values are asc or desc
max_users
optional int, maximum number of users returned
outside_org
optional boolean, controls whether to search outside your org (default is False)
- Returns
A list of users:
-
signup
(username, password, fullname, email)¶ Signs up users to an instance of Portal for ArcGIS.
Argument
Description
username
required string, must be unique in the Portal, >4 characters
password
required string, must be >= 8 characters.
fullname
required string, name of the user
email
required string, must be an email address
- Returns
the user, if created, else None
-
GroupManager¶
-
class
arcgis.gis.
GroupManager
(gis)¶ Bases:
object
Helper class for managing GIS groups. This class is not created by users directly. An instance of this class, called ‘groups’, is available as a property of the Gis object. Users call methods on this ‘groups’ object to manipulate (create, get, search…) users.
-
create
(title, tags, description=None, snippet=None, access='public', thumbnail=None, is_invitation_only=False, sort_field='avgRating', sort_order='desc', is_view_only=False, auto_join=False, provider_group_name=None)¶ Creates a group and returns it if successful.
- Returns
the group, if created, or None
-
create_from_dict
(dict)¶ Create a group with parameters specified in the dict See help of create() method for parameters :return:
the group, if created, or None
-
get
(groupid)¶ Returns the group object for the specified groupid.
- Arguments
groupid required string, the group identifier
- Returns
None if the group is not found and returns a group object if the group is found
-
search
(query='', sort_field='title', sort_order='asc', max_groups=1000, outside_org=False)¶ Searches for portal groups.
Note
A few things that will be helpful to know.
- The query syntax has quite a few features that can’t
be adequately described here. The query syntax is available in ArcGIS help. A short version of that URL is http://bitly.com/1fJ8q31.
Searching without specifying a query parameter returns a list of all groups in your organization.
- Most of the time when searching groups you want to
search within your organization in ArcGIS Online or within your Portal. As a convenience, the method automatically appends your organization id to the query by default. If you don’t want the API to append to your query set outside_org to True.
Argument
Description
query
optional query string on Portal, required for Online. If not specified, all groups will be searched. See notes
sort_field
optional string, valid values can be title, owner, created
sort_order
optional string, valid values are asc or desc
max_groups
optional int, maximum number of groups returned
outside_org
optional boolean, controls whether to search outside your org
- Returns
Returns a list of groups matching the specified query
-
DatastoreManager¶
-
class
arcgis.gis.
DatastoreManager
(gis, admin_url, server)¶ Bases:
object
Helper class for managing the GIS data stores in on-premises ArcGIS Portals. This class is not created by users directly. Instances of this class are returned from arcgis.geoanalytics.get_datastores() and arcgis.raster.analytics.get_datastores() functions to get the corresponding datastores. Users call methods on this ‘datastores’ object to manage the datastores in a site federated with the portal.
-
add
(name, item)¶ Registers a new data item with the data store.
Argument
Description
name
Required string. The name of the item to be added on the server.
item
Required dictionary. The dictionary representing the data item. See http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000001s9000000
- Returns
The new data item is registered successfully, None otherwise.
-
add_bigdata
(name, server_path=None)¶ Registers a bigdata fileshare with the data store.
Argument
Description
name
Required string. The unique bigdata fileshare name on the server.
server_path
Optional string. The path to the folder from the server.
- Returns
The big data fileshare is registered successfully, None otherwise.
-
add_database
(name, conn_str, client_conn_str=None, conn_type='shared')¶ Registers a database with the data store.
Argument
Description
name
Required string. The unique database name on the server.
conn_str
Required string. the path to the folder from the server (and client, if shared or serverOnly database).
client_conn_str
Optional string. The connection string for client to connect to replicated enterprise database.
conn_type
Optional string. Choice of “<shared|replicated|serverOnly>”, shared is the default.
- Returns
The database is registered successfully, None otherwise.
-
add_folder
(name, server_path, client_path=None)¶ Registers a folder with the data store.
Argument
Description
name
Required string. The unique fileshare name on the server.
server_path
Required string. The path to the folder from the server (and client, if shared path).
client_path
Optional string. If folder is replicated, the path to the folder from the client.
- Returns
The folder is registered successfully, None otherwise.
-
property
config
¶ The data store configuration properties affect the behavior of the data holdings of the server. The properties include: blockDataCopy—When this property is False, or not set at all, copying data to the site when publishing services from a client application is allowed. This is the default behavior. When this property is True, the client application is not allowed to copy data to the site when publishing. Rather, the publisher is required to register data items through which the service being published can reference data. Values: True | False Note: If you specify the property as True, users will not be able to publish geoprocessing services and geocode services from composite locators. These service types require data to be copied to the server. As a workaround, you can temporarily set the property to False, publish the service, and then set the property back to True.
-
get
(path)¶ Returns the data item object at the given path.
Argument
Description
path
Required string. The path for the data item.
- Returns
None if the data item is not found at that path, and the data item object if it is found.
-
search
(parent_path=None, ancestor_path=None, types=None, id=None)¶ You can use this operation to search through the various data items registered in the server’s data store. Searching without specifying the parent path and other parameters returns a list of all registered data items.
Argument
Description
parentPath
Optional string. The path of the parent under which to find items. Pass ‘/’ to get the root data items.
ancestorPath
Optional string. The path of the ancestor under which to find items.
types
Optional string. A comma separated filter for the type of the items. Types include folder, egdb, bigDataFileShare, datadir.
id
Optional string. A filter to search by the ID of the item.
- Returns
A list of data items matching the specified query.
-
validate
()¶ Validates all items in the datastore and returns True if validated.
In order for a data item to be registered and used successfully within the GIS’s data store, you need to make sure that the path (for file shares) or connection string (for databases) is accessible to every server node in the site. To validate all registered data items all at once, you can invoke this operation.
-
RoleManager¶
-
class
arcgis.gis.
RoleManager
(gis)¶ Bases:
object
Helper class to manage custom roles for users in a GIS
-
all
(max_roles=1000)¶ Returns list of all roles in the GIS :param max_roles: the maximum number of roles to be returned :return: list of all roles in the GIS
-
create
(name, description, privileges=None)¶ Creates and returns a custom role with the specified parameters
-
exists
(role_name)¶ Checks to see if a role exists by it’s name :role_name: name of the role to look up Returns:
boolean
-
get_role
(role_id)¶ Returns the role with the specified role id. Returns list of all roles in the GIS if a role_id is not specified :param role_id: the role id of the role to get. Leave None to get all roles :return: the role with the specified role id or a list of all roles
-
ResourceManager¶
-
class
arcgis.gis.
ResourceManager
(item, gis)¶ Bases:
object
Helper class for managing resource files of an item. This class is not created by users directly. An instance of this class, called ‘resources’, is available as a property of the Item object. Users call methods on this ‘resources’ object to manage (add, remove, update, list, get) item resources.
-
add
(file=None, folder_name=None, file_name=None, text=None, archive=False)¶ The add resources operation adds new file resources to an existing item. For example, an image that is used as custom logo for Report Template. All the files are added to ‘resources’ folder of the item. File resources use storage space from your quota and are scanned for viruses. The item size is updated to include the size of added resource files. Each file added should be no more than 25 Mb.
Supported item types that allow adding file resources are: Vector Tile Service, Vector Tile Package, Style, Code Attachment, Report Template, Web Mapping Application, Feature Service, Web Map, Statistical Data Collection, Scene Service, and Web Scene.
Supported file formats are: JSON, XML, TXT, PNG, JPEG, GIF, BMP, PDF, MP3, MP4, and ZIP. This operation is only available to the item owner and the organization administrator.
Argument
Description
file
optional string, path to the file that needs to be added
folder_name
optional string, provide a folder name if the file has to be added to a folder under resources
file_name
optional string, file name used to rename an existing file resource uploaded, or to be used together with text as file name for it.
text
optional string, text input to be added as a file resource, used together with file_name. If this resource is used, then file_name become required.
archive
optional bool, default = False. If True, file resources added are extracted and files are uploaded to respective folders.
- Returns
Python dict like the following if succeeded: {
”success”: True, “itemId”: “<item id>”, “owner”: “<owner username>”, “folder”: “<folder id>”
}
else like the following if it failed: {“error”: {
”code”: 400, “messageCode”: “CONT_0093”, “message”: “File type not allowed for addResources”, “details”: [] }
}
-
get
(file, try_json=True, out_folder=None, out_file_name=None)¶ Gets a specific file resource of an existing item.
Argument
Description
file
required string, path to the file for download. For files in the root, just specify the file name. For files in folders (prefixes), specify using the format <foldername>/<foldername>./../<filename>
try_json
optional bool. If True, will attempt to convert JSON files to Python dictionary objects. Default is True.
out_folder
optional string. Specify the folder into which the file has to saved. Default is user’s temporary directory.
out_file_name
optional string. Specify the name to use when downloading the file. Default is the resource file’s name.
This operation is only available to the item owner and the organization administrator.
- Returns
- Path to the downloaded file if getting a binary file (like a jpeg or png file) or if
try_jon = False when getting a JSON file.
If file is a JSON, returns as a Python dictionary.
-
list
()¶ Lists all file resources of an existing item. This resource is only available to the item owner and the organization administrator. :return:
A Python list of dictionaries of the form: [
- {
“resource”: “<resource1>”
}, {
“resource”: “<resource2>”
}, {
“resource”: “<resource3>”
}
]
-
remove
(file=None)¶ Removes a single resource file or all resources. The item size is updated once resource files are deleted.
Argument
Description
file
optional string, path to the file for removal. For files in the root, just specify the file name. For files in folders (prefixes), specify using the format <foldername>/<foldername>./../<filename>
If not specified, all resource files will be removed
This operation is only available to the item owner and the organization administrator.
- Returns
If succeeded a boolean of True will be returned.
else a dictionary with error info {“error”: {“code”: 404,
”message”: “Resource does not exist or is inaccessible.”, “details”: []
}
}
-
update
(file, folder_name=None, file_name=None, text=None)¶ The update resources operation allows to update existing file resources of an item. File resources use storage space from your quota and are scanned for viruses. The item size is updated to include the size of updated resource files.
Supported file formats are: JSON, XML, TXT, PNG, JPEG, GIF, BMP, PDF, and ZIP. This operation is only available to the item owner and the organization administrator.
Argument
Description
file
required string, path to the file on disk to be used for overwriting an existing file resource
folder_name
optional string, provide a folder name if the file resource being updated resides in a folder
file_name
optional string, destination name for the file used to update an existing resource, or to be used together with text parameter as file name for it.
For example, you can use fileName=banner.png to update an existing resource banner.png with a file called billboard.png without renaming the file locally.
text
optional string, text input to be added as a file resource, used together with file_name.
- Returns
Python dict like the following if succeeded: {
”success”: True, “itemId”: “<item id>”, “owner”: “<owner username>”, “folder”: “<folder id>”
}
else like the following if it failed: {“error”: {
”code”: 404, “message”: “Resource does not exist or is inaccessible.”, “details”: [] }
}
-