Setting the origin for each object to geometry
Low level Origin to geometry
Will have to investigate the difference between calling the set origin operator via code and via the UI
Instead can sum the vert coordinates make that the origin, and shift the matrix back accordingly
import bpy
from mathutils import Matrix, Vector

scene = bpy.context.scene

mesh_obs = [o for o in scene.objects if o.type == 'MESH']


for o in mesh_obs:
    me = o.data
    mw = o.matrix_world
    origin = sum((v.co for v in me.vertices), Vector()) / len(me.vertices)

    T = Matrix.Translation(-origin)
    me.transform(T)
    mw.translation = mw @ origin

Alternatively could change your mesh creation class to not use global coordinates.
Operators run on context
Operators use the context.  The origin set will set the origin of all selected mesh objects and can be run once on the selection rather than per object. See Python performance with Blender operators  as to why this  matters.
Another part of context is the code in question?  It is quite possible that changing the origin could be dealt with somewhere else if you are to quote:

In python I can create all of the features that I want

However without any idea of what prior code is, here is a  Test script, set origin of all mesh objects in the scene by passing them as overridden  context to the operator.
import bpy

scene = bpy.context.scene

mesh_obs = [o for o in scene.objects if o.type == 'MESH']

if mesh_obs:
    bpy.ops.object.origin_set(
            {&quot;object&quot; : mesh_obs[0],
            &quot;selected_objects&quot; : mesh_obs,
            &quot;selected_editable_objects&quot; : mesh_obs,
            }
        )