Researchers have unveiled a ground-breaking technique to produce pharmaceuticals on demand, which could eventually lead to a kind of 'Spotify for chemistry'.

The process involves sending a digital code to a specialised 3D printer, which can synthesise drugs at the click of a button, using widely available starting compounds.

In much the same way that Spotify hosts digital files of songs and allows instant playback on compatible devices, a similar service involving a database of drug code sequences could allow clinicians or patients to instantly get hold of almost any treatment they need.

This has the potential to revolutionise the pharmaceutical industry by making useful drugs more accessible – especially ones in short supply - as they will no longer need to be produced in dedicated factories. The breakthrough may also reduce the risk of drug counterfeiting, bring down prices and may also herald an era of tailored medications for patients.

Furthermore, it may encourage the production of pharmaceuticals which are not common enough to justify large-scale manufacturing, as well as the use of drugs in remote settings.

Scientists from the University of Glasgow have described their new approach in a paper published in the journal Science.

For the study, they demonstrated the technique by producing a drug called Baclofen – a type of muscle relaxant, which can be used to treat symptoms of multiple sclerosis. To do this, they had to digitise the chemical code for Baclofen – in a process compared to burning a CD to generate an .mp3 file.

"This approach is a key step in the digitisation of chemistry, and will allow the on-demand production of chemicals and drugs that are in short supply, hard to make at big facilities, and allow customisation to tailor them to the application," said Lee Cronin, who designed and developed the technique.

"We will also use this approach to make a 'Spotify for chemistry', allowing scientists to develop better code to make important chemicals."