ListReplicas

Summary

The ListReplicas function lists the replicas 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 ListReplicas function without any arguments.

Syntax

ListReplicas (workspace, {all_replicas})
ParameterExplanationData Type
workspace

The geodatabase workspace.

String
all_replicas

Specifies whether all replica types in the geodatabase will be returned.

  • True—All replica types will be returned. This may include Replica or SyncReplica objects.
  • False—Only Replica objects will be returned. These include replicas created from geodatabase replication workflows as well as replicas created from feature services running on traditional versioned data. This is the default.

(The default value is False)

Boolean
Return Value
Data TypeExplanation
Replica

A list returned from the function containing Replica objects.

If the all_replicas argument is set to True, SyncReplica objects may also be returned.

Code sample

ListReplicas example 1

For every replica in a workspace that is a sender, call the ExportDataChangeMessage function.

import arcpy
import os

sdeConnection = "C:/Data/toolboxDEFAULTVersion.sde"
outLocation = "C:/data"

for replica in arcpy.da.ListReplicas(sdeConnection):
    # If the replica is a sender, call ExportDataChangeMessage
    if replica.isSender:
        changesFile = os.path.join(outputLocation,
                                   f"changes_{replica.name}.gdb")
        arcpy.management.ExportDataChangeMessage(sdeConnection,
                                                 changes,
                                                 replica.name)
ListReplicas example 2

Print all replicas that are in conflict.

import arcpy

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

# Print the name of the replicas that are in conflict
for replica in arcpy.da.ListReplicas(sdeConnection):
    if replica.hasConflicts:
        print(replica.name)
ListReplicas example 3

Print the properties of a SyncReplica object

import arcpy

# Use the ListReplicas function to return all replicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\Projects\\MyProject\\myGDB.sde", True)

for r in replicas:
    # Check if the class is a SyncReplica
    if isinstance(r, arcpy.da.SyncReplica):
        # Print the properties of a SyncReplica object
        print(f"Properties of replica named: {r.name}")
        print(f"Datasets: {r.datasets}")
        print(f"Owner: {r.owner}")
        print(f"Replica ID: {r.replicaID}")
        print(f"Service name: {r.serviceName}")
        print(f"Version: {r.version}")
        print(f"Direction: {r.direction}")
        print(f"Sync model: {r.syncModel}")
        print(f"Last sync date: {r.lastSyncDate}")
        print(f"LayerServerGens: {r.layerServerGens}")
        print(f"LayerServerSibGens: {r.layerServerSibGens}")
        print(f"ReplicaServerGen: {r.replicaServerGen}")
        print(f"ReplicaServerSibGen: {r.replicaServerSibGen")
        print(f"Target type: {r.targetType}")
ListReplicas example 4

Print the creationDate, replicaDate, and geometry properties of each Replica or SyncReplica object. A Replica or SyncReplica object can have a creationDate property value, a replicaDate property value, or both. The creationDate and replicaDate properties describe when the replica was created; however, the creationDate property is in UTC, and the replicaDate property is in the time zone of the server machine. The geometry property is the replica’s spatial filter geometry.

import arcpy

# Use the ListReplicas function to return all Replicas and SyncReplicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\gdb\\mygeodatabase.sde", True)

for r in replicas:
    # Print Replica or SyncReplica object properties
    if hasattr(r, 'creationDate'):
        print(str(r.creationDate))  
    if hasattr(r, 'replicaDate'):
        print(str(r.replicaDate))
    if hasattr(r, 'geometry') and (r.geometry is not None):
        print(str(r.geometry.JSON))

Related topics


In this topic