add bone to armature

Add bone in the armature.
strange to say, that’s the command I took from the text plugin Rigify

in short:
scene.objects.active = obj (obj - here is my armature)
bpy.ops.object.mode_set(mode=‘EDIT’)
bone = bpy.data.edit_bones.new(‘root’)

but I get an error at startup - ‘BlendData’ object has no attribute ‘edit_bones’ - Accepts needed type ‘BlendDataArmatures’, but how to do it?

edit_bones is a property of Armature objects, not bpy.data or Objects.

import bpy
# get active object
ob = bpy.context.object

assert ob.type == 'ARMATURE'

bpy.ops.object.mode_set(mode='EDIT')

# get armature
arma = ob.data

# create new edit bone
bone = arma.edit_bones.new("root")
bone.tail.z += 2