How to add a button to outliner header via python script?
The header of the outliner panel can be accessed through bpy.types.OUTLINER_HT_header. It is possible to add additional buttons to the header by appending or prepending a draw function which assigns the relevant operators to the layout. The draw function could look like the following, if your operator class is called EXAMPLE_OT_something.
def draw(self, context):
        self.layout.operator(EXAMPLE_OT_something.bl_idname)

If the operator has been registered the draw function can be appended to the header. This places the button at the end of the header. Using .prepend would place it at the beginning.
bpy.types.OUTLINER_HT_header.append(draw)

Below is an example add-on that demonstrates the concept.
bl_info = {
    &quot;name&quot;: &quot;Outliner Header Button&quot;,
    &quot;author&quot;: &quot;Robert Guetzkow&quot;,
    &quot;version&quot;: (1, 0, 0),
    &quot;blender&quot;: (2, 81, 0),
    &quot;location&quot;: &quot;Outliner&quot;,
    &quot;description&quot;: &quot;Adds an example button to the outliner header.&quot;,
    &quot;wiki_url&quot;: &quot;&quot;,
    &quot;category&quot;: &quot;Outliner&quot;}

import bpy


class EXAMPLE_OT_something(bpy.types.Operator):
    bl_idname = &quot;example.something&quot;
    bl_label = &quot;Do something&quot;
    bl_description = &quot;This operator does something&quot;
    bl_options = {&quot;REGISTER&quot;}

    def execute(self, context):
        print(&quot;Hello&quot;)
        return {&quot;FINISHED&quot;}


def draw(self, context):
    self.layout.operator(EXAMPLE_OT_something.bl_idname)


classes = (EXAMPLE_OT_something,)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
        
    bpy.types.OUTLINER_HT_header.append(draw)


def unregister():
    bpy.types.OUTLINER_HT_header.remove(draw)
    
    for cls in classes:
        bpy.utils.unregister_class(cls)


if __name__ == &quot;__main__&quot;:
    register()