Can armature/bones be edited without edit mode? I was looking after some information about armature and bones, so I can continue my importer script. I found some nice info here; no BMesh, and simple enough for my needs as beginner, so just perfect. But while looking at the code I saw that it uses "edit mode" (line 120), what I wanted to avoid.

So my question is: can I programmatically add/manipulate bones, without edit mode? Is there any better way then in this code?

I also tried to use the "bones" collection, but I could not append/new/add items into them.
No, The armature must be in Edit mode for us to be allowed to add or remove bones. We can switch into and out of it, using bpy.ops.object.mode_set. An idiom I use a couple of times in my addon, is to store initial mode in a variable (prev_mode), then restore it when I'm finished:

prev_mode = armature.mode # save

bpy.ops.object.mode_set(mode='EDIT')
for bone in context.selected_bones:
    # do anything in edit mode
    hook_name = PRF_HOOK + bone.name
    hook = armature.data.edit_bones.new(hook_name)

bpy.ops.object.mode_set(mode='POSE')
for bone in context.selected_pose_bones:
    # do anything in pose mode
    hook = armature.pose.bones[PRF_HOOK + bone_name]
    ct_constraint = hook.constraints.new('COPY_TRANSFORMS')

bpy.ops.object.mode_set(mode=prev_mode) # restore


This way, we can access any editing mode, any number of times, without the user even notice when the script is finished.