Simple python script to stitch images into movie failing with incorrect context I'm trying to write a simple script that adds png images to the video seqeuence editor, and stitches them into a movie. However, between the blender API and all of the old documentation that's floating around online, I can't seem to get it to work. Here's my code:
import bpy
import os, glob


img_dir = 'my/img/dir'

# set movie render settings
resx = 1024
resy = 350

bpy.data.scenes[&quot;Scene&quot;].render.resolution_x = resx
bpy.data.scenes[&quot;Scene&quot;].render.resolution_y = resy
bpy.data.scenes[&quot;Scene&quot;].render.resolution_percentage = 100

scene = bpy.data.scenes[0]
editor = scene.sequence_editor_create()

# get image files
image_files = []
for _file in os.listdir(path=img_dir):
    if _file.endswith('.png'):
        image_files.append(_file)

context = bpy.context

# add to sequencer
img_strip = [{'name':i} for i in image_files]
frames = len(image_files)
frame_end = frames - 1  # offset for python counting

a = bpy.ops.sequencer.image_strip_add(directory=img_dir, files=img_strip,
    channel=1, frame_start=0, frame_end=frame_end)

strip_name = file[0].get(&quot;name&quot;)
bpy.data.scenes[&quot;Scene&quot;].frame_end = frames
bpy.data.scenes[&quot;Scene&quot;].render.image_settings.file_format = 'AVI_JPEG'
bpy.data.scenes[&quot;Scene&quot;].render.filepath = out_dir
bpy.ops.render.render( animation=True )

with output:
line 32, in &lt;module&gt;
    channel=1, frame_start=0, frame_end=frame_end)
  File &quot;/usr/share/blender/scripts/modules/bpy/ops.py&quot;, line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.image_strip_add.poll() failed, context is incorrect


What does this error mean? And how might I go about modifying my code?
Ditch the operator.
Have updated the code from
Importing multiple movie clips inside one directory via script

look at all images in a path
glob on &quot;*.png&quot;
to use pathlib.Path

Adding each image as a strip.
import bpy
from pathlib import Path

# glob all movie files from
dir_path = &quot;/home/batfinger/Pictures&quot;
img_dir = Path(dir_path)
glob = &quot;*.png&quot;
frame_duration = 24
files = sorted(list(img_dir.glob(glob)))

# get sequence editor
scene = bpy.context.scene
#scene.sequence_editor_clear()
sed = scene.sequence_editor_create()
seq = sed.sequences

# add movie strips
for i, fp in enumerate(files):
    ms = seq.new_image(
            name=fp.name,
            filepath=str(fp),
            channel=i + 1,
            frame_start= i * frame_duration + 1 ,
            
            )
    ms.frame_final_duration = frame_duration
    # print some details
    print(&quot;%s ch: %d fs: %3.1f len: %d&quot; %
            (fp.name, i + 1, ms.frame_start, ms.frame_final_duration)
            )

Adding images as sequence to one strip.
import bpy
from pathlib import Path

dir_path = &quot;/home/batfinger/Pictures&quot;
img_dir = Path(dir_path)
glob = &quot;*.png&quot;
frame_duration = 24
files = sorted(list(img_dir.glob(glob)))

# get sequence editor
scene = bpy.context.scene
#scene.sequence_editor_clear()
sed = scene.sequence_editor_create()
seq = sed.sequences
duration = len(files)
# add image strip using first
fp = files.pop(0)
imstrip = seq.new_image(
    name=fp.name,
    filepath=str(fp),
    frame_start=1,
    channel=1,
    )
# add the elements 
while files:
    imstrip.elements.append(files.pop(0).name)
    
imstrip.frame_final_duration = duration
imstrip.update()