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 72 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.10.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.10.0
File Size Uploaded Provenance Actions
morocco_communes-1.10.0.tar.gz 3.2 MB Without provenance Details for morocco_communes-1.10.0.tar.gz

Built distribution (wheel)

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

Total release size: 6.3 MB

Release files / morocco_communes-1.10.0.tar.gz

Download URL morocco_communes-1.10.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
94a70e74b8b7972e2b6b0d8a6328b00dff087dfd6be6d7c6d52f267c428db734
BLAKE2b-256 checksum
How to use checksums
2dcd497c3e3818cc4e352bfc953e155b0c499400e13e2cf9fa05cfc57d96d80b
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.10.0-py3-none-any.whl

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

Security for morocco-communes 1.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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