docs: def createReplica(self,
                        replicaName,
                        layers,
                        layerQueries=None,
                        geometryFilter=None,
                        replicaSR=None,
                        transportType="esriTransportTypeUrl",
                        returnAttachments=False,
                        returnAttachmentsDatabyURL=False,
                        async=False,
                        attachmentsSyncDirection="none",
                        syncModel="none",
                        dataFormat="json",
                        replicaOptions=None,
                        wait=False,
                        out_path=None):
          """
          The createReplica operation is performed on a feature service
          resource. This operation creates the replica between the feature
          service and a client based on a client-supplied replica definition.
          It requires the Sync capability. See Sync overview for more
          information on sync. The response for createReplica includes
          replicaID, server generation number, and data similar to the
          response from the feature service query operation.
          The createReplica operation returns a response of type
          esriReplicaResponseTypeData, as the response has data for the
          layers in the replica. If the operation is called to register
          existing data by using replicaOptions, the response type will be
          esriReplicaResponseTypeInfo, and the response will not contain data
          for the layers in the replica.
  
          Inputs:
             replicaName - name of the replica
             layers - layers to export
             layerQueries - In addition to the layers and geometry parameters, the layerQueries
              parameter can be used to further define what is replicated. This
              parameter allows you to set properties on a per layer or per table
              basis. Only the properties for the layers and tables that you want
              changed from the default are required.
              Example:
               layerQueries = {"0":{"queryOption": "useFilter", "useGeometry": true,
               "where": "requires_inspection = Yes"}}
             geometryFilter - Geospatial filter applied to the replica to
              parse down data output.
             returnAttachments - If true, attachments are added to the replica and returned in the
              response. Otherwise, attachments are not included.
             returnAttachmentDatabyURL -  If true, a reference to a URL will be provided for each
              attachment returned from createReplica. Otherwise,
              attachments are embedded in the response.
             replicaSR - the spatial reference of the replica geometry.
             transportType -  The transportType represents the response format. If the
              transportType is esriTransportTypeUrl, the JSON response is contained in a file,
              and the URL link to the file is returned. Otherwise, the JSON object is returned
              directly. The default is esriTransportTypeUrl.
              If async is true, the results will always be returned as if transportType is
              esriTransportTypeUrl. If dataFormat is sqlite, the transportFormat will always be
              esriTransportTypeUrl regardless of how the parameter is set.
              Values: esriTransportTypeUrl | esriTransportTypeEmbedded
             returnAttachments - If true, attachments are added to the replica and returned in
              the response. Otherwise, attachments are not included. The default is false. This
              parameter is only applicable if the feature service has attachments.
             returnAttachmentsDatabyURL -  If true, a reference to a URL will be provided for
              each attachment returned from createReplica. Otherwise, attachments are embedded
              in the response. The default is true. This parameter is only applicable if the
              feature service has attachments and if returnAttachments is true.
             attachmentsSyncDirection - Client can specify the attachmentsSyncDirection when
              creating a replica. AttachmentsSyncDirection is currently a createReplica property
              and cannot be overridden during sync.
              Values: none, upload, bidirectional
             async - If true, the request is processed as an asynchronous job, and a URL is
              returned that a client can visit to check the status of the job. See the topic on
              asynchronous usage for more information. The default is false.
             syncModel - Client can specify the attachmentsSyncDirection when creating a replica.
              AttachmentsSyncDirection is currently a createReplica property and cannot be
              overridden during sync.
             dataFormat - The format of the replica geodatabase returned in the response. The
              default is json.
              Values: filegdb, json, sqlite, shapefile
             replicaOptions - This parameter instructs the createReplica operation to create a
              new replica based on an existing replica definition (refReplicaId). It can be used
              to specify parameters for registration of existing data for sync. The operation
              will create a replica but will not return data. The responseType returned in the
              createReplica response will be esriReplicaResponseTypeInfo.
             wait - if async, wait to pause the process until the async operation is completed.
             out_path - folder path to save the file
          """
          if self.syncEnabled == False and "Extract" not in self.capabilities:
              return None
          url = self._url + "/createReplica"
          dataformat = ["filegdb", "json", "sqlite", "shapefile"]
          params = {"f" : "json",
                    "replicaName": replicaName,
                    "returnAttachments": returnAttachments,
                    "returnAttachmentsDatabyURL": returnAttachmentsDatabyURL,
                    "attachmentsSyncDirection" : attachmentsSyncDirection,
                    "async" : async,
                    "syncModel" : syncModel,
                    "layers" : layers
                    }
          if dataFormat.lower() in dataformat:
              params['dataFormat'] = dataFormat.lower()
          else:
              raise Exception("Invalid dataFormat")
          if layerQueries is not None:
              params['layerQueries'] = layerQueries
          if geometryFilter is not None and \
             isinstance(geometryFilter, GeometryFilter):
              params.update(geometryFilter.filter)
          if replicaSR is not None:
              params['replicaSR'] = replicaSR
          if replicaOptions is not None:
              params['replicaOptions'] = replicaOptions
          if transportType is not None:
              params['transportType'] = transportType
  
          if async:
              if wait:
                  exportJob = self._post(url=url,
                                            param_dict=params,
                                            securityHandler=self._securityHandler,
                                            proxy_url=self._proxy_url,
                                            proxy_port=self._proxy_port)
                  status = self.replicaStatus(url=exportJob['statusUrl'])
                  while status['status'].lower() != "completed":
                      status = self.replicaStatus(url=exportJob['statusUrl'])
                      if status['status'].lower() == "failed":
                          return status
  
                  res = status
  
              else:
                  res = self._post(url=url,
                                       param_dict=params,
                                       securityHandler=self._securityHandler,
                                       proxy_url=self._proxy_url,
                                       proxy_port=self._proxy_port)
          else:
              res = self._post(url=url,
                                  param_dict=params,
                                  securityHandler=self._securityHandler,
                                  proxy_url=self._proxy_url,
                                  proxy_port=self._proxy_port)
  
  
          if out_path is not None and \
             os.path.isdir(out_path):
              dlURL = None
              if 'resultUrl' in res:
                  dlURL = res["resultUrl"]
              elif 'responseUrl' in res:
                  dlURL = res["responseUrl"]
              elif 'URL' in res:
                  dlURL = res["URL"]
              if dlURL is not None:
                  return self._get(url=dlURL,
                                   securityHandler=self._securityHandler,
                                   proxy_url=self._proxy_url,
                                   proxy_port=self._proxy_port,
                                   out_folder=out_path)
              else:
                  return res
          elif res is not None:
              return res
          return None