(Python API 2.82a)how to pin vertex group with python api
Here's a quick minimum working example with Blender 2.82a and Python:

import bpy

def clear_scene():
    for block in bpy.data.meshes:
        if block.users == 0:
            bpy.data.meshes.remove(block)
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete()

def make_cloth(vertices):
    """Make a plane at height 0.2m and subdivide. Then, pin vertices."""
    bpy.ops.mesh.primitive_plane_add(location=(0, 0, 0.2))
    bpy.ops.object.editmode_toggle()
    bpy.ops.mesh.subdivide(number_cuts=20)
    bpy.ops.object.editmode_toggle()
    bpy.ops.object.modifier_add(type='CLOTH')

    # Pin the designated vertices.
    gripped_group = bpy.context.object.vertex_groups.new(name='Pinned')
    gripped_group.add(vertices, 1.0, 'ADD')
    bpy.context.object.modifiers["Cloth"].settings.vertex_group_mass = 'Pinned'

if __name__ == '__main__':
    clear_scene()
    vertices = [0]
    make_cloth(vertices)


Note: the clear_scene method is not necessary to get pinned vertices. I just had it there to remove the starting items so that the only thing left would be the cloth.

If this file is called test.py, then run blender -P test.py. I get this when I open the GUI:



Notice the vertex groups shown to the right in the screenshot above. 

Clicking the "play"' button to animate the scene, I get this at frame 85:



Unfortunately, it isn't always clear how vertex indices are determined. I would consult this question for further information.