The first known written reference to Frankfurt was signed in 794 by none other than Charlemagne, who granted the town to the convent at St Emmeram. Frankfurt had been established as a trading centre since Roman times, and by the 12th century the city's famous trade fairs were attracting punters from as far afield as the Mediterranean and the Baltic. Frankfurt was propelled into prominence when it was made the site of the election and coronation of German kings, with Frederick I Barbarossa setting the tradition in motion in 1152. The Frankfurters bought their autonomy from Karl IV for a fee of 8800 Gulden in 1372, making Frankfurt a freie Reichstadt, or free imperial city, but this couldn't prevent the city from being occupied on numerous occasions: in 1631 by Swedish troops during the Thirty Years' War, in 1759-63 by French troops during the Seven Years' War, and again during the Napoleonic Wars.
Frankfurt's character was strongly secular, as befitting a cosmopolitan trading centre, and the city was among the first to embrace Luther's reformist ideas. It held a significant position in the Holy Roman Empire of Germany, although the Hessian principalities that surrounded it remained a disorganised and lowly bunch right up to 1945. The Holy Roman Empire ended with a whimper in 1806 with Napoleon, and in the wash-up that followed his fall from grace the country's countless principalities were reorganised into a confederation of 35 states, with Frankfurt hosting its ineffective Reichstag. In 1848, that great year of revolutions, Germany's very first parliamentary delegation met briefly at Frankfurt's Paulskirche; US president John F Kennedy was referring to this event when he described Frankfurt as 'the cradle of democracy in Germany'.