def set_value(
        self, name, value, ttl=None, local=True, scope=SYSTEM_SCOPE, encrypt=False
    ):
        """
        Set a value for the provided key.

        By default, value is set in a namespace local to the pack/class. If you want to
        set a global value, pass local=False to this method.

        :param name: Key name.
        :type name: ``str``

        :param value: Key value.
        :type value: ``str``

        :param ttl: Optional TTL (in seconds).
        :type ttl: ``int``

        :param local: Set value in a namespace local to the pack/class. Defaults to True.
        :type: local: ``bool``

        :param scope: Scope under which to place the item. Defaults to system scope.
        :type: local: ``str``

        :param encrypt: Encrypt the value when saving. Defaults to False.
        :type: local: ``bool``

        :return: ``True`` on success, ``False`` otherwise.
        :rtype: ``bool``
        """
        if scope != SYSTEM_SCOPE:
            raise ValueError("Scope %s is unsupported." % scope)

        name = self._get_full_key_name(name=name, local=local)

        value = str(value)
        client = self.get_api_client()

        self._logger.debug("Setting value in the datastore (name=%s)", name)

        instance = KeyValuePair()
        instance.id = name
        instance.name = name
        instance.value = value
        instance.scope = scope
        if encrypt:
            instance.secret = True

        if ttl:
            instance.ttl = ttl

        client.keys.update(instance=instance)
        return True

        Set a value for the provided key.

        By default, value is set in a namespace local to the pack/class. If you want to
        set a global value, pass local=False to this method.

        :param name: Key name.
        :type name: ``str``

        :param value: Key value.
        :type value: ``str``

        :param ttl: Optional TTL (in seconds).
        :type ttl: ``int``

        :param local: Set value in a namespace local to the pack/class. Defaults to True.
        :type: local: ``bool``

        :param scope: Scope under which to place the item. Defaults to system scope.
        :type: local: ``str``

        :param encrypt: Encrypt the value when saving. Defaults to False.
        :type: local: ``bool``

        :return: ``True`` on success, ``False`` otherwise.
        :rtype: ``bool``
        
st2common/st2common/services/datastore.py