code: def del_from_groups(self, username, groups):
          
          # it follows the same logic than add_to_groups
          # but with MOD_DELETE
          ldap_client = self._bind()
          tmp = self._get_user(self._byte_p2(username), ALL_ATTRS)
          if tmp is None:
              raise UserDoesntExist(username, self.backend_name)
          dn = tmp[0]
          attrs = tmp[1]
          attrs['dn'] = dn
          self._normalize_group_attrs(attrs)
          dn = self._byte_p2(tmp[0])
          for group in groups:
              group = self._byte_p2(group)
              for attr in self.group_attrs:
                  content = self._byte_p2(self.group_attrs[attr] % attrs)
                  ldif = [(ldap.MOD_DELETE, attr, self._byte_p3(content))]
                  try:
                      ldap_client.modify_s(group, ldif)
                  except ldap.NO_SUCH_ATTRIBUTE as e:
                      self._logger(
                          severity=logging.INFO,
                          msg="%(backend)s: user '%(user)s'"
                          " wasn't member of group '%(group)s'"
                          " (attribute '%(attr)s')" % {
                              'user': username,
                              'group': self._uni(group),
                              'attr': attr,
                              'backend': self.backend_name
                              }
                      )
                  except Exception as e:
                      ldap_client.unbind_s()
                      self._exception_handler(e)
          ldap_client.unbind_s()
docs: Delete user from groups