Reverse Engineer it.
In answers to
How to draw a circle hole by bmesh on the plane?
and
and Create Circle with Inner Radius (Similarly to @Tlouskey mentions adding a cone, but whereas he is using solidify thickness for wall thickness, cone with depth=0 and hence solidify thickness as height if you will
demonstrate other methods to make a hole in a mesh object.
another would be add plane, inset face, then delete face.
Reminder start with cursor in sensible position, anyway set inset to 1
which could be coded, however and having just done that, will use How do I Create a script for geometry I create? to "reverse engineer it into a script"
import bpy
context = bpy.context
verts = ((-2.0, -2.0, 0.0),
(2.0, -2.0, 0.0),
(-2.0, 2.0, 0.0),
(2.0, 2.0, 0.0),
(-1.0, 1.0, 0.0),
(-1.0, -1.0, 0.0),
(1.0, -1.0, 0.0),
(1.0, 1.0, 0.0))
faces = ((5, 4, 2, 0),
(6, 5, 0, 1),
(7, 6, 1, 3),
(4, 7, 3, 2))
me = bpy.data.meshes.new("Plane")
me.from_pydata(verts, [], faces)
ob = bpy.data.objects.new("Plane", me)
context.collection.objects.link(ob)
context.view_layer.objects.active = ob
edit to change "Plane" to suit, and as mentioned can add modifier by appending
sm = ob.modifiers.new("Solidify", 'SOLIDIFY')
sm.thickness = 2
to script.
Note.
To make the cube hollow by giving it "wall thickness", can add the modifier directly to the default cube.
A sphere is used via boolean difference modifier for cutaway.
