arcresthelper package

Submodules

arcresthelper.common module

exception arcresthelper.common.ArcRestHelperError[source]

Bases: exceptions.Exception

Raised when error occurs in utility module functions.

class arcresthelper.common.Tee(*files)[source]

Bases: object

Combines standard output with a file for logging.

write(obj)[source]
arcresthelper.common.chunklist(l, n)[source]

Yield successive n-sized chunks from l.

Parameters:
  • l (object) – The object to chunk.
  • n (int) – The size of the chunks.
Yields:

The next chunk in the object.

Raises:

TypeError – if l has no len().

Examples

>>> for c in arcresthelper.common.chunklist(list(range(20)), 6):
...     print(c)
[0, 1, 2, 3, 4, 5]
[6, 7, 8, 9, 10, 11]
[12, 13, 14, 15, 16, 17]
[18, 19]
>>> list(arcresthelper.common.chunklist(string.ascii_uppercase, 7))
['ABCDEFG', 'HIJKLMN', 'OPQRSTU', 'VWXYZ']
arcresthelper.common.close_log(log_file)[source]

Closes the open file and returns sys.stdout to the default (i.e., console output).

Parameters:log_file (file) – The file object to close.
arcresthelper.common.find_replace(obj, find, replace)[source]

Searches an object and performs a find and replace.

Parameters:
  • obj (object) – The object to iterate and find/replace.
  • find (str) – The string to search for.
  • replace (str) – The string to replace with.
Returns:

The object with replaced strings.

Return type:

object

arcresthelper.common.find_replace_string(obj, find, replace)[source]

Performs a string.replace() on the input object.

Parameters:
  • obj (object) – The object to find/replace. It will be cast to str.
  • find (str) – The string to search for.
  • replace (str) – The string to replace with.
Returns:

The replaced string.

Return type:

str

arcresthelper.common.getLayerIndex(url)[source]

Extract the layer index from a url.

Parameters:url (str) – The url to parse.
Returns:The layer index.
Return type:int

Examples

>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url)
12
arcresthelper.common.getLayerName(url)[source]

Extract the layer name from a url.

Parameters:url (str) – The url to parse.
Returns:The layer name.
Return type:str

Examples

>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url)
'test'
arcresthelper.common.getOrgId(url)[source]

Extract the org ID from a url.

Parameters:url (str) – The url to parse.
Returns:The org ID.
Return type:str

Examples

>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url)
'<random>'
arcresthelper.common.init_config_json(config_file)[source]

Deserializes a JSON configuration file.

Parameters:config_file (str) – The path to the JSON file.
Returns:A dictionary object containing the JSON data. If config_file does not exist, returns None.
Return type:dict
arcresthelper.common.init_log(log_file)[source]

Creates log file on disk and “Tees” sys.stdout to console and disk

Parameters:log_file (str) – The path on disk to append or create the log file.
Returns:The opened log file.
Return type:file
arcresthelper.common.is_number(s)[source]

Determines if the input is numeric

Parameters:s – The value to check.
Returns:True if the input is numeric, False otherwise.
Return type:bool
arcresthelper.common.local_time_to_online(dt=None)[source]

Converts datetime object to a UTC timestamp for AGOL.

Parameters:dt (datetime) – The datetime.datetime object to convert. Defaults to None, i.e., datetime.datetime.now().
Returns:A UTC timestamp as understood by AGOL (time in ms since Unix epoch * 1000)
Return type:float

Examples

>>> arcresthelper.common.local_time_to_online() # PST
1457167261000.0
>>> dt = datetime.datetime(1993, 3, 5, 12, 35, 15) # PST
>>> arcresthelper.common.local_time_to_online(dt)
731392515000.0

See also

online_time_to_string() for converting a UTC timestamp

arcresthelper.common.merge_dicts(dicts, op=<built-in function add>)[source]

Merge a list of dictionaries.

