code: def copy(self, sql, data, **kwargs):
          
          sql = as_text(sql)
  
          if self.closed():
              raise errors.InterfaceError('Cursor is closed')
  
          self.flush_to_query_ready()
  
          if isinstance(data, binary_type):
              stream = BytesIO(data)
          elif isinstance(data, text_type):
              stream = StringIO(data)
          elif isinstance(data, file_type):
              stream = data
          else:
              raise TypeError("Not valid type of data {0}".format(type(data)))
  
          self.connection.write(messages.Query(sql))
  
          while True:
              message = self.connection.read_message()
  
              self._message = message
              if isinstance(message, messages.ErrorResponse):
                  raise errors.QueryError.from_error_response(message, sql)
  
              self.connection.process_message(message=message)
  
              if isinstance(message, messages.ReadyForQuery):
                  break
              elif isinstance(message, messages.CopyInResponse):
                  self.connection.write(messages.CopyStream(stream, **kwargs))
                  self.connection.write(messages.CopyDone())
  
          if self.error is not None:
              raise self.error
docs: EXAMPLE:
          >> with open("/tmp/file.csv", "rb") as fs:
          >>     cursor.copy("COPY table(field1,field2) FROM STDIN DELIMITER ',' ENCLOSED BY ''''",
          >>                 fs, buffer_size=65536)