Translate in viewport

Is there a way to move an object in the viewport in real time with python? A python command that does the same thing as pressing the “g” key.

bpy.ops.transform.translate('INVOKE_DEFAULT')

Thanks! It works.