Parameters:
  • dicts (list) – a list of dictionary objects
  • op (operator) – an operator item used to merge the dictionaries. Defaults to operator.add().
Returns:

the merged dictionary

Return type:

dict

arcresthelper.common.noneToValue(value, newValue)[source]

Convert None to a different value.

Parameters:
  • value – The value to convert. This can be anything.
  • newValue – The resultant value. This can be anything.
Returns:

newValue

arcresthelper.common.online_time_to_string(value, timeFormat, utcOffset=0)[source]

Converts AGOL timestamp to formatted string.

Parameters:
  • value (float) – A UTC timestamp as reported by AGOL (time in ms since Unix epoch * 1000)
  • timeFormat (str) – Date/Time format string as parsed by datetime.strftime().
  • utcOffset (int) – Hours difference from UTC and desired output. Default is 0 (remain in UTC).
Returns:

A string representation of the timestamp.

Return type:

str

Examples

>>> arcresthelper.common.online_time_to_string(1457167261000.0, "%Y-%m-%d %H:%M:%S")
'2016-03-05 00:41:01'
>>> arcresthelper.common.online_time_to_string(731392515000.0, '%m/%d/%Y %H:%M:%S', -8) # PST is UTC-8:00
'03/05/1993 12:35:15'

See also

local_time_to_online() for converting a datetime.datetime object to AGOL timestamp

arcresthelper.common.random_int_generator(maxrange)[source]

Generates a random integer from 0 to maxrange, inclusive.

Parameters:maxrange (int) – The upper range of integers to randomly choose.
Returns:The randomly generated integer from random.randint().
Return type:int

Examples

>>> arcresthelper.common.random_int_generator(15)
9
arcresthelper.common.random_string_generator(size=6, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]

Generates a random string from a set of characters.

Parameters:
  • size (int) – The length of the resultant string. Defaults to 6.
  • chars (str) – The characters to be used by random.choice(). Defaults to string.ascii_uppercase.
Returns:

The randomly generated string.

Return type:

str

Examples

>>> arcresthelper.common.random_string_generator()
'DCNYWU'
>>> arcresthelper.common.random_string_generator(12, "arcREST")
'cESaTTEacTES'
arcresthelper.common.trace()[source]

Determine information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple
arcresthelper.common.unicode_convert(obj)[source]

Converts unicode objects to anscii.

Parameters:obj (object) – The object to convert.
Returns:The object converted to anscii, if possible. For dict and list, the object type is maintained.
arcresthelper.common.write_config_json(config_file, data)[source]

Serializes an object to disk.

Parameters:
  • config_file (str) – The path on disk to save the file.
  • data (object) – The object to serialize.

arcresthelper.featureservicetools module

class arcresthelper.featureservicetools.featureservicetools(securityinfo)[source]

Bases: arcresthelper.securityhandlerhelper.securityhandlerhelper

AddFeaturesToFeatureLayer(url, pathToFeatureClass, chunksize=0, lowerCaseFieldNames=False)[source]

Appends local features to a hosted feature service layer.

Parameters:
  • url (str) – The URL of the feature service layer.
  • pathToFeatureClass (str) – The path of the feature class on disk.
  • chunksize (int) – The maximum amount of features to upload at a time. Defaults to 0.
  • lowerCaseFieldNames (bool) – A boolean value indicating if field names should be converted to lowercase before uploading. Defaults to False.
Returns:

The result from arcrest.agol.services.FeatureLayer.addFeatures().

Raises:

ArcRestHelperError – if arcpy can’t be found.

Notes

If publishing to a PostgreSQL database, it is suggested to to set lowerCaseFieldNames to True.

DeleteFeaturesFromFeatureLayer(url, sql, chunksize=0)[source]

Removes features from a hosted feature service layer by SQL query.

Parameters:
  • url (str) – The URL of the feature service layer.
  • sql (str) – The SQL query to apply against the feature service. Those features that satisfy the query will be deleted.
  • chunksize (int) – The maximum amount of features to remove at a time. Defaults to 0.
