Skip to main content

GeoThai python-library

Every province, district, subdistrict and postal code of Thailand, in one typed Python package with search.

👉 Website · 👉 Data and changelog

Features

  • 77 provinces, 928 districts and 7,436 subdistricts with Thai and English names and DOPA codes
  • Postal codes per subdistrict, and a lookup from a postal code to its subdistricts
  • Search by Thai or English name, with or without spaces, hyphens or the word for the level
  • Frozen dataclasses with a docstring on every field, and Literal types for every code
  • Data loads on the first call, so import geothai stays fast
  • No dependencies

Install

pip install geothai

The package needs Python 3.11 or later.

Usage

>>> from geothai import address, by_postal_code, districts, province, search, subdistricts
>>> province("84")
Province(code='84', name_th='สุราษฎร์ธานี', name_en='Surat Thani')
>>> len(districts("84"))
19
>>> [s.name_en for s in subdistricts("8405")]
['Ko Pha-ngan', 'Ban Tai', 'Ko Tao']
>>> [s.name_th for s in by_postal_code("84280")]
['เกาะพะงัน', 'บ้านใต้']
>>> a = address("840503")
>>> f"{a.subdistrict.name_th} {a.district.name_th} {a.province.name_th}"
'เกาะเต่า เกาะพะงัน สุราษฎร์ธานี'
>>> [f"{r.level} {r.area.name_th}" for r in search("phangan")]
['district เกาะพะงัน', 'subdistrict เกาะพะงัน']

API

Function Returns
provinces() All 77 provinces, sorted by code
province(code) One province, or None
districts(province_code) The districts of a province, empty for an unknown code
district(code) One district, or None
subdistricts(district_code) The subdistricts of a district, empty for an unknown code
subdistrict(code) One subdistrict, or None
address(subdistrict_code) The subdistrict with its district and province, or None
by_postal_code(postal_code) The subdistricts that use a postal code
search(query, *, limit=10) Provinces, districts and subdistricts whose name has the query
DATA_VERSION The GeoThai/data release in this package, such as '2026.10.20'

Every function takes codes as strings and returns a new list. The areas are frozen dataclasses, so you can use them as dictionary keys.

The areas that DOPA abolished have their own module:

>>> from geothai.abolished import abolished_areas
>>> next(a for a in abolished_areas() if a.code == "100205").abolished_on
'2006-01-01'

Types

from geothai.types import Province, ProvinceCode, SearchResult, Subdistrict
Type Content
Province, District, Subdistrict, Abolished One area. Each field has its description from the data schema
ProvinceCode, DistrictCode, SubdistrictCode Every code in use, for autocomplete and checks in your editor
Address, SearchResult What address() and search() return

The functions take str, not the code types. A data release can remove a code, and that must not break your type check in a patch update.

Versions

A new GeoThai/data release ships as a patch version. A change to the API gets a minor or major version. DATA_VERSION tells you which data you have. The changes in each data release are at geothai.fasu.dev/changelog.

Upgrading from v2

Version 3 is a rewrite on new data. Version 2 did not load its data after install, so code that used it did not run.

v2 v3
get_all_provinces() provinces()
get_province_by_code(10) province("10")
get_all_districts(), get_all_subdistricts() districts(code), subdistricts(code)
get_district_by_code(), get_subdistrict_by_code() district(), subdistrict()
get_postal_codes_by_code(code) by_postal_code(code)
get_provinces_by_criterion(...) and the others A list comprehension on the list

The v2 code is on the archive branch.

Why?

Address forms in Thailand need the same four lists, and most copies of them are old: merged postal codes, abolished subdistricts, English names on the wrong area. This package ships the data that GeoThai checks against official sources, with types your editor can read.

License

The code is MIT. The data is CC BY 4.0 © 2026 Pongsakorn Thipayanate.

If you show the data, credit "GeoThai".

Metadata

Release files for geothai 3.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 geothai 3.0.0
File Size Uploaded Provenance
geothai-3.0.0.tar.gz 166.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for geothai 3.0.0
File Interpreter ABI Platform
geothai-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 334.0 kB

Release files / geothai-3.0.0.tar.gz

Download URL geothai-3.0.0.tar.gz
Size 166.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f20fda5e6c697110a4d50d7e0b325f0c4902fecd894b4859b4c11dacda6cf097
BLAKE2b-256 checksum
How to use checksums
9651e01ff88368c93741ceda490346bd0c6d90ccf6b0eded65356a061104b737
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 / geothai-3.0.0-py3-none-any.whl

Download URL geothai-3.0.0-py3-none-any.whl
Size 167.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eae650b6eb520114af9e3ab560331e64fdd27aa07e6816853fedb2f1ebff572c
BLAKE2b-256 checksum
How to use checksums
eea53fa91b37c25a121d31bae9b6058e8bfc14f09ead1840808a595cce352be5
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 geothai 3.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 geothai-3.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 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

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