Duplicate a mesh via python I'd like to improve my duplicator script.
bpy.ops.object.duplicate() seems to require me to select the object first.
I'd like to just feed the object straight to it instead.

Is there a smarter way to handle it than I did so far?

def duplicator(name):
    # select the object
    obj = bpy.data.objects.get(name)
    obj.select_set(True)

    # Loop 3 times, duplicate it, name it
    for i in range(1,4):
        # duplicate selected object
        bpy.ops.object.duplicate()

        # name new object with a string and number
        newObj = bpy.context.selected_objects[0]
        newName = 'Plane_' + str ( i )
        newObj.name = newName


duplicator('Plane_0')
Another take

Before closing as dupe, thought I would put together another take on this for example sake.

Added a method that simply yields n copies of the given object with a new name and suffix.  If linked is False the object copies all share the same mesh.

import bpy
from bpy import context 

def object_duper(ob, name, n=1, linked=False):
    assert(ob)
    for i in range(n):
        copy = ob.copy()
        if ob.data and linked:
            copy.data = copy.data.copy()
        copy.name = f"{name}_{i + 1}"
        yield copy

# testing

ob = context.object

for o in object_duper(ob, ob.name, 5):
    context.scene.collection.objects.link(o)


This method simply dupes the objects which will naturally be added to bpy.data.objects collection. I have not put in the link to collection.  Could emulate your answer method with, and pass the collection

def dupe_n_link(collection, ob, name, n=1, linked=False):
    for o in object_duper(ob, name, n=n, linked=linked):
        collection.objects.link(o)


Can think of many reasons to create multiple duplicates, may not always wish  to add all dupes to same collection, may wish to add one to each collection

ob = context.object

colls = bpy.data.collections

for c, o in zip(colls, object_duper(ob, "Basis", n=len(colls))):
    c.objects.link(o)