Skip to main content

Find Taiwan ZIP code by address fuzzily.

Project description

This package lets you find ZIP code by address in Taiwan.

The main features:

  1. Fast. It builds ZIP code index by tokenization.
  2. Gradual. It returns partial ZIP code rather than noting when address is not detailed enoguh.
  3. Stand-alone. It depends on nothing.


Find ZIP code gradually:

>>> import zipcodetw
>>> zipcodetw.find('臺北市')
>>> zipcodetw.find('臺北市信義區')
>>> zipcodetw.find('臺北市信義區市府路')
>>> zipcodetw.find('臺北市信義區市府路1號')

After v0.3, you even can find ZIP code like:

>>> zipcodetw.find('松山區')
>>> zipcodetw.find('秀山街')
>>> zipcodetw.find('台北市秀山街')


It is available on PyPI:

$ sudo pip install zipcodetw

Just install it and have fun. :)

Build Index Manually

If you install it by pip or python install, a ZIP code index will be built automatically. But if you want to use it from source code, you have to build an index manually:

$ python -m zipcodetw.builder


The ZIP code directory is provided by Chunghwa Post, and is available from:



  1. Updated to the 3+3 v2102.01 data.
  2. Fixed a Python 3 bug, maybe.


  1. A black hole ate the logs.


  1. Fixed the py2 py3 compatibility. Thanks the contribution from Poren Chiang and Ryan.


  1. Updated the data to 2014/12.


  1. Fixed a rarely issue that causes IndexError.


  1. Reverted removing insignificant tokens introduced in v0.5.4.
  2. It now handles insignificant tokens; and
  3. redundant units in the finding logic (directory.find).
  4. Allowed number token ends without unit.
  5. Now address.tokens is a list.


  1. Fixed a gradual matching issue causing some wrong results.


  1. Removed the token whose unit is insignificant automatically.


  1. Fixed and simplified the matching logic for address tail.
  2. Refined the index building logic.


  1. Fixed the issue while it was running in multi-threaded environment.
  2. Added a new argument, keep_alive, for the Directory class.


  1. Refined the code slightly.


  1. It now builds a ZIP code index when you install it; so
  2. the package size is 12.5x smaller.
  3. The internal API is better now.


  1. It now shipped with an index compiled in SQLite; so
  2. initiation time is ~680x faster, i.e. ~30ms each import; and
  3. zipcodetw.find is ~1.9x slower, i.e. ~2ms each call; and
  4. has bigger package size.
  5. All code was moved into zipcodetw package.
  6. zipcodetw.find now returns unicode instead of string.


  1. It builds full index for middle tokens; and
  2. also normalizes Chinese numerals now!
  3. zipcodetw.find is ~1.06x faster.
  4. But initiation time increases to ~1.7x.


  1. zipcodetw.find is 8x faster now!
  2. It has a better tokenizing logic; and
  3. a better matching logic for sub-number now.
  4. zipcodetw.find_zipcodes was removed.
  5. Internal API was changed a lot.
  6. The tests are better now.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zipcodetw-0.6.8.tar.gz (592.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page