A Rally Task item must be associated with a WorkProduct (customarily an Artifact like HierarchicalRequirement (aka UserStory), Defect or TestCase). Using the pyral toolkit, once you have your Rally instance, get the object refs for the Workspace, Project and WorkProduct that the task is to be associated with, then populate a Python dict with those items along with the other required Task attributes and throw it at Rally.
Task creation recipe:
[insert your boilerplate code for dealing with command line args, Rally options, etc]
rally = Rally(server, username, password, workspace=workspace, project=project)
artifact_ident = args.pop() # get the FormattedID of an artifact as the Task relation target
wksp = rally.getWorkspace()
proj = rally.getProject()
artifact = rally.get("UserStory", fetch="FormattedID",
query='FormattedID = "%s"' % artifact_ident,
instance=True)
# for a Task, the Workspace, Project, WorkProduct, Name, State and TaskIndex attributes
# are required. The Workspace, Project and WorkProduct attributes must be supplied as
# valid Rally object references.
info = { "Workspace" : wksp.ref,
"Project" : proj.ref,
"WorkProduct" : artifact.ref,
"Name" : "Scrape vanilla bean",
"State" : "Defined",
"TaskIndex" : 1,
"Description" : "With a dull knife, strip material from the vanilla bean"
}
task = rally.put('Task', info)
print "Created Task: %s associated with UserStory %s" % (task.FormattedID, artifact.FormattedID)