Python: exchange object
With help from @batFinger I derived this working solution:

import bpy
import os

scene = bpy.context.scene
cam = bpy.data.objects['Camera']
obj = bpy.data.objects['Cube']

scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = 'testImage.png'
scene.render.resolution_x = 640
scene.render.resolution_y = 640

# change mesh
path = r"assembly_upsampled.stl"
bpy.ops.import_mesh.stl(filepath=path)
obj.data = bpy.context.object.data
bpy.data.objects.remove(bpy.context.object)

# scale size
max_dim = 2
if obj.dimensions.length:
    obj.scale *= max_dim / max(obj.dimensions)

# render
scene.frame_set(scene.frame_end)
bpy.ops.render.render(write_still = True)