Returns:

The result from arcrest.agol.services.FeatureLayer.deleteFeatures().

Notes

If you want to delete all features, it is suggested to use the SQL query "1=1".

EnableEditingOnService(url, definition=None)[source]

Enables editing capabilities on a feature service.

Parameters:
  • url (str) – The URL of the feature service.
  • definition (dict) – A dictionary containing valid definition values. Defaults to None.
Returns:

The existing feature service definition capabilities.

Return type:

dict

When definition is not provided (None), the following values are used by default:

Key Value
hasStaticData False
allowGeometryUpdates True
enableEditorTracking False
enableOwnershipAccessControl False
allowOthersToUpdate True
allowOthersToDelete True
capabilities "Query,Editing,Create,Update,Delete"
GetFeatureService(itemId, returnURLOnly=False)[source]

Obtains a feature service by item ID.

Parameters:
  • itemId (int) – The feature service’s item ID.
  • returnURLOnly (bool) – A boolean value to return the URL of the feature service. Defaults to False.
Returns:

When returnURLOnly is True, the URL of the feature service is returned.

When False, the result from arcrest.agol.services.FeatureService() or arcrest.ags.services.FeatureService().

GetLayerFromFeatureService(fs, layerName='', returnURLOnly=False)[source]

Obtains a layer from a feature service by feature service reference.

Parameters:
  • fs (FeatureService) – The feature service from which to obtain the layer.
  • layerName (str) – The name of the layer. Defaults to "".
  • returnURLOnly (bool) – A boolean value to return the URL of the layer. Defaults to False.
Returns:

When returnURLOnly is True, the URL of the layer is returned.

When False, the result from arcrest.agol.services.FeatureService() or arcrest.ags.services.FeatureService().

GetLayerFromFeatureServiceByURL(url, layerName='', returnURLOnly=False)[source]

Obtains a layer from a feature service by URL reference.

Parameters:
  • url (str) – The URL of the feature service.
  • layerName (str) – The name of the layer. Defaults to "".
  • returnURLOnly (bool) – A boolean value to return the URL of the layer. Defaults to False.
Returns:

When returnURLOnly is True, the URL of the layer is returned.

When False, the result from arcrest.agol.services.FeatureService() or arcrest.ags.services.FeatureService().

QueryAllFeatures(url, sql, out_fields='*', chunksize=1000, savePath=None)[source]

Performs an SQL query against a hosted feature service layer.

Parameters:
  • url (str) – The URL of the feature service layer.
  • sql (str) – The SQL query to apply against the feature service. Those features that satisfy the query will be returned.
  • out_fields (str) – A comma delimited list of field names to return. Defaults to "*", i.e., return all fields
  • chunksize (int) – The maximum amount of features to query at a time. Defaults to 1000.
  • savePath (str) – The full path on disk where the features will be saved. Defaults to None.
Returns:

When savePath is not provided (None), the result from

arcrest.agol.services.FeatureLayer.query().

When savePath is provided, the result from

arcrest.common.general.FeatureSet.save().

RemoveAndAddFeatures(url, pathToFeatureClass, id_field, chunksize=1000)[source]

Deletes all features in a feature service and uploads features from a feature class on disk.

Parameters:
  • url (str) – The URL of the feature service.
  • pathToFeatureClass (str) – The path of the feature class on disk.
  • id_field (str) – The name of the field in the feature class to use for chunking.
  • chunksize (int) – The maximum amount of features to upload at a time. Defaults to 1000.
Raises:

ArcRestHelperError – if arcpy can’t be found.

disableSync(url, definition=None)[source]

Disables Sync capabilities for an AGOL feature service.

Parameters:
  • url (str) – The URL of the feature service.
  • definition (dict) – A dictionary containing valid definition values. Defaults to None.
Returns:

The result from arcrest.hostedservice.service.AdminFeatureService.updateDefinition().

Return type:

dict

