Skip to main content

keihan_tracker

PyPI Python Test Typed License: MIT

京阪電車の列車位置・遅れ・ダイヤと、京阪バスの接近情報を Python で扱う非公式ライブラリです。

同期・非同期どちらでも / 型ヒントつき / 通信なしでテストできる層分け / 公式サイトに優しいレート制限つき

できること

機能 内容
🚃 列車の今 走っている列車の位置・種別・行先・遅れ
🪧 発車標 駅に「これから来る列車」を時刻順に
⏱️ 到着予測 遅れを加味して、駅に着く時刻を推定
🏁 先着 「〇〇には先着」のように、先に着く列車を調べる
🚌 京阪バス 接近情報(到着予定・遅れ)と、便ごとの時刻表

インストール

pip install keihan-tracker

Python 3.10 以上で動きます。

はじめての使い方

香里園に来る列車を5本表示します。

from keihan_tracker import KHTrackerSync

with KHTrackerSync() as tracker:
    tracker.fetch_pos()                    # 公式サイトから最新の情報を取る
    station = tracker.station("香里園")     # 駅番号 18 や "KH18" でも探せます

    for train, stop in station.upcoming_trains[:5]:
        when = stop.time.strftime("%H:%M") if stop.time else "--:--"   # ダイヤが乱れると時刻が分からないことがある
        print(when, train.train_type.value, train.destination)
21:27 準急 淀屋橋
21:27 準急 出町柳
21:39 準急 出町柳
...

async で書くなら KHTracker を使います。

import asyncio
from keihan_tracker import KHTracker

async def main():
    async with KHTracker() as tracker:
        await tracker.fetch_pos()
        for train in tracker.find_trains(active=True, min_delay=5):
            print(train.train_number, train.train_type.value, f"{train.delay_minutes}分遅れ")

asyncio.run(main())

バスも同じように取れます。

from keihan_tracker import BusClient

async def main():
    async with BusClient() as client:
        for bus in await client.arrivals("京阪香里園", 1):   # バス停名と、のりば番号
            print(bus.route, bus.destination, bus.expected or bus.scheduled, bus.status.value)

もっと知りたいとき

知りたいこと 読むもの
定期的に取り続ける・到着予測・バス・同期版と非同期版 使い方
つまずきやすい点・公式データの癖 使い方の「注意点」
クラスごとの属性とメソッド リファレンス
値がどこまで正確か(公式の値か推定か) 信頼性
v2 から書き換える 移行ガイド

公式サイトへの負荷について

  • 列車位置の取得は30秒に1回までに制限しています(公式の位置情報は1分ごとにしか変わりません)。
  • User-Agent で keihan_tracker と名乗ってアクセスします。
  • 取得先と頻度は使い方の「取得先と負荷への配慮」にあります。

関連プロジェクト

ライセンス

MIT License © 2026 dk-butsuri

Metadata

Release files for keihan-tracker 3.0.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 keihan-tracker 3.0.0
File Size Uploaded Provenance Actions
keihan_tracker-3.0.0.tar.gz 88.0 kB With provenance Details for keihan_tracker-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keihan-tracker 3.0.0
File Interpreter ABI Platform Actions
keihan_tracker-3.0.0-py3-none-any.whl Python 3 none any Details for keihan_tracker-3.0.0-py3-none-any.whl

Total release size: 140.3 kB

Release files / keihan_tracker-3.0.0.tar.gz

Download URL keihan_tracker-3.0.0.tar.gz
Size 88.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ca7cc8d6a959cd738fcef0187168159754fc33b29adb15e41efe4a9bc44c8cc9
BLAKE2b-256 checksum
How to use checksums
169b72b24e61551530e412640d07cbad1fed3f59510454822057480c81d952a3
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 Nov 14, 2026.

Transparency log

Release files / keihan_tracker-3.0.0-py3-none-any.whl

Download URL keihan_tracker-3.0.0-py3-none-any.whl
Size 52.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5d580cca406b4d4b8f08a91715801ba791fb2539f5bfc0ed002eb815601db9f
BLAKE2b-256 checksum
How to use checksums
b03293c31942d2d45d0819ad4991f8cb09e735e954d1e7e74a5aacad4c8967a9
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 Nov 14, 2026.

Transparency log

Security for keihan-tracker 3.0.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for keihan_tracker-3.0.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 Nov 14, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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