Three would-be thugs have learnt their lesson after setting upon a fellow train passenger in a dimly-lit alley in Sydney's west

The three men attacked the 27-year-old German medical student after getting off the train and following him down the alley at Kingswood on Tuesday.

What the muggers did not realise was that the alley ran behind the Ninja Senshi Ryu warrior school.

A ninja student coming out of class noticed the attack and alerted his teacher and three other students.

Ninja sensei, Kaylan Soto, says he and his students gave chase to the men.

"We looked around to see what was happening and there were three blokes on this guy just kicking him and punching him in the head," he said.

"We started running towards them and they took off. They would have seen five of us in ninja gear...all in black with our belts on, running toward them.

"I think they're probably still running if I'm not mistaken."

Police say they have charged a 16-year-old boy and a 20-year-old man with robbery in company over the assault.

They are looking for a third male described as being aged between 15 and 17, 165cm tall and caucasian.

Anyone with information is urged to call Crime Stoppers on 1800 333 000.