ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

ListVersions

  • Summary
  • Discussion
  • Syntax
  • Code sample

Summary

Lists the versions in the workspace.

Discussion

You can specify the path to a connection file as an argument to the function or you can set the workspace environment to the connection file and call the ListVersions function without any arguments.

Note:

The arcpy.da.ListVersions function should not to be confused with the arcpy.ListVersions function, which is used to return a list of version names the connected user has permission to use.

Syntax

ListVersions (sde_workspace)
ParameterExplanationData Type
sde_workspace

An enterprise geodatabase workspace.

String

Return Value

Data TypeExplanation
Version

A list of Version objects.

Code sample

ListVersions example 1

Identify all versions modified within the last week.

import arcpy
import datetime

# Use datetime to establish current date/time
#
now = datetime.datetime.now()

sdeConnection = "C:/MyProject/toolboxDEFAULTVersion.sde"

# Compare lastModified property of each version to current date, and 
#  print version name if the version was modified in the last 7 days.
#
for version in arcpy.da.ListVersions(sdeConnection):
    if (now - version.lastModified).days < 7:
        print(version.name)
ListVersions example 2

Delete any versions belonging to a particular user that have no children.

import arcpy

sdeConnection = "C:/MyProject/toolboxDEFAULTVersion.sde"

for version in arcpy.da.ListVersions(sdeConnection):
    # Delete any versions owned by "RJones" that don't have any children
    #
    if version.name.split(".")[0] == "RJones" and not version.children:
        print("Deleting version {0}".format(version.name))
        arcpy.DeleteVersion_management(sdeConnection, version.name)
ListVersions example 3

Reconcile and post versions with a specific description. This example uses a feature service that has the version management capability enabled.

# Import system modules 
import arcpy

# Sign into ArcGIS Enterprise
arcpy.SignInToPortal("https://myserver.mydomain.com/portal", 'portaladmin', 
                     'my.password')

# Create a variable for the feature service URL
myFS = "https://myserver.mydomain.com/server/rest/services/BranchVersioningData/FeatureServer"

# Use the ListVersions function to get a list of versions
versions = arcpy.da.ListVersions(myFS)

# Create a list of version to reconcile
listToRec = []

# For each version in the list, append only those that have the "READY TO POST" 
# description
for version in versions:
    if "READY FOR POST" in version.description.upper():
        listToRec.append(version.name)
        
# Reconcile and post the versions 
arcpy.ReconcileVersions_management(myFS,
                                   'ALL_VERSIONS',
                                   'sde.DEFAULT',
                                   listToRec,
                                   'NO_LOCK_ACQUIRED',
                                   'ABORT_CONFLICTS',
                                   'BY_OBJECT',
                                   'FAVOR_EDIT_VERSION',
                                   'POST',
                                   'KEEP_VERSION')

Related topics

  • Version
  • An overview of the Versions toolset
  • What is a version?
  • An overview of traditional versioning

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal