How to set a random value for only visible shape keys?
import bpy
from random import uniform
context = bpy.context
obj = context.object

def set_shapekeys(obj, value=0.5, random=False):
    sk = obj.data.shape_keys
    for i, kb in enumerate(sk.key_blocks.values()):
        if not i or kb.mute:
            # assume kb[0] is 'Basis'
            continue
        if random:
            kb.value = uniform(kb.slider_min, kb.slider_max)
        else:
            kb.value = value

#set visible keys to random

set_shapekeys(obj, random=True)

#set visible keys to 0.7

#set_shapekeys(obj, value=0.7)


Use set_shapekeys(obj, value=0.5) to set all visible shapekeys to 0.5