Create NLA strip from python without overlapping other strips

Is there a way in python to check if an NLA track has open space in a range of frames? I couldn’t find anything in the API nor by using the dir() function in a python console. I would expect it to be either in the NlaTrack class or the NlaStrips class. The only way I can think of so far is to run and catch the error, such as:

try:"NewStrip", 35,["SomeAction"])
except Exception as e:
	err = e
if 'Error: Unable to add strip (the track does not have any space to accommodate this new strip)\n' in err.args:
	# code for what to do if there is no room for the strip

One problem with this is that it will initially attempt to create a strip that is the length of the action, which could be past open space in the track. However, I might want to run the action quicker or only use part of the action. For example, suppose a track is free from frames 30-80, and I use to create a strip with an action that lasts 100 frames, but I only want to use the first 25 frames. Do do this I would have to initially create the strip as 100 frames long then set NlaStrip.action_frame_end to 25. This would make the strip last from frames 35-60, which would fit since the track is open from frames 30-80. However, since it initially makes the strip 100 frames long, it would last from frames 30-130, and would overlap the strip that starts at frame 81. This would cause the error and the strip would not be created.

The only way I can think of around this is to create a dummy action that lasts only 1 frame, then change NlaStrip.action to the action I want the strip to use. However, this all does not seem like good practice. Is there a way to check if a track is open at a frame, or for a range of frames? Is there a way to set the length of a strip when using so that it wouldn’t overlap other strips in the same track?

you can iterate over the strips and check the difference between the strip.frame_end and strip.frame_start of the next or previous strip
if you are going to add a strips while iterating then you should probably use while loop instead of for.
so something like

i = 1
while i < len(track.strips)
     empty_range = track.strips[i].frame_start - track.strips[i-1].frame_end
     if empty_range > 1:
   = 'new strips', start = track.strips[i-1].frame_end, action = your_action)
     i += 1

if your action.frame_range is bigger then the empty space range then I guess you would probably need either to add first the strip with an empty action and then change its frame_end and action, or create it temporarily on a different track or different point in time and then change back via its attributes

Thanks for the response. I wish there was a more convenient way to do this, but this will work well enough.