Skip to main content

Easy wrapper for the zip code data of Japan

Project description

Easy wrapper for the zip code data of Japan

Powered by Yamato Nagata

Installation

install with pip

$ pip install jusho

GitHub

Example

Useful example HERE

demo

from jusho import Jusho, Address, City, Prefecture

postman = Jusho()

print(postman.by_zip_code('160-0021'))  # '1600021', '〒1600021' and whatever is valid
# [Address(id=116156, city=City(id=1972, prefecture=Prefecture(id=36, kanji='東京都', kana='トウキョウト', eng='TOKYO T...

print(postman.prefectures)
# [Prefecture(id=0, kanji='北海道', kana='ホッカイドウ', eng='HOKKAIDO'), Prefecture(id=3, kanji='青森県', kana='アオモリケ...

osaka: Prefecture = postman.search_prefectures('大阪', 'kanji')[0]
print(postman.cities(osaka))
# [City(id=3613, prefecture=Prefecture(id=78, kanji='大阪府', kana='オオサカフ', eng='OSAKA FU'), kanji='大阪市都島区', ka...

shimamoto: City = postman.search_cities('三島郡島本町', prefecture=osaka)[0]
print(postman.addresses(shimamoto))
# [Address(id=264932, city=City(id=3799, prefecture=Prefecture(id=78, kanji='大阪府', kana='オオサカフ', eng='OSAKA FU'), kanji='三島郡島本町', kana='ミシマグンシマモトチョウ', eng='MISHIMA ...

aoba: Address = postman.search_addresses('青葉', city=shimamoto)[0]
# `postman.search_addresses('青葉', prefecture=osaka)`, `postman.search_addresses('青葉')` are also valid
# but the result is not the same.
print(aoba.hyphen_zip)
# 618-0015

"""
Address object has a lot of info
"""

admin_division_code: str = aoba.admin_division_code  # 27301

old_zip_code: str = aoba.old_zip_code  # 618

zip_code: str = aoba.zip_code  # 6180015

prefecture: Prefecture = aoba.prefecture  # Prefecture(id=78, kanji='大阪府', kana='オオサカフ', eng='OSAKA FU')

city: City = aoba.city  # City(id=3799, prefecture=Prefecture(id=78, kanji='大阪府', kana='オオサカフ', eng='OSAKA FU'), kanji='三島郡島本町', kana='ミシマグンシマモトチョウ', eng='MISHIMA GUN SHIMAMOTO CHO')

print('\n'.join((
    aoba.kanji,  # 青葉
    aoba.kana,  # アオバ
    aoba.eng,  # AOBA
    '--------',
    aoba.concat_kanji,  # 大阪府 三島郡島本町 青葉
    aoba.concat_kana,  # オオサカフ ミシマグンシマモトチョウ アオバ
    aoba.concat_eng,  # Aoba, Mishima Gun Shimamoto Cho, Osaka Fu
    '--------',
    aoba.city.kanji,  # 三島郡島本町
    aoba.city.kana,  # ミシマグンシマモトチョウ
    aoba.city.eng,  # MISHIMA GUN SHIMAMOTO CHO
    '--------',
    aoba.city.concat_kanji,  # 大阪府 三島郡島本町
    aoba.city.concat_kana,  # オオサカフ ミシマグンシマモトチョウ
    aoba.city.concat_eng,  # Mishima Gun Shimamoto Cho, Osaka Fu
    '--------',
    aoba.prefecture.kanji,  # 大阪府
    aoba.prefecture.kana,  # オオサカフ
    aoba.prefecture.eng,  # OSAKA FU
)))

TroubleShooting

No database file found!

Database file is already included in the package.
But in case Jusho can't find the database file, you can download it with Jusho.create_database(path: str).

And then specify the path to the database file like Jusho(database_path='/path/to/database.db').

# data
data is from Japan Post
- https://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip
- https://www.post.japanpost.jp/zipcode/dl/roman/ken_all_rome.zip

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

jusho-1.0.1.tar.gz (5.5 MB view details)

Uploaded Source

Built Distribution

jusho-1.0.1-py3-none-any.whl (5.1 MB view details)

Uploaded Python 3

File details

Details for the file jusho-1.0.1.tar.gz.

File metadata

  • Download URL: jusho-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for jusho-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0963cf0b48f7065f20d683b78dca893f293db62a1461ea934fdc7b2defd52957
MD5 d541418d6c176ce8e7606d859fae03ea
BLAKE2b-256 8d8f605dcf1cd63635c6b93c0cd23f5cfe9a35bc060630e2189d6e614197d934

See more details on using hashes here.

File details

Details for the file jusho-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: jusho-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for jusho-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8f7230fa5607f840d89be7e5b1e9a7f41ff556354447695b1d336c2a2c30ad8
MD5 7214b6e254cf280bf7fda81fcbf66de2
BLAKE2b-256 ce52750669a78beba43ca72873761a18e5698720ad74a7f3f271beb1b61d83a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page