How to Create the UV Grid Texture with Python?
Either generate a checkerboard and assign the pixels to a new image data block or just call bpy.ops.image.new() and pass UV_GRID:

One downside of using the operator is that you would have to supply a reliable (unique) name for the image data block otherwise it automatically gets renamed to Untitled.001, Untitled.002... due to Blender's nature of handling data:
import bpy
import secrets

# Generate &quot;unique&quot; name
image_name = secrets.token_hex(5)

# Call the operator 
bpy.ops.image.new(
        name=image_name, 
        width=1024, 
        height=1024, 
        color=(0.0, 0.0, 0.0, 1.0), 
        alpha=True, 
        generated_type='UV_GRID', # BLANK, COLOR_GRID
        float=False, 
        use_stereo_3d=False, 
        tiled=False
    )

# Get the image from data blocks
image = bpy.data.images.get(image_name)

# Display the result
if image:
    bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
    # Change area type
    area = bpy.context.window_manager.windows[-1].screen.areas[0]
    area.type = 'IMAGE_EDITOR'

    # Assign the image
    bpy.context.area.spaces.active.image = image

Related:

Is it possible to create image data and save to a file from a script
How to open an image editor window and display an image file in it?