The Hanafi school or Hanafism is the largest school of Islamic jurisprudence out of the four principal schools within Sunni Islam. It developed from the teachings of the jurist and theologian Abu Hanifa (c. 699–767 CE), who systemised the use of reasoning (ra'y). Hanafi legal theory primarily derives law from the Quran, the sayings and practices of Muhammad (sunnah), scholarly consensus (ijma) and analogical reasoning (qiyas), but also considers juristic discretion (istihsan) and local customs (urf). It is distinctive in its greater usage of qiyas than other schools.
The school spread throughout the Muslim world under the patronage of various Islamic empires, including the Abbasids and Seljuks. The region of Transoxiana emerged as a centre of classical Hanafi scholarship between the 10th and 12th centuries, which gave rise to the Maturidi school of theology. The Ottoman Empire adopted Hanafism as its official school of law and influenced the legal thought of the school, eventually codifying it as the Mecelle in the 1870s.