Morocco’s 1,503 communes, as open data.
Official HCP codes, names in French and Arabic, population from the 2024 and 2014 censuses, what they found about people and homes, the establishments the last one mapped, and a boundary for every commune but one. Free to use.
- < 10
- 10–50
- 50–150
- 150–500
- 500–2,000
- 2,000+
- no boundary
people per km², 2024
- < −10%
- −10 to −2%
- about the same
- +2 to +10%
- +10 to +25%
- > +25%
- no 2014 figure
- no boundary
population, 2014 to 2024
- < 10%
- 10%–20%
- 20%–30%
- 30%–40%
- 40%–50%
- 50%+
- no figure
- no boundary
of people aged 10 and over, 2024
- urban
- rural
- no boundary
1,502 communes, from the boundaries this API serves.Every commune, by région© OpenStreetMap contributors, ODbL
- 12
- régions
- 83
- provinces and préfectures
- 213
- cercles
- 1,503
- communes
- 41
- arrondissements
How a code reads
Each group of digits names a level, so a commune’s code already contains its province and its région. Cercles sit above rural communes only; an urban commune may hold arrondissements instead.
| code | How a code reads | Population, 2024 |
|---|---|---|
| 01 | Tanger-Tétouan-Al Hoceimarégion | 4,030,222 |
| 01.511 | Tanger-Assilahpréfecture | 1,494,413 |
| 01.511.05 | Tangercercle | 60,807 |
| 01.511.05.19 | Hjar Ennhalcommune | 27,204 |
| 01.511.01.0 | Tangercommune | 1,275,428 |
| 01.511.01.05 | Mghoghaarrondissement | 252,656 |
What the numbers show
The south is filling up
Population change by région between the 2014 and 2024 censuses.
- Dakhla-Oued Ed-Dahab+53.9%
- Laâyoune-Sakia El Hamra+22.6%
- Tanger-Tétouan-Al Hoceima+13.3%
- Souss-Massa+12.8%
- Casablanca-Settat+12.1%
- Rabat-Salé-Kénitra+12.0%
- Marrakech-Safi+8.2%
- Fès-Meknès+5.5%
- Guelmim-Oued Noun+3.4%
- Drâa-Tafilalet+1.3%
- Béni Mellal-Khénifra+0.2%
- Oriental−0.9%
Dakhla-Oued Ed-Dahab grew by more than half. The Oriental is the only région that shrank. Each bar is summed from the région’s communes.
Most communes are small
Communes by 2024 population.
- <2k: 64
- 2–5k: 243
- 5–10k: 452
- 10–25k: 515
- 25–50k: 125
- 50–100k: 56
- 100k+: 48
Half the people, under 1% of the land
The 121 densest communes, against the other 1,382.
Most communes lost people
Communes that lost or gained people between the censuses. Overall, urban +12.8%, rural +3.0%.
lost peoplegained
What the two censuses found
5 rates HCP published in 2014 and again in 2024, for Morocco, each asked the same way both times.
- Can’t read or write32.2%24.8%Can’t read or write: 32.2% in 2014, 24.8% in 2024.
- Higher education6.1%10.2%Higher education: 6.1% in 2014, 10.2% in 2024.
- Unemployment16.2%21.3%Unemployment: 16.2% in 2014, 21.3% in 2024.
- Running water73.0%82.9%Running water: 73.0% in 2014, 82.9% in 2024.
- Electricity91.6%97.1%Electricity: 91.6% in 2014, 97.1% in 2024.
20142024
Whether the crosswalk holds up
207 communes were renumbered by the 2015 reform, so their 2014 population had to be matched by name and elimination rather than read off an unchanged code. If those matches were wrong, their implied growth would scatter differently.
The bar spans the 10th to 90th percentile, the block the 25th to 75th, the line the median. The 2 distributions nearly overlap, so the matches look sound. The crosswalk’s README gives the reasoning for each pair.
Run a query
Requests go to the live API.
French, Arabic or a slug. Accents and Arabic letter variants fold, and old names work too: Fez finds Fès, Port Lyautey finds Kénitra.
RequestGET /api/search?q=Fez&limit=5
Pick an example or type a query, then run it.
Build on it
- APIEvery route, with a real response
- MCPConnect Claude, ChatGPT, Cursor or VS Code
- ComponentsA commune picker for forms
- npmThe data as a typed package, offline
- PythonEvery table as a DataFrame, offline
Where a request is answered
The X-Api-Tier header says where a request was answered. A static file has none, since nothing ran.
A file on the CDN
no header, because nothing ran
11,629 responses are written when the site’s built, and cost nothing to serve.
A rewrite to that file
X-Api-Tier: alias
A query string can’t pick a file, so requests written that way are resolved to the file that already holds the answer, and the response names it.
Worked out on the spot
X-Api-Tier: computed
Search, point and radius queries, and filter combinations no single file covers. These are the only requests that spend anything.
Take the whole thing
Every file here is built from the dataset in the repository, which works without the API too. Boundaries, and every figure drawn from them, are under ODbL. The README describes each field.
- CommunesODbLJSON1.8 MBCSV184 KB
- RégionsJSON5.3 KBCSV957 B
- Provinces and préfecturesJSON39 KBCSV6.2 KB
- CerclesJSON97 KBCSV15 KB
- ArrondissementsJSON33 KBCSV3.8 KB
- 2014 to 2024 crosswalkJSON103 KBCSV28 KB
- 2024 census figures, with fields.json naming each one. The communes are in communes/, a file per régionpeople.csv4.9 MBhouseholds.csv881 KBprovinces.json1.2 MBregions.json186 KBfields.json57 KB
- 2014 census figures, in the same shapepeople.csv8.2 MBhouseholds.csv980 KBprovinces.json2 MBregions.json298 KBfields.json77 KBunplaced.json1.6 KB
- Economic establishments counted in 2024establishments.csv205 KBcommunes.json707 KBprovinces.json41 KBregions.json6.3 KBfields.json8 KB
- Boundaries as TopoJSON, one file per régionODbLTanger-Tétouan-Al Hoceima282 KBOriental260 KBFès-Meknès197 KBRabat-Salé-Kénitra170 KBBéni Mellal-Khénifra92 KBCasablanca-Settat172 KBMarrakech-Safi223 KBDrâa-Tafilalet88 KBSouss-Massa149 KBGuelmim-Oued Noun65 KBLaâyoune-Sakia El Hamra107 KBDakhla-Oued Ed-Dahab163 KB
- Boundaries as GeoJSON, one file per régionODbLTanger-Tétouan-Al Hoceima1.1 MBOriental943 KBFès-Meknès739 KBRabat-Salé-Kénitra606 KBBéni Mellal-Khénifra300 KBCasablanca-Settat573 KBMarrakech-Safi768 KBDrâa-Tafilalet279 KBSouss-Massa484 KBGuelmim-Oued Noun212 KBLaâyoune-Sakia El Hamra322 KBDakhla-Oued Ed-Dahab543 KB
- The urban housing stock in 2024, by dwelling rather than by householddwellings.csv214 KBcommunes.json450 KBprovinces.json99 KBregions.json14 KBfields.json22 KB
- Which communes border which, and how much boundary they shareODbLJSON343 KBCSV222 KB
- Province and région outlines, GeoJSONODbLprovinces3 MBrégions2.2 MBarrondissements196 KB
- SourcesJSON5.7 KB