Skip to main content

Unified Python API for Korean train (SRT, KTX/Korail) reservation

Project description

koreantrain

Unified Python API for Korean train reservation — supports both SRT and KTX (Korail) with a single interface.

Installation

pip install koreantrain

Usage

from koreantrain import SRTService, KorailService, Passenger

# SRT
srt = SRTService("id", "pw")
trains = srt.search("수서", "부산", "20260301", "140000", time_limit="200000")
reservation = srt.reserve(trains[0], passengers=[Passenger.adult(2)])
print(reservation)  # [SRT] 03월 01일, 수서~부산(14:00~16:30) 53700원(2석), 구입기한 ...

# Korail (KTX) — same interface
korail = KorailService("id", "pw", train_type="ktx")
trains = korail.search("서울", "부산", "20260301", "140000", time_limit="200000")
reservation = korail.reserve(trains[0], passengers=[Passenger.adult(2)])

# Cancel
srt.cancel(reservation)

Passenger Types

Passenger.adult(count=1)
Passenger.child(count=1)
Passenger.senior(count=1)
Passenger.toddler(count=1)  # Korail only

Seat Type

from koreantrain import SeatType

srt.reserve(train, seat_type=SeatType.SPECIAL_FIRST)
# GENERAL_FIRST (default), GENERAL_ONLY, SPECIAL_FIRST, SPECIAL_ONLY

Error Handling

from koreantrain import LoginError, SoldOutError, NetworkError, ReservationError

try:
    srt.reserve(train)
except SoldOutError:
    print("매진")
except LoginError:
    print("로그인 만료")
except NetworkError:
    print("네트워크 오류")

Dependencies

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

koreantrain-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

koreantrain-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file koreantrain-0.1.0.tar.gz.

File metadata

  • Download URL: koreantrain-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for koreantrain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a18c9b220d641a3bb105c53c2186bd4314e855633a228242b9048c6b49b5ca4c
MD5 2cd3002ff85bc46feb1189118326bb82
BLAKE2b-256 6b0f420c2ed9bf8220bb0cc072062a480fddf554c28cc46e5219eae86e9a4acf

See more details on using hashes here.

File details

Details for the file koreantrain-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: koreantrain-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for koreantrain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68545173cef8f97119f2294e426f67bfb4cd4c8ae78e0414a283653f03a24b0b
MD5 9da963ae82d9fe537ffdd11595ebd149
BLAKE2b-256 fb075b9b448a270bf112b0909c4f38bef087596a2da80d86da96b5b33a50afa1

See more details on using hashes here.

Supported by

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