I have some 3d objects that I use Python code to rotate. In the Blender preview this works fine.
How can I export the animation caused by the Python code to gltf? The normal gltf export exposes the objects but not the animation.
The glTF exporter is looking for animation keyframes in the NLA tracks for export. If you have custom Python code that's just writing to the object transform on the fly, that's not going to be found by the exporter. Your Python code will need to create actual animation keyframes, such that the exporter can read those keyframes and write them into the glTF file.