Shihāb al-Dīn al-Qarāfī or in full Shihāb al-Dīn Abū al-'Abbās Aḥmad ibn Idrīs (al-Sanhaji al-Bihinsi al-Misri) al-Qarāfī (1228–1285), was a Maliki jurist of Berber (Sanhaja) origin who lived in Ayyubid and MamlukEgypt. He was born in the Bahnasa district of Upper Egypt reportedly sometime around 1228.
He is considered by many to be the greatest Maliki legal theoretician of the 13th century; his writings and influence on Islamic legal theory (uṣūl al-fiqh) spread throughout the Muslim world. His insistence on the limits of law underscores the importance of non-legal (not to be confused with illegal) considerations in determining the proper course of action, with significant implications for legal reform in the modern Islamic world. His views on the common good (maslahah) and custom provide means to accommodate the space-time differential between modern and premodern realities. The most important of his many works are Al-dhakhirah (The Stored Treasure), Al-furuq (Differences), Nafais al usul (Gems of Legal Theory), and Kitab al-ihkam fi tamyiz al-fatawa an al-ahkam wa tasarrufat al-qadi wa'l-imam (The Book of Perfecting the Distinction Between Legal Opinions, Judicial Decisions, and the Discretionary Actions of Judges and Caliphs).