npm package

The whole hierarchy as a typed package. It works offline and has no dependencies.

Install

shell
npm install morocco-communes

The package on npm

Use

JavaScript
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.

JavaScript
import regions from "morocco-communes/regions";

Records

ListFields
regionscode, name, population
provincescode, name, type, region, population
cerclescode, name, region, province, population
communescode, slug, name, type, region, province, cercle, population, population2014
arrondissementscode, 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 by 01.511.01.0 or tanger.
  • provincesOf(region), cerclesOf(province) and arrondissementsOf(commune) list a unit’s children.
  • communesOf(code) takes a région, a province or a cercle.
  • version is 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.