How to add BOID brain settings to a particle system via python script?

I am trying to use a script to add some rules to the boid brain of a particle system and the operators on website here,, don’t seem to be doing anything. Does anyone know a way to do add various rules to a boid brain system via script?

I am using the following code to add the particle system to an existing selected object in the scene. Everything works up until the last line where I try to add the Boid rule. That line doesn’t seem to do anything to the particle system.

#adding particle system with custom particle system settings

obj = bpy.context.active_object

if len(obj.particle_systems) == 0:"part", type='PARTICLE_SYSTEM')
    part = obj.particle_systems[0]

    settings = part.settings = 'Bug System'
    settings.count = 1000
    settings.frame_start = 1
    settings.frame_end = (250)
    settings.lifetime = 500
    settings.lifetime_random = 0
    settings.emit_from = 'FACE'
    settings.physics_type = 'BOIDS'
    bpy.context.object.show_instancer_for_render = False
    settings.show_unborn = True
    settings.use_dead = True
    settings.render_type = 'COLLECTION'
    settings.particle_size = 0.05
    settings.size_random = 0.3["Bug System"].instance_collection =[context.scene.spyderfy_tool.my_stringbugsystem]
    settings.show_unborn = False
    settings.use_dead = False
    settings.jitter_factor = 0
    settings.object_factor = 1
    settings.effector_weights.turbulence = 0
    #adding boid brain rules in correct order
    bpy.ops.boid.rule_add(type='FLOCK') #This is the one that doesn't seem to be working.