This is an example of how to rank a User Story in relation to another User Story using the Pyral toolkit. Below are some useful links that were used to create this simple example.
This does not include the boiler plate connection and authentication code. You can get an example of that code here. The script, named testRank.py, takes 2 command line parameters. The first parameter is the FormattedID of the HierarchicalRequirement that you want to change the ranking. The second parameter is the FormattedID of the HierarchicalRequirement used to rank the one from the first parameter below. For the example below, US1 will be ranked below US2.
[user@pyralScripts]$ python testRank.py US1 US2
query_criteria = 'FormattedID contains "%s"' % args[0]
query_criteria2 = 'FormattedID contains "%s"' % args[1]
response = rally.get('HierarchicalRequirement', fetch=True, query=query_criteria)
response2 = rally.get('HierarchicalRequirement', fetch=True, query=query_criteria2)
story=response.next()
story2=response2.next()
rally.rankBelow( story, story2 )
print("Finished ranking artifacts.")