Blender and animations with python?

Hello currently im writing a plugin for blender!
The plugin is basically animates the bones of rig with datas imported from X file, but the bpy animation documentation is confused me, i’ve surfed every post about bpy animations on google, and got
no clear explanation.

The datas from X imported file to create animation are:
Duration,
FPS,
key frame times,
bone names,
key frame count for each bone
Quaternion for Rotation
Vector3 for Translation,

The part im stuck at is this:
I cant change properties of POSE bones ‘bpy not allows me’ so dont know how to apply those rotation, translation on each posebone at each frame,

Thats the script i written after searching


# ./part of script

Armature = bpy.context.active_object

bpy.context.view_layer.objects.active = Armature

PoseBone = Armature.pose.bones[BoneName].bone
PoseBone.translate(Vector(TRANSLATE))
PoseBone.keyframe_insert(data_path="location", frame=i)

PoseBone.transform<<<transform not works for pose bone :/>>>(Quaternion(ROTATION))
PoseBone.keyframe_insert(data_path="rotation", frame=i)

I’d like to learn how to create animation with python script, but there’s no clear explanation i found on internet, maybe we can make this thread global guide that everyone can read this thread on one day to learn & create their animation scripts.