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), used with attribution, and remains subject to its terms (see NOTICE). This project is not affiliated with or endorsed by the Ministry of Economy and Finance.

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

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

Contributing

pip install -e ".[dev]" then pytest. See RELEASING.md. The behaviour shared with the JavaScript and PHP packages is defined in SPEC.md and checked by spec/conformance.json.

Metadata

Release files for cambodia-geo 1.0.1

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.1
File Size Uploaded Provenance
cambodia_geo-1.0.1.tar.gz 228.2 kB With provenance Details

Built distribution (wheel)

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

Total release size: 454.9 kB

Release files / cambodia_geo-1.0.1.tar.gz

Download URL cambodia_geo-1.0.1.tar.gz
Size 228.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b36ed17a24f9b830eb523cf7a8e99e860f7c52d18b38ae71ee4fc10615ff8f61
BLAKE2b-256 checksum
How to use checksums
6f4926a045a96e6118ba94513e775f0916107b56ba900244e695fdcfa85b6b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL cambodia_geo-1.0.1-py3-none-any.whl
Size 226.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f20f8478db027ea4968e76810a46ce10b686c0d10ca24d57fc6697328bff966
BLAKE2b-256 checksum
How to use checksums
c10f97bdc982d2f097e62c36de689f430da0009ce59b83dc8605a35c127c15b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

Security for cambodia-geo 1.0.1

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.1.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 21, 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.1 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