Skip to main content

cambodia-geo

Lightweight, zero-dependency Python library for Cambodia's administrative divisions: provinces (ខេត្ត), districts (ស្រុក/ខណ្ឌ), communes (ឃុំ/សង្កាត់) and villages (ភូមិ). Look things up by code, Khmer name or English name, in any mix.

Data source: data.mef.gov.kh (bundled dataset year: see cambodia_geo.DATA_YEAR).

pip install cambodia-geo

Python 3.9+. No runtime dependencies. Data is bundled and loaded lazily on first use.

Quick start

import cambodia_geo as kh

kh.provinces()                                 # all provinces
kh.districts("Siemreap")                       # districts of a province
kh.communes("17", "Angkor Thum")               # communes of a district
kh.villages("សៀមរាប", 1702, "ជប់តាត្រាវ")        # villages of a commune

p = kh.get_province("សៀមរាប")                   # Province(code='17', name_kh=..., name_en=...)
p.code, p.name_kh, p.name_en
p.to_dict()                                    # plain dict, ready for JSON

kh.get_district("Angkor Thum", province="Siemreap")
kh.get_commune("170201")
kh.search("angkor")                            # across all levels, best matches first

Records can be passed straight back in:

for province in kh.provinces():
    for district in kh.districts(province):
        ...

API

Function Returns Not found
provinces() list[Province] -
districts(province) list[District] []
communes(province, district) list[Commune] []
villages(province, district, commune) list[Village] []
get_province(query) Province None
get_district(query, *, province=None) District None
get_commune(query, *, district=None, province=None) Commune None
get_village(query, *, commune=None, district=None, province=None) Village None
search(query, *, level=None, limit=50) list[Province | District | Commune | Village] []

Also: DATA_YEAR (int) and __version__ (str).

Records are frozen dataclasses (hashable, typed, py.typed included):

Type Fields
Province code, name_kh, name_en
District code, name_kh, name_en, province_code
Commune code, name_kh, name_en, province_code, district_code
Village code, name_kh, name_en, province_code, district_code, commune_code

Matching rules

  • A query is a code ("17", 17, "017" and Khmer digits "១៧" are equal), a Khmer name or an English name.
  • Names ignore case, spaces and - ' . , : "Siem Reap" == "siemreap".
  • With a parent (province=, district=, ...) the first match inside it is returned.
  • Without a parent, a name must be unambiguous; if several places share the name, None is returned instead of guessing. Codes are always safe to use alone.

Data notes

The bundled MEF files are shipped exactly as published. The 2025 dataset contains a few upstream quirks:

  • Some village codes are shared by several villages of the same commune (e.g. 08120101, and the placeholder 0506140-). Listing functions return all of them; get_village(code) without a parent returns None for these codes instead of guessing, and a scoped get_village(name, commune=...) returns the first match.
  • Commune 120913 (Phnom Penh, district 1209) has villages but is missing from the commune list, so villages("12", "1209", "120913") returns [].

Stability (no surprise breaking changes)

  • Semantic Versioning. Only names in cambodia_geo.__all__ are public.
  • Within a major version, functions, parameters and record fields are never removed or renamed; new options are keyword-only with defaults, new record fields are appended.
  • Removals are announced with a DeprecationWarning and a changelog entry first.
  • Data updates (once a year) ship as a MINOR release. Government reorganisations can change codes or names between years; pin the version (cambodia-geo~=1.0) if you store codes long-term, and check DATA_YEAR.

Data & licence

The code is MIT licensed. The bundled data comes from the Ministry of Economy and Finance (data.mef.gov.kh, terms of use) and remains subject to its terms.

ភាសាខ្មែរ (សង្ខេប)

បណ្ណាល័យ Python ស្រាល គ្មាន dependency សម្រាប់ស្វែងរក ខេត្ត ស្រុក ឃុំ ភូមិ នៃកម្ពុជា តាមលេខកូដ ឈ្មោះខ្មែរ ឬឈ្មោះអង់គ្លេស។ ដំឡើងដោយ pip install cambodia-geo ហើយប្រើ import cambodia_geo as kh។ ទិន្នន័យអាប់ដេតរៀងរាល់ឆ្នាំ (មើល kh.DATA_YEAR)។

Contributing

pip install -e ".[dev]" then pytest. See RELEASING.md.

Metadata

Release files for cambodia-geo 1.0.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 cambodia-geo 1.0.0
File Size Uploaded Provenance
cambodia_geo-1.0.0.tar.gz 219.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cambodia-geo 1.0.0
File Interpreter ABI Platform
cambodia_geo-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 445.4 kB

Release files / cambodia_geo-1.0.0.tar.gz

Download URL cambodia_geo-1.0.0.tar.gz
Size 219.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5cc173d45408e5ef730709a96384e22c4c5fd2131e1a45a563861c6b537deb16
BLAKE2b-256 checksum
How to use checksums
b5530bc50e259dfc09865654a7ac481e1a45e0225b9dea4fcdca25ea3aef0801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / cambodia_geo-1.0.0-py3-none-any.whl

Download URL cambodia_geo-1.0.0-py3-none-any.whl
Size 225.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c0e5c238e4eff52341bad719a3a0a8f9ee7b233259bc5001647017e19ab6768
BLAKE2b-256 checksum
How to use checksums
fa361d8fef17056969c9903bd1f91836069f8ec8667a315d5b4ff61ba9ce2f43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for cambodia-geo 1.0.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cambodia_geo-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

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