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, match, 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 เกาะพะงัน']
>>> match("ต.ตลาด", district="อ.เมือง", province="สุราษฎร์ธานี")[0].subdistrict.code
'840101'

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
match(subdistrict, *, district, province, postal_code) The addresses that fit a hand-written address
DATA_VERSION The GeoThai/data release in this package, such as '2026.10.22'

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

match() is for addresses typed by hand, such as old records or form input. It reads short forms such as ต., อ. and จ., the word เมือง for a capital district, and กทม for Bangkok. Names must match in full. One result means the address is clear. More than one means you need another argument: 795 subdistrict names are used more than once. None means no current subdistrict has the name.

The areas that DOPA abolished have their own module:

>>> from geothai.abolished import abolished_areas
>>> bang_na = next(a for a in abolished_areas() if a.code == "104701")
>>> bang_na.abolished_on
'2022-04-22'
>>> bang_na.successors
('104702', '104703')
>>> bang_na.successors_basis
'notice'

successors lists the codes that took an abolished area's place. successors_basis says how sure the link is: "notice" comes from a Royal Gazette notice, with the date and source in successors_in_force and successors_source. "name" is a match by Thai name for codes DOPA dropped in 2006, likely but not proven. When no successor is known, successors is empty.

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". Source credits and the license of thailand-geography-json are in NOTICE.

Metadata

Release files for geothai 3.1.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.1.0
File Size Uploaded Provenance
geothai-3.1.0.tar.gz 175.3 kB With provenance Details

Built distribution (wheel)

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

Total release size: 353.0 kB

Release files / geothai-3.1.0.tar.gz

Download URL geothai-3.1.0.tar.gz
Size 175.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e25a727707d624ae8966c7b8d9a8bcfc76e52e050f76658bed7686892dfe5cf0
BLAKE2b-256 checksum
How to use checksums
703164642f847849688baef330259d7e2c86c3bf52c0ec9a940c749c76705b5f
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 22, 2026.

Transparency log

Release files / geothai-3.1.0-py3-none-any.whl

Download URL geothai-3.1.0-py3-none-any.whl
Size 177.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6bec42a58ed459edc4351b5cd26c77e3a94504a173b662d5e84ee99aa0ab280
BLAKE2b-256 checksum
How to use checksums
9d8a7d5d4b1c5281bfb8c13993b9fb8ee0fa1352001135aa8d1708927a5aba96
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 22, 2026.

Transparency log

Security for geothai 3.1.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.1.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 22, 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.1.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