korail-py-SDK
Legal notice: This is an unofficial client, unaffiliated with KORAIL. Apache-2.0 covers material the maintainer can license; it grants no service-access or trademark rights. Vendor message data has separate rights, and no independent redistribution grant has been established. Read LEGAL.md, NOTICE, third-party notices and provenance before use or redistribution.
A synchronous Python client for the KORAIL protocol, organized around separate transport, protocol, service and model layers. Import the public client and models from korail_py_sdk.
Documentation · Architecture · Validation · Contributing · Legal notice
What it supports
| Area | Capabilities |
|---|---|
| Search | Direct and transfer schedules, pagination, continuation recovery, seat maps |
| Sessions | Authentication, cookies, configuration, device profiles and explicit proxies |
| Transactions | Reservations, cancellation, payment and refund operations |
| Resources | Account and ticket reads, travel products and airport limousine operations |
| Public API | 239 root exports, 86 public client methods and typed models |
Transaction methods can affect real tickets and money. Automated validation is offline; these capabilities are not a claim of current live-service acceptance.
Install
Install the korail-py-SDK distribution with Python 3.11 or newer:
python -m pip install korail-py-SDK
# Optional SOCKS proxy support:
python -m pip install 'korail-py-SDK[socks]'
The Python import name is korail_py_sdk.
Search example
from korail_py_sdk import KorailClient, TrainSearchQuery
with KorailClient() as client:
response = client.search_trains(TrainSearchQuery("서울", "부산", "20991230", "090000"))
for train in response.trains:
print(train.train_no, train.departure_time)
Replace the example date with a valid travel date. Executing this example sends a real schedule request; automated tests do not execute it.
Behavior that matters
- Every search obtains a fresh response; seat availability and transaction outcomes are never cached.
- Transaction requests are never retried automatically. Check uncertain outcomes through official channels before trying again.
- The default software declaration profile replaces diagnostic-only tokens; ordinary single-train reservations use the observed GET/query profile. See configuration and validation limits.
- Decode failures retain the whole response in
error.raw, with nested context inerror.parser_rawwhen available. Treat both as potentially sensitive. - Pagination detects repeated pages and preserves continuation metadata.
- Business rejection, malformed responses, session expiry and protocol-access rejection remain distinct.
- HTTP cookies have one owner; curl responses are adapted without a second decompression pass. Credential and payment fields are hidden from generated model representations.
Maintenance and recovery
Explicit maintenance/rate-limit responses (including HTTP 429/503) block subsequent requests to the same configured API origin. Two consecutive transport failures also open a cooldown. Defaults are 30 minutes, 1 hour, 2 hours, then 4 hours, plus up to 10% positive jitter; a longer server Retry-After takes precedence. Errors expose status_code, retry_after (seconds) and next_probe_at (UTC Unix timestamp) when available. Invalid strResult values raise KorailProtocolError and retain raw.
During cooldown, login, queue admission and ordinary API calls fail locally. Once the deadline passes, only a caller-requested get_service_status() may probe recovery, and only one probe can run at a time. A successful status response permits ordinary calls again; it does not prove that every login or transaction endpoint is healthy. The library starts no timer, worker or background traffic. Applications should schedule one status check at next_probe_at only while work is pending, then resume reads gradually. Never replay an ambiguous reservation/payment automatically.
For a single-process application, use the default in-memory policy with no database configuration. Clients in that process share cooldowns and recovery-probe exclusion. Restarting the process clears this state, so the next call may contact the server again.
from korail_py_sdk import KorailApiError, KorailClient
with KorailClient() as client:
try:
status = client.get_service_status()
except KorailApiError as error:
if error.next_probe_at is None:
raise
next_check_at = error.next_probe_at # Schedule; do not loop immediately.
SQLite remains an optional advanced setting for restart persistence or multiple processes: create a MaintenancePolicy(state_path="/app/data/korail-maintenance.sqlite3") from korail_py_sdk.maintenance and pass it as KorailClient(maintenance=policy). The parent directory must already exist on a local filesystem. The database stores only origins, counters, deadlines and probe leases, without credentials or response bodies; separate hosts need application-level coordination. Set probe_lease longer than your longest possible status request when customizing timeouts beyond the default 5-minute lease. Separate policy objects without state_path have independent state.
Queue transport errors no longer bypass admission to send the API request. Error retries check the remaining queue budget before sleeping or sending again, and there is no sleep after the final failure. Queue admission has a 300-second default budget; explicitly setting KorailConfig(netfunnel_wait_limit=None) restores unlimited normal queue waiting. The budget does not cancel an already-running HTTP request or delay token cleanup.
These are deliberate behavior corrections: raise_on_fail=False cannot bypass maintenance/rate-limit protection, and malformed result envelopes are rejected before later steps in a transaction. Account errors, application-update requirements and protocol-access rejections alone do not establish maintenance.
Architecture
src/
└── korail_py_sdk/
├── api/ Public client and convenience resources
├── services/ Authentication, search and transaction rules
├── protocol/ Request compilation and response decoding
├── transport/ HTTP, curl adaptation and queue admission
├── models/ Value objects, exceptions and type declarations
├── configuration/ Device and environment settings
├── security/ Password transformation and token serialization
├── messages/ Localized message lookup
└── resources/ Protocol contracts and vendor message data
See ARCHITECTURE.md for ownership boundaries and locations for behavioral changes. The package builds and runs from this repository.
Validation and performance
The test suite and decoder comparisons use synthetic data. See VALIDATION.md for the checks and their limits.
Offline benchmarks exercise mock transports and do not establish real KORAIL request latency or acceptance.
Development
.venv/bin/python -m pip install -e '.[dev]'
.venv/bin/python -m pytest
.venv/bin/ruff check .
.venv/bin/ruff format --check .
.venv/bin/mypy
.venv/bin/python -m build
.venv/bin/python -m twine check dist/*
.venv/bin/python tools/packaging/check_artifacts.py dist/*.whl --sdist dist/*.tar.gz
Tests block network traffic and use synthetic data. See CONTRIBUTING.md for repository-only checks, documentation builds and packaging boundaries. Do not include credentials, passenger data, payment details or unredacted responses in issues.
License and provenance
The maintainer-authored software is offered under Apache-2.0, subject to the scope and notices in LEGAL.md, NOTICE and THIRD_PARTY_NOTICES.md.
Material provenance is recorded in PROVENANCE.md. Third-party data, runtime dependencies, trademarks and service-access permissions retain their respective rights. No live login, reservation, cancellation, payment or refund has been used to validate this release.
Metadata
Release files for korail-py-SDK 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| korail_py_sdk-0.1.2.tar.gz | 500.2 kB | Without provenance | Details for korail_py_sdk-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| korail_py_sdk-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for korail_py_sdk-0.1.2-py3-none-any.whl |
Total release size: 993.1 kB
Release files / korail_py_sdk-0.1.2.tar.gz
| Download URL | korail_py_sdk-0.1.2.tar.gz |
|---|---|
| Size | 500.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bbb231fbe36438c6879daa144faa94e9a3cd1da2e4cee01e9f2cc45f1a9068a
|
|
BLAKE2b-256 checksum How to use checksums |
93c397fd289ab541c30438db8eff07fa06b98b16f96bc4ecdac4b733cd61ed36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / korail_py_sdk-0.1.2-py3-none-any.whl
| Download URL | korail_py_sdk-0.1.2-py3-none-any.whl |
|---|---|
| Size | 492.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc9a7a51ffcbb6c042ba4621e1ad93de8d1c577f49eef0e13eb20d45bca4e9e4
|
|
BLAKE2b-256 checksum How to use checksums |
dafb52464fcaadafb3f31aa2970d23ca62de3f6902a4cdf35f63c1a2b2dae775
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for korail-py-SDK 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.