I wonder if there were some common themes or conditions that led to the rise of the city states in the past.
The rise of cities or towns seems someone well documented But the move from urban to a political or govermental entity is less clear to me.
If question is too broad, perhaps europe or italy evolution is a narrowing.
Not really, no.
A densely urbanized and politically autonomous community can only exist in a globalized world, that is to say a world where specialized goods and services (the typical city-activity) can be easily traded in exchange for raw and/or agricultural goods (typically with several intermediate steps, through a medium of exchange). It is difficult to draw parallels between modern city-states, like Monaco, Singapore, or even semi-autonomous cities like Hong Kong or Gibraltar, with historic autonomous or semi-autonomous cities. The conditions under which these communities emerged and developed are very different.
The modern city-state is almost always a political carve-out, an urban community which for whatever reason was separated and rendered sovereign or semi-sovereign. In some cases, like Singapore or Hong Kong, the cities in question had a specific role in the context of colonial history. In other cases, like Monaco or Liechtenstein, their preservation is more an accident of history, with pre-national autonomies preserved due to inaccessibility or irrelevance.
As we turn the clock back to a world where trade routes are more perilous, services translate with more difficulty across cultures and social systems, and goods become more perishable over long voyages, cities result as being increasingly dependent on their hinterland and the surrounding countryside. There are very few cities (in Europe, at least) which unilaterally cut themselves off (politically) from their surroundings. Rather, medieval European societies which are particularly urbanized, or where the urban space plays host to particularly powerful political institutions, most commonly emerge when a nation-like super-structure is particularly weak or notably absent (and that is saying something, since while we might measure political effectiveness against modern concepts of sovereignty, contemporary ideals were much different in the medieval era). So unlike of modern accords and agreements stipulating sovereignty, in medieval Europe there is seldom one single moment when autonomous cities can be said to spring into existence. Rather, city institutions organically developed economic and political powers (often extending their influence far into the countryside and over satellite towns) such that they could operate with something resembling sovereignty.
So on the example of Italy, the peninsula (like much of Mediterranean Europe) is on the one hand notable for its high degree of historic urbanization (which it is able to preserve, at least comparatively, through the post-roman period) and on the other hand notable for a particularly weak governmental super-structure which deteriorates even further in the eleventh century (I wrote about that, along with a few other things which might interest you on the context of this question, in this other answer). Importantly, Italians never jettison the broad notion of "Empire," and at times even insist on it and exploited it: countless Italian cities received "Charters" enshrining their autonomy from the Holy Roman Emperor, leading to the confusing situation (at least as far as out modern understanding might allow) whereby their nominal sovereign was in fact codifying and guaranteeing their independence. That is fundamentally because sovereignty and independence, as understood by Italians, doesn't really match the sorts of notions modern readers would recognize until at least the seventeenth century, and besides, those Italian states which were earliest in developing the apparatus of modern government (notable examples include the Republic of Venice, and somewhat surprisingly, those parts of Italy integrated with the Spanish Empire) could not be termed city-states at this point, having become complex polities governing extensive territories.