enableSync(url, definition=None)[source]

Enables Sync capability for an AGOL feature service.

Parameters:
  • url (str) – The URL of the feature service.
  • definition (dict) – A dictionary containing valid definition values. Defaults to None.
Returns:

The result from arcrest.hostedservice.service.AdminFeatureService.updateDefinition().

Return type:

dict

arcresthelper.featureservicetools.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

arcresthelper.orgtools module

class arcresthelper.orgtools.orgtools(securityinfo)[source]

Bases: arcresthelper.securityhandlerhelper.securityhandlerhelper

createGroup(title, tags, description='', snippet='', phone='', access='org', sortField='title', sortOrder='asc', isViewOnly=False, isInvitationOnly=False, thumbnail=None)[source]

Creates a new group.

Parameters:
  • title (str) – The name of the new group, limited to 250 characters.
  • tags (str) – A comma delimited list of tag names.
  • description (str) – A description of the group that can be any length.
  • snippet (str) – Snippet or summary of the group that has a character limit of 250 characters. Defaults to "".
  • phone (str) – Group contact information, limited to 250 characters. Defaults to "".
  • access (str) – Sets the access level for the group. Defaults to "org".
  • sortField (str) – Sets sort field for group items. Defaults to "title".
  • sortOrder (str) – Sets sort order for group items. Defaults to "asc".
  • isViewOnly (bool) – A boolean value to create a view-only group with no sharing. Defaults to False.
  • isInvitationOnly (bool) – A boolean value to not accept join requests. Defaults to False.
  • thumbnail (str) – The full pathname to the group thumbnail to upload. Defaults to None.
Returns:

If sucessful, the result from arcrest.manageorg._community.Community.createGroup().

If the group already exists or there is an error, None is returned.

Parameters Possible Values
access private|org|public
sortField title|owner|avgrating|numviews|created|modified
sortOrder asc|desc
createRole(name, description='', privileges=None)[source]

Creates a new role.

Parameters:
  • name (str) – The name of the new role.
  • description (str) – The description of the new role. Defaults to "".
  • privileges (str) – A comma delimited list of privileges to apply to the new role. Defaults to None.
Returns:

If privileges is None, the result from arcrest.manageorg._portals.Portal.createRole().

If privileges were succesfully added, the result from arcrest.manageorg._portals.Roles.setPrivileges().

getGroupContent(groupName, onlyInOrg=False, onlyInUser=False)[source]

Gets all the content from a group.

Parameters:
  • groupName (str) – The name of the group from which to get items.
  • onlyInOrg (bool) – A boolean value to only return content belonging to the current org. Defaults to False.
  • onlyInUser (bool) – A boolean value to only return content belonging to the current user credentials. Defaults to False.
Returns:

A list of content belonging to the group.

Return type:

list

See also

getGroupContentItems() for retrieving only items.

getGroupContentItems(groupName)[source]

Gets all the items owned by a group(s).

Parameters:groupName (list) – The name of the group(s) from which to get items.
Returns:A list of items belonging to the group(s).
Return type:list

Notes

If you want to get items from a single group, groupName can be passed as a str.

See also

getGroupContent() for retrieving all content, not just items.

getThumbnailForItem(itemId, fileName, filePath)[source]

Gets an item’s thumbnail and saves it to disk.

Parameters:
  • itemId (str) – The item’s ID.
  • fileName (str) – The name of the output image.
  • fileName – The directory on disk where to save the thumbnail.
Returns:

The result from arcrest.manageorg._content.UserItem.saveThumbnail()

Return type:

dict

shareItemsToGroup(shareToGroupName, items=None, groups=None)[source]

Share already published items with a group(s).

Parameters:
  • shareToGroupName (list) – The name of the group(s) with which the item(s) will be shared.
  • items (list) – The item(s) that will be shared, referenced by their ID. Defaults to None.
  • groups (list) – The group(s) whose content will be shared, referenced by their ID. Defaults to None.

Notes

