code: def init(self, **settings):
          
          if self.get_status() != 'not-initialized':
              raise ClusterError(
                  'cluster in {!r} has already been initialized'.format(
                      self._data_dir))
  
          process = subprocess.run(
              [self._pg_basebackup, '-h', self._master['host'],
               '-p', self._master['port'], '-D', self._data_dir,
               '-U', self._repl_user],
              stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  
          output = process.stdout
  
          if process.returncode != 0:
              raise ClusterError(
                  'pg_basebackup init exited with status {:d}:\n{}'.format(
                      process.returncode, output.decode()))
  
          with open(os.path.join(self._data_dir, 'recovery.conf'), 'w') as f:
              f.write(textwrap.dedent("""\
                  standby_mode = 'on'
                  primary_conninfo = 'host={host} port={port} user={user}'
              """.format(
                  host=self._master['host'],
                  port=self._master['port'],
                  user=self._repl_user)))
  
          return output.decode()
docs: Initialize cluster.