the political level, the community emancipated itself from the exile of Baghdad at the beginning of the eleventh century and acquired its first secular chief. Each community was placed under the authority of a council of notables headed by a chief (naggid) who, through the faithful, disposes of the resources necessary for the proper functioning of the various institutions: worship, schools, a tribunal headed by the rabbi- Judge (dayan), etc. The maggid of Kairouan undoubtedly had the ascendancy over those of the communities of smaller size. The Jews participate greatly in the exchanges with Al-Andalus, Egypt and the Middle East. Grouped in separate quarters (although many Jews settled in the Muslim districts of Kairouan during the Fatimid period), they had house of prayer, schools and a court. The port cities of Mahdia, Sousse, Sfax and Gabès saw a steady influx of Jewish immigrants from the Levant to the end of the eleventh century, and their communities participated in these economic and intellectual exchanges. Monopolizing the goldsmiths' and jewelers' crafts, they also worked in the textile industry, as tailors, tanners and shoemakers, while the smallest rural communities practiced agriculture (saffron, henna, vine, etc.) or breeding of nomadic animals. Under the Hafsids, Spanish and Ottomans (1236–1603) The departure of the Fatimids to Egypt in 972 led their Zirid vassals to seize power and eventually break their bonds of political and religious submission in the middle of the eleventh century. The Banu Hilal and the Banu Sulaym, were sent in retaliation against Tunisia by the Fatimids, took Kairouan in 1057 and plundered it, which empties it of all its population then plunges it into the doldrums. Combined with the triumph of Sunnism and the end of the Babylonian gaonate, these events marked the end of the Kairouan community and reversed the migratory flow of the Jewish populations towards the Levant, with the elites having already accompanied the Fatimid court in Cairo. Jews have migrated to the coastal cities of Gabes, Sfax, Mahdia, Sousse and Tunis, but also to Béjaïa, Tlemcen and Beni Hammad Fort. Under the Hafsid dynasty, which was established in 1236 as a breakaway from the Almohad dynasty, the condition of the Jews greatly improved. Besides Kairwan, there were at that time important communities in Mehdia, Kalaa, the island of Djerba, and the city of Tunis. Considered at first as foreigners, the Jews were not permitted to settle in the interior