API Client

class routinepy.lib.api.client.ApiClient[source]

Client for fetching routine data using the BUBT routine APIs

Note

There are no public APIs provided by the university, I have to reverse engineer the official routine webpage to get the endpoints

async get_class_routine(semester_type: SemesterType = SemesterType.CURRENT, faculty_code: str = None, program_code: ProgramCode = None, room: str = None, intake: str = None, section: str = None, course_code: str = None) list[ClassPeriod][source]

Get class routine data based on provided filters

Shortcut for method get_routine() with automatically filled parameter:

  • routine_type=RoutineType.CLASS

Returns:

A list of ClassPeriod objects

Return type:

list[ClassPeriod]

async get_class_routine_update_info(semester_type: SemesterType = SemesterType.CURRENT) list[UpdateInfo] | None[source]

Get class routine update metadata.

Shortcut for method get_last_update() with automatically filled parameter:

  • routine_type=RoutineType.CLASS

Returns:

A list of UpdateInfo objects

Return type:

list[UpdateInfo]

async get_mid_routine(semester_type: SemesterType = SemesterType.CURRENT, faculty_code: str = None, program_code: ProgramCode = None, room: str = None, intake: str = None, section: str = None, course_code: str = None) list[TermExam][source]

Get mid-term routine data based on provided filters

Shortcut for method get_routine() with automatically filled parameter:

  • routine_type=RoutineType.MID

Returns:

A list of TermExam objects

Return type:

list[TermExam]

async get_mid_routine_update_info(semester_type: SemesterType = SemesterType.CURRENT) list[UpdateInfo] | None[source]

Get mid-term routine update metadata.

Shortcut for method get_last_update() with automatically filled parameter:

  • routine_type=RoutineType.MID

Returns:

A list of UpdateInfo objects

Return type:

list[UpdateInfo]

async get_final_routine(semester_type: SemesterType = SemesterType.CURRENT, faculty_code: str = None, program_code: ProgramCode = None, room: str = None, intake: str = None, section: str = None, course_code: str = None) list[TermExam][source]

Get final-term routine data based on provided filters

Shortcut for method get_routine() with automatically filled parameter:

  • routine_type=RoutineType.FINAL

Returns:

A list of TermExam objects

Return type:

list[TermExam]

async get_final_routine_update_info(semester_type: SemesterType = SemesterType.CURRENT) list[UpdateInfo] | None[source]

Get final-term routine update metadata.

Shortcut for method get_last_update() with automatically filled parameter:

  • routine_type=RoutineType.FINAL

Returns:

A list of UpdateInfo objects

Return type:

list[UpdateInfo]

async get_routine(routine_type: RoutineType, semester_type: SemesterType = SemesterType.CURRENT, faculty_code: str = None, program_code: ProgramCode = None, room: str = None, intake: str = None, section: str = None, course_code: str = None) List[ClassPeriod | TermExam | FacultyPeriod] | None[source]

Base method for getting routine data based on provided filters.

Parameters:
  • routine_type (RoutineType) – Type of routine (e.g., ‘class’, ‘mid’ )

  • semester_type (SemesterType, optional) – Type of semester (e.g., ‘past’, ‘present’ ) (required for class routine only), defaults to SemesterType.CURRENT

  • faculty_code (str, optional) – The faculty member code to filter by (e.g., ‘MDI’, ‘MAFI’ ), defaults to None

  • program_code (ProgramCode, optional) – The program code to filter by (e.g., ‘006’, ‘001’), defaults to None

  • room (str, optional) – The four digit room number to filter by (e.g., ‘2420’, ‘2709’), defaults to None

  • intake (str, optional) – The intake number to filter by (e.g., ‘49’, ‘50’), defaults to None

  • section (str, optional) – The section number to filter by (e.g., ‘1’, ‘2), defaults to None

  • course_code (str, optional) – The course code to filter by (e.g., ‘CSE 101’, ‘CSE 331’), defaults to None

Raises:

ValueError

If invalid or incompatible filter combinations are provided, such as:

  • Invalid routine_type, semester_type, or program_code (not matching their respective Enum values).

  • Neither program_code, faculty_code, nor room provided.

  • room not being a four-digit string.

  • section provided without intake.

  • Empty or malformed course_code.

Returns:

A list of routine objects or None if no data is found:

  • List[ClassPeriod] for routine_type=RoutineType.CLASS.

  • List[TermExam] for exam-related routine_type (e.g., RoutineType.MID).

  • List[FacultyPeriod] if faculty_code is provided.

Return type:

List[ClassPeriod | TermExam | FacultyPeriod] | None

Note

The room parameter is split into building and room number for the payload.

async get_last_update(sync_routine_type: SyncRoutineType, semester_type: SemesterType | None = SemesterType.CURRENT) list[UpdateInfo] | None[source]

Base method of getting update information of a routine.

Parameters:
  • sync_routine_type (SyncRoutineType) – Type of the routine to get information

  • semester_type (Optional[SemesterType], optional) – Type of the routine to get information, defaults to SemesterType.CURRENT

Returns:

Update information of a routine containing last modified and when created.

Return type:

list[UpdateInfo]

Example Output of Class Routine Update Metadata:

[
    UpdateInfo(
        id="4",
        routine="routine",
        semester="present",
        semseter_code="064",
        hash="cd16a548f98a4bc5214f77c5d751f860",
        minor_change="4",
        major_change="6",
        updated_at="2025-06-02 21:32:08",
        created_at="2024-09-24 11:07:19",
    ),
    UpdateInfo(
        id="3",
        routine="routine",
        semester="present",
        semseter_code="610",
        hash="822401605769ca575740327771176bbd",
        minor_change="2",
        major_change="7",
        updated_at="2025-06-02 17:15:08",
        created_at="2024-09-24 11:07:19",
    ),
]

Example

Basic Setup

First, initialize the API client:

from routinepy.lib import ApiClient

client = ApiClient()

Some Scenarios

  1. Department Routine - Get class routine for an entire department:

data = await client.get_class_routine(
   program_code=ProgramCode.CSE_Day
)
  1. Faculty Routine - Get class routine for a specific faculty member:

data = await client.get_class_routine(
   faculty_code="MDI"
)
  1. Intake Routine - Get class routine for a specific department intake:

data = await client.get_class_routine(
   program_code=ProgramCode.CSE_Day,
   intake="49"
)
  1. Mid-Term Routine - Get exam routine for a specific department intake:

data = await client.get_mid_routine(
   program_code=ProgramCode.CSE_Day,
   intake="49"
)