If you want to share with a single group, shareToGroupName can be passed as a str.

arcresthelper.orgtools.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

arcresthelper.portalautomation module

class arcresthelper.portalautomation.portalautomation(securityinfo)[source]

Bases: arcresthelper.securityhandlerhelper.securityhandlerhelper

createGroups(configFiles, dateTimeFormat=None)[source]

Parses a JSON configuration file to create groups.

Parameters:
  • configFiles (list) – A list of JSON files on disk containing configuration data for creating groups.
  • dateTimeFormat (str) – A valid date formatting directive, as understood by datetime.datetime.strftime(). Defaults to None, i.e., '%Y-%m-%d %H:%M'.
createRoles(configFiles, dateTimeFormat=None)[source]

Parses a JSON configuration file to create roles.

Parameters:
  • configFiles (list) – A list of JSON files on disk containing configuration data for creating roles.
  • dateTimeFormat (str) – A valid date formatting directive, as understood by datetime.datetime.strftime(). Defaults to None, i.e., '%Y-%m-%d %H:%M'.
publishfromconfig(configFiles, combinedApp=None, dateTimeFormat=None)[source]

Parses a JSON configuration file to publish data.

Parameters:
  • configFiles (list) – A list of JSON files on disk containing configuration data for publishing.
  • combinedApp (str) – A JSON file on disk containing configuration data for app publishing. Defaults to None.
  • dateTimeFormat (str) – A valid date formatting directive, as understood by datetime.datetime.strftime(). Defaults to None, i.e., '%Y-%m-%d %H:%M'.
setLog(log_file)[source]

References

arcresthelper.common.init_log()

stageContent(configFiles, dateTimeFormat=None)[source]

Parses a JSON configuration file to stage content.

Parameters:
  • configFiles (list) – A list of JSON files on disk containing configuration data for staging content.
  • dateTimeFormat (str) – A valid date formatting directive, as understood by datetime.datetime.strftime(). Defaults to None, i.e., '%Y-%m-%d %H:%M'.
arcresthelper.portalautomation.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

arcresthelper.publishingtools module

arcresthelper.publishingtools.lineno()[source]

Returns the current line number in our program.

class arcresthelper.publishingtools.publishingtools(securityinfo)[source]

Bases: arcresthelper.securityhandlerhelper.securityhandlerhelper

folderExist(name, folders)[source]

Determines if a folder exists, case insensitively.

Parameters:
  • name (str) – The name of the folder to check.
  • folders (list) – A list of folder dicts to check against. The dicts must contain the key:value pair title.
Returns:

True if the folder exists in the list, False otherwise.

Return type:

bool

getItem(userContent, title=None, name=None, itemType=None)[source]

Gets an item by a combination of title, name, and type.

Parameters:
  • userContent (list) – A list of user content.
  • title (str) – The title of the item. Defaults to None.
  • name (str) – The name of the item. Defaults to None.
  • itemType (str) – The type of the item. Defaults to None.
Returns:

The item’s ID. If the item does not exist, None.

Return type:

str

Raises:

AttributeError – If both title and name are not specified (None).

See also

getItemID()

getItemID(userContent, title=None, name=None, itemType=None)[source]

Gets the ID of an item by a combination of title, name, and type.

Parameters:
  • userContent (list) – A list of user content.
  • title (str) – The title of the item. Defaults to None.
  • name (str) – The name of the item. Defaults to None.
  • itemType (str) – The type of the item. Defaults to None.
Returns:

The item’s ID. If the item does not exist, None.

Return type:

str

Raises:

AttributeError – If both title and name are not specified (None).

See also

getItem()

publishApp(app_info, map_info=None, fsInfo=None)[source]

Publishes apps to AGOL/Portal

Parameters:
  • app_info (list) – A list of JSON configuration apps to publish.
  • map_info (list) – Defaults to None.
  • fsInfo (list) – Defaults to None.
Returns:

A dictionary of results objects.

Return type:

