to substitute
obj.data.use_auto_smooth = True
obj.data.auto_smooth_angle = 30*0.0174533
in Blender >4.1 you can do
bpy.ops.object.modifier_add_node_group(asset_library_type='ESSENTIALS', asset_library_identifier="", relative_asset_identifier="geometry_nodes/smooth_by_angle.blend/NodeTree/Smooth by Angle")
or using context override:
import bpy
obj=bpy.context.active_object
(lambda obj: (foo:=bpy.context.temp_override(active_object= obj),foo.__enter__(),bpy.ops.object.modifier_add_node_group(asset_library_type='ESSENTIALS', asset_library_identifier="", relative_asset_identifier="geometry_nodes/smooth_by_angle.blend/NodeTree/Smooth by Angle"),foo.__exit__()))(obj)
I also came up with a one liner for doing the same thing without ops (can probably be simplified, I just cant find any docs on how to do it "properly" so therefore I had to build the file path manually based on blender version number & executable file path):
import bpy
obj=bpy.context.active_object
node=obj.modifiers.new("Smooth by Angle", "NODES"); node.node_group=bpy.data.node_groups['Smooth by Angle'] if 'Smooth by Angle' in bpy.data.node_groups else (bpy.ops.wm.append(directory=bpy.app.binary_path.replace('\\','/')[0:bpy.app.binary_path.replace('\\','/').rfind('/')]+f"/{bpy.app.version_string[:bpy.app.version_string.rindex('.')]}/datafiles/assets/geometry_nodes/smooth_by_angle.blend/NodeTree/Smooth by Angle"),bpy.data.node_groups['Smooth by Angle'])[1];node["Input_1"]=30*0.0174533
Note that only the last example gives you a reference to the newly added modifier - and is therefore the only of these solutions that lets you set the angle to anything but its default.
I suppose one might also want to check if a modifier by the name "Smooth by Angle" exists on the object, and only add one if it doesnt - and then set the angle to whatever one desires on the newly added or existing "Smooth by Angle" modifier:
import bpy
obj=bpy.context.active_object
(lambda obj, angleDegrees=30: (obj.modifiers["Smooth by Angle"].__setitem__("Input_1",angleDegrees*0.0174533) if "Smooth by Angle" in obj.modifiers else (foo:=bpy.context.temp_override(active_object= obj),foo.__enter__(),bpy.ops.object.modifier_add_node_group(asset_library_type='ESSENTIALS', asset_library_identifier="", relative_asset_identifier="geometry_nodes/smooth_by_angle.blend/NodeTree/Smooth by Angle"),foo.__exit__(),obj.modifiers["Smooth by Angle"].__setitem__("Input_1",angleDegrees*0.0174533))))(obj,25)
use_auto_smooth
has been removed in Blender 4.1. If the addon hasn't been updated, you can still use it by downgrading to Blender 4.0. $\endgroup$