Python path for allowing animation of viewport and render visibility of objects EDIT: It turns out I formulated this question out of a misunderstanding of my own old code. See @batFINGER and @scurest answers.
I'm working on a script which automates some animation, which includes turning on and off objects' viewport and render visibility with Object.hide_viewport and Object.hide_render. These objects will be created with the script.
In the Object Properties tab under 'Visibility', there is a button besides the 'Show in Viewports' and 'Show in Renders' buttons that allows these settings to show up in the Dope Sheet and be animated. I've attached a photo of these buttons, highlighted in red. How can I access these 'Animate property.' buttons with Python? As in what value do they change? Nothing shows up when hovering over this button with Python Tooltips on, nor does anything show up in the scripting info view when I click this button. Or is there an alternate way to do this?
Thanks!
Keyframe Insert / Delete.
Further to the answer of @scurest

Mouse over the property after setting to refresh the panel
Every object in blender has a keyframe_insert and keyframe_delete method.   It does everything required, eg if the object has no animation data or action it adds them, then adds the keyframe.
Set the value, insert the keyframe. eg hide the object at frame 10
&gt;&gt;&gt; C.object.hide_viewport = True
&gt;&gt;&gt; C.object.keyframe_insert('hide_viewport', frame=10)
True

Can pass the frame, or it defaults to the current frame of the scene.