dict

publishCombinedWebMap(maps_info, webmaps)[source]

Publishes a combination of web maps.

Parameters:maps_info (list) – A list of JSON configuration combined web maps to publish.
Returns:A list of results from arcrest.manageorg._content.UserItem.updateItem().
Return type:list
publishFeatureCollections(configs)[source]

Publishes feature collections to a feature service.

Parameters:configs (list) – A list of JSON configuration feature service details to publish.
Returns:A dictionary of results objects.
Return type:dict
publishFsFromMXD(fs_config)[source]

Publishes the layers in a MXD to a feauture service.

Parameters:fs_config (list) – A list of JSON configuration feature service details to publish.
Returns:A dictionary of results objects.
Return type:dict
publishItems(items_info)[source]

Publishes a list of items.

Parameters:items_info (list) – A list of JSON configuration items to publish.
Returns:A list of results from arcrest.manageorg._content.User.addItem().
Return type:list
publishMap(maps_info, fsInfo=None, itInfo=None)[source]

Publishes a list of maps.

Parameters:maps_info (list) – A list of JSON configuration maps to publish.
Returns:A list of results from arcrest.manageorg._content.UserItem.updateItem().
Return type:list
updateFeatureService(efs_config)[source]

Updates a feature service.

Parameters:efs_config (list) – A list of JSON configuration feature service details to update.
Returns:A dictionary of results objects.
Return type:dict
arcresthelper.publishingtools.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

arcresthelper.resettools module

class arcresthelper.resettools.resetTools(securityinfo)[source]

Bases: arcresthelper.securityhandlerhelper.securityhandlerhelper

removeUserData(users=None)[source]

Removes users’ content and data.

Parameters:users (str) – A comma delimited list of user names. Defaults to None.

Warning

When users is not provided (None), all users in the organization will have their data deleted!

removeUserGroups(users=None)[source]

Removes users’ groups.

Parameters:users (str) – A comma delimited list of user names. Defaults to None.

Warning

When users is not provided (None), all users in the organization will have their groups deleted!

arcresthelper.resettools.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

arcresthelper.securityhandlerhelper module

arcresthelper.securityhandlerhelper.lineno()[source]

Returns the current line number in our program.

class arcresthelper.securityhandlerhelper.securityhandlerhelper(securityinfo)[source]

Bases: object

A number of different security handlers are suppoted by ArcGIS; this function simplifies the creation of the handlers.

Parameters:securityinfo (dict) – A dict with the type of handler and information to be created.
Key Description Required?
security_type security type used to connect See Values *
username username for log in LDAP|NTLM **
password password for log in LDAP|NTLM **
proxy_url url for proxy server Optional
proxy_port port for proxy server Optional
token_url url for token server Optional
referer_url url for referer Optional
certificatefile   PKI
keyfile   PKI
client_id   OAuth
secret_id   OAuth
* Values: ArcGIS|Portal|LDAP|NTLM|PKI|OAuth (defaults to Portal)
** Also required for ArcGIS|Portal unless using anonymous logins

Examples

>>> securityinfo = {'username' : 'secret', 'password' : 'really_secret'}
>>> shh = arcresthelper.securityhandlerhelper.securityhandlerhelper(securityinfo)
>>> print(shh._org_url)
http://myorg.maps.arcgis.com
dispose()[source]

Disposes the securityhandlerhelper object.

message
Returns:Any messages generated by the object.
Return type:str
securityhandler
Returns:The security handler object.
Return type:securityhandlerhelper
valid
Returns:True if the object is valid, False otherwise.
Return type:bool
arcresthelper.securityhandlerhelper.trace()[source]

Determines information about where an error was thrown.

Returns:line number, filename, error message
Return type:tuple

Examples

>>> try:
...     1/0
... except:
...     print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace()))
...
Error on 'line 1234'
in file 'C:\foo\baz.py'
with error 'ZeroDivisionError: integer division or modulo by zero'

Module contents