Skip to main content

Your gateway to real-time Indian Railways data powered by NTES.

Project description

RailSutra


Railsutra is a lightweight Python package that provides Indian Railways information using pandas. It fetches data from the National Train Enquiry System (NTES) which allows you to make necessary railway related queries easily.

Features

  • Get trains running between two stations directly as Pandas DataFrame.
  • Flexible station matching when searching for trains.
  • Fully compatible with pandas for easy data analysis.

Installation

Install via pip:

pip install railsutra

Functions

1. get_stn_name(stn_code: str) -> str

Get the full station name for a given station code.

from railsutra import *
station = get_stn_name(stn_code='LKO') # lower-case allowed
print(station)
LUCKNOW JN.

2. get_trains_btw_stns(from_stn: str, to_stn: str, flex_stn:bool = False) -> pandas.DataFrame

Fetch all trains running between two stations. Returns a pandas DataFrame with train details.

  • from_stn : From station code.
  • to_stn : To station code.
  • flex_stn (optional) : Set True to allow flexible station matching.
import pandas as pd
from railsutra import *

# following to be done for full DataFrame view.
pd.set_option('display.max_rows',None)
pd.set_option('display.max_columns',None)
pd.set_option('display.width',None)

dtf = get_trains_btw_stns('GKP','LJN',flex_stn=True)
print(dtf)
  train_no      train_name service_days    train_type src_time   src_station src_code dest_time dest_station dest_code duration             classes
0    12203  GARIB RATH EXP  Mon,Tue,Fri    Garib Rath    00:45  Gorakhpur Jn      GKP     05:55  Lucknow Jn.       LKO    05:10                  3E
1    15114    CPR GTNR EXP        Daily  Mail Express    01:20  Gorakhpur Jn      GKP     06:35  Gomti Nagar      GTNR    05:15  1A,2A,3A,3E,SL,GEN

3. get_live_stn(stn_code: str) -> pandas.DataFrame

Get live arrivals and departures for a station. Returns a Pandas DataFrame showing train number, train name, arrival time, departure time, platform, and delay info (if available).

  • stn_code : Station Code.
from railsutra import get_live_stn
import pandas as pd

# following to be done for full DataFrame view.
pd.set_option('display.max_rows',None)
pd.set_option('display.max_columns',None)
pd.set_option('display.width',None)

dtf = get_live_stn(stn_code='cnb')
print(dtf.head(3))
  train_no         train_name   src  dest sch_arr exp_arr arr_delay sch_dep exp_dep dep_delay pf
0    55346  KSJ-LJN PASSENGER   KSJ   LJN   22:05   22:06         1   22:10   22:10       NaN  9
1    15658    BRAHMAPUTRA EXP   KYQ   DLI   21:30   22:17        47   21:35   22:18        43  2
2    12397      MAHABODHI EXP  GAYA  NDLS   22:05   22:18        13   22:10   22:19         9  2

4. get_train_name(train_no: str) -> str

Returns the name of the train.

from railsutra import get_train_name
train_name = get_train_name(train_no=13010)
print(train_name)
DOON EXPRESS

5. get_train_live_status(train_no, date: str, run_df: bool = False) -> dict

Fetches and returns the status of the train in dictionary format.

  • train_no : 5 digit train number.
  • date : Date for which status is required (dd-mm-yyyy).
  • run_df : set True if you want a Pandas DataFrame showing the whole running.
1. Getting status of the train.
from railsutra import get_train_live_status
import pandas as pd

status_dict = get_train_live_status(train_no=12231,date="04-09-2025",run_df=True)
print(status_dict['status']) # for status
Train has reached destination CHANDIGARH (CDG) at 10:13 05-Sep-2025.
2. Whole running DataFrame.
from railsutra import get_train_live_status
import pandas as pd

pd.set_option('display.max_rows',None)
pd.set_option('display.max_columns',None)
pd.set_option('display.width',None)

status_dict = get_train_live_status(train_no=15031,date="04-09-2025",run_df=True)
print(status_dict['running']) # for whole running DataFrame
        stn_name sch_arr      sch_dep exp_arr_time exp_arr_dt arr_delay exp_dep_time exp_dep_dt dep_delay
0   GORAKHPUR JN  Source        05:45       Source        NaN       NaN        05:45     04 Sep       NaN
1       SAHJANWA   06:08        06:10        06:09     04 Sep         1        06:11     04 Sep         1
2     KHALILABAD   06:25        06:27        06:28     04 Sep         3        06:35     04 Sep         8
3          BASTI   06:48        06:50        07:02     04 Sep        14        07:05     04 Sep        15
4        BABHNAN   07:15        07:17        07:28     04 Sep        13        07:31     04 Sep        14
5    MANKAPUR JN   07:44        07:46        08:00     04 Sep        16        08:02     04 Sep        16
6       GONDA JN   08:20        08:23        08:46     04 Sep        26        08:54     04 Sep        31
7    COLONELGANJ   08:48        08:50        09:23     04 Sep        35        09:25     04 Sep        35
8   BARABANKI JN   10:08        10:10        10:34     04 Sep        26        10:36     04 Sep        26
9   BADSHAHNAGAR   10:44        10:46        11:09     04 Sep        25        11:12     04 Sep        26
10    LUCKNOW NE   11:25  Destination        11:34     04 Sep         9  Destination        NaN       NaN

Notes

  • RailSutra uses NTES - National Train Enquiry System data. Schedules and status directly gets updated.
  • This package uses Internet Connectivity for fetching data, in absence of which will always return Empty DataFrames.

License

This project is licensed under the MIT License - see the LICENSE file in this distribution for details.

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

railsutra-0.2.8.tar.gz (144.1 kB view details)

Uploaded Source

Built Distribution

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

railsutra-0.2.8-py3-none-any.whl (143.1 kB view details)

Uploaded Python 3

File details

Details for the file railsutra-0.2.8.tar.gz.

File metadata

  • Download URL: railsutra-0.2.8.tar.gz
  • Upload date:
  • Size: 144.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for railsutra-0.2.8.tar.gz
Algorithm Hash digest
SHA256 d8f8291ebf852611bbe3ec4fce6cd2a059306dcb8f3bf66c4858f44659bbb7d7
MD5 ace85fa01f2c3447620ab757a513e685
BLAKE2b-256 be888b5fad8e3643ebc577dfa6c2f53e1f6d89518d1b6ca0093167fd6ff4300f

See more details on using hashes here.

File details

Details for the file railsutra-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: railsutra-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 143.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for railsutra-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 37c6f6ac3e7595ea25be03aa2042020c481b8141f1c93c0c1a860898e54f720a
MD5 8e126f9cff9f53100dd84a8d5ff69e30
BLAKE2b-256 827480dac5f67b9822c1f09e5c17270fdabbf8d1e83d0d851736a19e179a994f

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