Skip to main content

morocco-communes

Morocco's 12 régions, 83 provinces and préfectures, 213 cercles, 1,503 communes and 41 arrondissements, with HCP's codes, names in French and Arabic, the 2024 and 2014 census figures, and the establishments the 2024 census mapped. It reads from files inside the package, so it works offline.

pip install "morocco-communes[pandas]"
import morocco_communes as mc

communes = mc.communes()                    # 1,503 rows
communes[communes["region_code"] == "01"]   # the 146 in Tanger-Tétouan-Al Hoceima

people = mc.indicators("people")            # the 2024 census, by unit, area and sex
economy = mc.economy()                      # the establishments, by unit
housing = mc.housing()                      # the urban dwellings, by unit

Every table is a pandas DataFrame. With as_frame=False it's a list of dicts instead, and then the package needs nothing but the standard library.

Tables

Call Rows
regions(), provinces(), cercles(), communes(), arrondissements() one per unit
indicators(subject, census) one per unit and area, and per sex for people
economy() one per unit, from the country down to the commune
housing() one per unit with an urban area, 784 of them
crosswalk() one per commune renumbered in 2015

indicators takes "people" or "households", and census "2024" or "2014". The 2024 census asks 73 of the 2014 questions the same way, so those columns subtract.

fields() says what each column measures, with HCP's own heading for it and its unit, and for 2024 the concept HCP defines it under and its wording. It takes "indicators", "indicators2014", "economy" or "housing". sources() gives each workbook's URL, its SHA-256 and the date it was read, and version is the dataset's.

Codes

A unit is identified by its HCP code, and the code is the hierarchy: 01.511.01.0 is a commune of province 01.511, in région 01. Codes stay strings, so code_digits keeps the leading zeros that make it 9 digits wide.

What's elsewhere

Boundaries, which communes border which, search, the urban centres and a commune lookup by point are in the repository and its API. Those all come from OpenStreetMap under ODbL, so they aren't in this package, and neither are the area and density fields derived from them. data/v1/geometry/adjacency.csv is the contiguity graph if you want one: pandas.read_csv takes it straight.

Licence

The code is MIT. The data is the Haut-Commissariat au Plan's, from RGPH 2024 and RGPH 2014, reusable on CC BY 4.0 terms: credit it and say what you changed.

Metadata

Release files for morocco-communes 1.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morocco-communes 1.8.0
File Size Uploaded
morocco_communes-1.8.0.tar.gz 3.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for morocco-communes 1.8.0
File Interpreter ABI Platform
morocco_communes-1.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 MB

Release files / morocco_communes-1.8.0.tar.gz

Download URL morocco_communes-1.8.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
2ffae5bf576187b86c43569784d5da280f952c0f98c4ef9cb1a339420e4ff7fe
BLAKE2b-256 checksum
How to use checksums
fc7baaeb822ca0306d119320c95708e0a39e508d15af3d04a4aa25512b897062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / morocco_communes-1.8.0-py3-none-any.whl

Download URL morocco_communes-1.8.0-py3-none-any.whl
Size 3.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b61c04faefdba0bb86aafd2010fc8d75227883a4c9424b63b24d74bcb62168fa
BLAKE2b-256 checksum
How to use checksums
24040403aa12a39957cc96e6b6184b58caa61fef3931d29740b203e7040e5588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

1.9.1

2 release files

1.9.0

2 release files

This release

1.8.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page