The 21-year-old, who can also play in midfield, scored twice in 33 games after joining Posh from Hartlepool for £500,000 in September 2014.
But he did not figure last season and spent the first half of the campaign with Bradford City, before returning to Pools on loan in February.
James has signed with an option to make the move permanent next May.
He is Darrell Clarke's third new signing of the summer for Rovers, who have won promotion in the last two seasons, following Plymouth Argyle central defender Peter Hartley and Port Vale winger Byron Moore.
"He's only 21 but already has the benefit of over 150 league games behind him," said Clarke. "They sold him to Peterborough for a £500,000 fee and he has since been out on loan at Bradford City and back at Hartlepool.
"I thought he was Pools' best player when they came to The Mem last season. I've watched him on a number of occasions in the last few years. He's always impressed me with his work rate and I believe I can get him scoring goals."
Find all the latest football transfers on our dedicated page.

Matt McClure stunned the hosts by flicking the Shots into a 1-0 lead after three minutes, but Tranmere hit back through Cole Stockton's sharp volley on the rebound nine minutes later.
Connor Jennings then fired Tranmere in front after being put clean through by James Norwood after 23 minutes, but Aldershot dug in and levelled up via Bernard Mensah five minutes before the interval.
Lois Maynard headed Liam Ridehalgh's free-kick wide as the hosts pushed late on, but they were unable to stop leaders Lincoln extending their advantage to five points.
Match report supplied by the Press Association.
Match ends, Tranmere Rovers 2, Aldershot Town 2.
Second Half ends, Tranmere Rovers 2, Aldershot Town 2.
Substitution, Aldershot Town. Manny Oyeleke replaces Jim Kellerman.
Jim Kellerman (Aldershot Town) is shown the yellow card.
Substitution, Tranmere Rovers. Andy Cook replaces Cole Stockton.
Substitution, Aldershot Town. Shamir Fenelon replaces Idris Kanu.
Connor Jennings (Tranmere Rovers) is shown the yellow card.
Substitution, Tranmere Rovers. Erico Sousa replaces Adam Buxton.
Kundai Benyu (Aldershot Town) is shown the yellow card.
Michael Ihiekwe (Tranmere Rovers) is shown the yellow card.
Second Half begins Tranmere Rovers 2, Aldershot Town 2.
First Half ends, Tranmere Rovers 2, Aldershot Town 2.
Goal!  Tranmere Rovers 2, Aldershot Town 2. Bernard Mensah (Aldershot Town).
Goal!  Tranmere Rovers 2, Aldershot Town 1. Connor Jennings (Tranmere Rovers).
Goal!  Tranmere Rovers 1, Aldershot Town 1. Cole Stockton (Tranmere Rovers).
Goal!  Tranmere Rovers 0, Aldershot Town 1. Matt McClure (Aldershot Town).
First Half begins.
Lineups are announced and players are warming up.
Bristol Rovers have signed forward Luke James on a season-long loan from fellow League One side Peterborough United.
[NEXT_CONCEPT]
Tranmere lost ground at the top of the National League after Aldershot held them to a 2-2 draw.