npm package
The whole hierarchy as a typed package. It works offline and has no dependencies.
Install
npm install morocco-communesUse
import { regions, provincesOf, communesOf, getCommune } from "morocco-communes";
regions[0].name.fr; // "Tanger-Tétouan-Al Hoceima"
provincesOf("01"); // its 8 provinces and préfectures
communesOf("01.511"); // the 12 communes of Tanger-Assilah
getCommune("tanger"); // { code: "01.511.01.0", type: "urban", population: 1275428, ... }Each list is also its own module, so a région dropdown doesn’t pull in every commune.
import regions from "morocco-communes/regions";Records
| List | Fields |
|---|---|
| regions | code, name, population |
| provinces | code, name, type, region, population |
| cercles | code, name, region, province, population |
| communes | code, slug, name, type, region, province, cercle, population, population2014 |
| arrondissements | code, name, commune, population |
name is { fr, ar } and population is the 2024 census total. A parent is given by its code, and a commune’s cercle is null when it’s urban.
Helpers
getCommune(codeOrSlug)finds a commune by01.511.01.0ortanger.provincesOf(region),cerclesOf(province)andarrondissementsOf(commune)list a unit’s children.communesOf(code)takes a région, a province or a cercle.versionis the dataset’s version, which is also the package’s.
What it leaves out
Boundaries, and everything drawn from them (the centroid, bounding box, OpenStreetMap id, area and density), are under ODbL, so they stay in the downloads and the API. Households and the Moroccan and foreign split stay out too.
Licence
The code is MIT. The data is from the Haut-Commissariat au Plan (RGPH 2024 and 2014); credit it when you publish it.