API Reference

The following section outlines the API of pymyku.

Client

class pymyku.Client(username, password)

Bases: pymyku.type.ClientType

Represents a client connection that connects to MyKU. This class is used to interact with the MyKU API. The client is initialized with a username and password and will login to MyKU automatically.

property login_response

Recent login response.

Returns

Response from the login request. Represented by pymyku.attribute.FetchedResponses.LOGIN_RESPONSE

Return type

dict

property access_token

Recent access token from the login response.

Returns

Access token. Represented by pymyku.attribute.Token.ACCESS_TOKEN

Return type

str

property schedule_response

Recent schedule response.

Returns

Response from the schedule request. Represented by pymyku.attribute.FetchedResponses.SCHEDULE_RESPONSE

Return type

Response

property academic_year

Current academic year.

Returns

Current academic year. Represented by pymyku.attribute.Schedule.ACADEMIC_YEAR

Return type

Optional[str]

property semester

Current semester.

Returns

Current semester. Represented by pymyku.attribute.Schedule.SEMESTER

Return type

Optional[str]

property user_data

Return the user data extracted form login response.

Returns

User data. Represented by pymyku.attribute.User

Return type

dict

property student_data

Return the student data extracted form login response.

Returns

Student data. Represented by pymyku.attribute.Student

Return type

dict

property std_code

Return the student code extracted from the login response.

Returns

Student code. Represented by pymyku.attribute.Student.STD_CODE

Return type

str

valid_response(response, to_json=True)

If the response is not 200, check if the error is due to an expired token. If so, reset the token and raise an error. Otherwise, raise the error

Parameters
  • response (Response) – The response object returned from the request.

  • to_json (Optional[dict]) – If True, the response will be converted to a JSON object.

Returns

Return the response if the response is 200. Otherwise, raise the error.

Return type

Union[dict, Response]

Raises
initialize()

Initialize the client by logging in and fetch user data. login() will be called to fetch login data. After that, fetch_schedule() will be called to fetch schedule data.

Affected attributes: login_response, access_token, schedule_response, academic_year and semester

reset()

Reset the client attributes.

Affected attributes: login_response, access_token, schedule_response, academic_year and semester

headers()

Return the headers for the requests.

Returns

The headers for the requests containing pymyku.constant.APP_KEY and access_token.

Return type

dict

login()

Login to MyKu and fetch user data.

API: https://myapi.ku.th/auth/login

Returns

Response object from the login request. Represented by pymyku.attribute.FetchedResponses.LOGIN_RESPONSE

Return type

Response

fetch_schedule(as_response=False)

Send GET request to MyKU common/getschedule API.

API: https://myapi.ku.th/common/getschedule

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request. Represented by pymyku.attribute.FetchedResponses.SCHEDULE_RESPONSE

Return type

Union[dict, Response]

fetch_announce(academic_year=None, semester=None, as_response=False)

Send GET request to MyKU advisor/getAnnounceStd API.

API: https://myapi.ku.th/advisor/getAnnounceStd

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Return type

Union[List[dict], Response]

fetch_grades(as_response=False)

Send GET request to MyKU std-profile/checkGrades API.

API: https://myapi.ku.th/std-profile/checkGrades

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request.

Return type

Union[dict, Response]

fetch_group_course(as_response=False)

Send GET request to MyKU std-profile/getGroupCourse API.

API: https://myapi.ku.th/std-profile/getGroupCourse

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request.

Return type

Union[dict, Response]

fetch_student_address(as_response=False)

Send GET request to MyKU std-profile/getStdAddress API.

API: https://myapi.ku.th/std-profile/getStdAddress

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request.

Return type

Union[dict, Response]

fetch_student_personal(as_response=False)

Send GET request to MyKU std-profile/getStdPersonal API.

API: https://myapi.ku.th/std-profile/getStdPersonal

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Return type

Union[dict, Response]

fetch_student_education(as_response=False)

Send GET request to MyKU std-profile/getStdEducation API.

API: https://myapi.ku.th/std-profile/getStdEducation

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request.

Return type

Union[dict, Response]

fetch_gpax(as_response=False)

Send GET request to MyKU stddashboard/gpax API.

API: https://myapi.ku.th/stddashboard/gpax

Parameters

as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False

Returns

Response from the request.

Return type

Union[dict, Response]

fetch_enroll(academic_year=None, semester=None, as_response=False)

Send GET request to MyKU enroll/searchEnrollResult API.

API: https://myapi.ku.th/enroll/searchEnrollResult

Parameters
Returns

Response from the request.

Return type

Union[dict, Response]

search_subject(query)

Query subject with subject id by sending GET request to MyKU enroll/searchSubjectOpenEnr API.

API: https://myapi.ku.th/enroll/searchSubjectOpenEnr

Parameters

query (str) – Subject id or name to query. (At least 3 characters), e.g. ‘013’, ‘01355119’, ‘eng’ or ‘english’

Returns

List of subject dicts.

Return type

List[Dict[str, str]]

Raises
search_subject_open(subject_id, section='', campus_code='')

Query subject enrollment info (All section) of current semester by sending GET request to MyKU enroll/openSubjectForEnroll API.

API: https://myapi.ku.th/enroll/openSubjectForEnroll

Parameters
  • subject_id (str) – Subject id to query, e.g. ‘01355119’ or ‘01355119-64’

  • section (Optional[str]) – Section of the subject, e.g. ‘1’

  • campus_code (Optional[str]) – Campus code, ‘B’ for Bang Khen, ‘C’ for Sakolkorn, ‘I’ for affiliated institute, ‘K’ for Kamphaeng Saen, ‘P’ for Suphanburi.

Returns

List of subject’s opening section.

Return type

List[Dict[str, Union[str, int]]]

Raises
  • Value – The subject_id is less than 3 characters long.

  • exception.HTTPError – The request is not successful.

search_section_detail(subject_id)

Send GET request to MyKU enroll/searchSectionDetail API.

API: https://myapi.ku.th/enroll/searchSectionDetail

Parameters

section_id (str) – Section id. e.g. ‘186426’

Returns

_description_

Return type

Dict[str, Union[str, int]]

get(attr)

Get any value from MyKU client. (login response and schedule response) Use enums from pymyku.attribute as key to get value.

Parameters

attr (Enum) – Enum from attribute.

Returns

Value of the attribute.

Return type

Any

Raises

TypeError – The attr is not an Enum.

get_group_course()

Send GET request to MyKU std-profile/getGroupCourse API and return the result.

Returns

List of group course dicts (timetable).

Return type

List[dict]

Raises
get_gpax()

Send GET request to MyKU std-profile/getGPAX API and return the gpax.

Returns

GPAX.

Return type

float

Raises
get_total_credit()

Send GET request to MyKU std-profile/getTotalCredit API and return the total credit.

Returns

Total credit.

Return type

int

Raises
get_grades(key='subject_code')

Fetch grades for each subjects in all semesters.

Parameters

key (str) – Subject key from the response. Can be subject_code or subject_name_en. Otherwise, subject_code will be used. Defaults to “subject_code”.

Returns

Dict of grades for each subjects in all semesters.

Return type

Dict[str, Dict[str, str]]

Raises
get_enrolled_subjects(academic_year=None, semester=None)

Get enrolled subjects in a specific semester.

Parameters
Returns

List of enrolled subjects.

Return type

List[dict]

Requests

pymyku.requests.get(url, params=None, **kwargs)

Sends a GET request.

Parameters
  • url – URL for the new Request object.

  • params – (optional) Dictionary, list of tuples or bytes to send in the query string for the Request.

  • **kwargs – Optional arguments that request takes.

Returns

Response object

Return type

requests.Response

pymyku.requests.post(url, data=None, json=None, **kwargs)

Sends a POST request.

Parameters
  • url – URL for the new Request object.

  • data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.

  • json – (optional) A JSON serializable Python object to send in the body of the Request.

  • **kwargs – Optional arguments that request takes.

Returns

Response object

Return type

requests.Response

pymyku.requests.login(username, password)

Send POST request to MyKU auth/login API.

API: https://myapi.ku.th/auth/login

Parameters
  • username (str) – Your Nontri account username (b##########)

  • password (str) – Your password (Don’t worry, your password is not saved)

Returns

Response object from auth/login API.

Return type

Response

pymyku.requests.logout(access_token='', login_response={}, client=None)

Send POST request to MyKU auth/logout API.

I am uncertain that this request method will work properly.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/auth/logout

Parameters
Returns

Response object from auth/logout API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_schedule(access_token='', user_type='', campus_code='', faculty_code='', major_code='', student_status_code='', login_response={}, client=None)

Send GET request to MyKU common/getschedule API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/common/getschedule

Parameters
Returns

Response object from common/getschedule API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_group_course(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)

Send GET request to MyKU std-profile/getGroupCourse API.

Assigning only (login_response and schedule_response) or client is acceptable.

API: https://myapi.ku.th/std-profile/getGroupCourse

Parameters
Returns

Response object from std-profile/getGroupCourse API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_check_grades(access_token='', std_code='', login_response={}, client=None)

Send GET request to MyKU std-profile/checkGrades API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/std-profile/checkGrades

Parameters
Returns

Response object from std-profile/checkGrades API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_gpax(access_token='', std_id='', login_response={}, client=None)

Send GET request to MyKU stddashboard/gpax API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/stddashboard/gpax

Parameters
Returns

Response object from stddashboard/gpax API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_announce(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)

Send GET request to MyKU advisor/getAnnounceStd API.

Assigning only (login_response and schedule_response) or client is acceptable.

API: https://myapi.ku.th/advisor/getAnnounceStd

Parameters
Returns

Response object from advisor/getAnnounceStd API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.search_enroll(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)

Send GET request to MyKU enroll/searchEnrollResult API.

Assigning only (login_response and schedule_response) or client is acceptable.

API: https://myapi.ku.th/enroll/searchEnrollResult

Parameters
Returns

Response object from enroll/searchEnrollResult API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_student_personal(access_token='', std_id='', login_response={}, client=None)

Send GET request to MyKU std-profile/getStdPersonal API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/std-profile/getStdPersonal

Parameters
Returns

Response object from std-profile/getStdPersonal API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_student_education(access_token='', std_id='', login_response={}, client=None)

Send GET request to MyKU std-profile/getStdEducation API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/std-profile/getStdEducation

Parameters
Returns

Response object from std-profile/getStdEducation API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.get_student_address(access_token='', std_id='', login_response={}, client=None)

Send GET request to MyKU std-profile/getStdAddress API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/std-profile/getStdAddress

Parameters
Returns

Response object from std-profile/getStdAddress API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.search_subject(query, access_token='', login_response={}, client=None)

Send GET request to MyKU enroll/searchSubjectOpenEnr API.

Assigning only login_response or client is acceptable.

API: https://myapi.ku.th/enroll/searchSubjectOpenEnr

Parameters
Returns

Response object from enroll/searchSubjectOpenEnr API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.search_subject_open(query, section='', access_token='', campus_code='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)

Send GET request to MyKU enroll/openSubjectForEnroll API.

Assigning only (login_response and schedule_response) or client is acceptable.

API: https://myapi.ku.th/enroll/openSubjectForEnroll

Parameters
Returns

Response object from enroll/openSubjectForEnroll API.

Return type

Response

Raises

ValueError – Required parameters are missing.

pymyku.requests.search_section_detail(section_id, access_token='', login_response={}, client=None)

Send GET request to MyKU enroll/searchSectionDetail API.

API: https://myapi.ku.th/enroll/searchSectionDetail

Parameters
Returns

Response object from enroll/searchSectionDetail API.

Return type

Response

Raises

ValueError – Required parameters are missing.

Utilities

pymyku.utils.response_to_json(response)

Convert response to json. Do nothing if response is already dictionary

Parameters

response (Union[Response, dict]) – The response to convert.

Returns

Dictionary representation of the response.

Return type

dict

Raises

TypeError – Invalid response type.

pymyku.utils.extract(response, attr)

Extract any value from login response or schedule response. Use enums from pymyku.attribute as key to get value.

Parameters
  • response (Union[Response, dict]) – The response to extract from. (Can be login response or schedule response)

  • attr (Enum) – The attribute to extract.

Returns

Value of the attribute.

Return type

Any

Raises

TypeError – Invalid attr type.

pymyku.utils.get_raise(dictionary, key, dict_name=None)

Raise ValueError if key is not found in dictionary.

Parameters
  • dictionary (dict) – The dictionary to search in.

  • key (str) – The key to search for.

  • dict_name (Optional[str]) – Name of the dictionary.

Returns

Value of the key.

Return type

Any

Raises

ValueError – If key is not found in dictionary.

pymyku.utils.extract_user_data(login_response)

Extract user data from login response.

Parameters

login_response (Union[Response, dict]) – The response of the login request.

Returns

User data. Represented by pymyku.attribute.User

Return type

dict

Raises

ValueError – If user data is not found.

pymyku.utils.extract_student_data(login_response)

Extract student data from login response.

Parameters

login_response (Union[Response, dict]) – The response of the login request.

Returns

Student data. Represented by pymyku.attribute.Student

Return type

dict

Raises

ValueError – If student data is not found.

pymyku.utils.extract_access_token(login_response)

Extract student code from login response

Parameters

login_response (Union[Response, dict]) – This is the response from the login request.

Returns

Access token. Represented by pymyku.attribute.Token.ACCESS_TOKEN

Return type

str

Raises

ValueError – If access token is not found.

pymyku.utils.extract_std_code(login_response)

Extract student code from login response

Parameters

login_response (Union[Response, dict]) – The response of the login request.

Returns

Student code. Represented by pymyku.attribute.Student.STD_CODE

Return type

str

pymyku.utils.extract_std_id(login_response)

Extract student id from login response.

Parameters

login_response (Union[Response, dict]) – The response of the login request.

Returns

Student id. Represented by pymyku.attribute.Student.STD_ID

Return type

str

pymyku.utils.extract_schedule(schedule_response, as_dict=False, full_result=False)

Extract academic_year and semester from schedule response.

Parameters
  • schedule_response (Union[Response, dict]) – The response from the schedule request.

  • as_dict (Optional[bool]) – Whether to return the result as a dictionary or not. By default False

  • full_result (Optional[bool]) – If True, return the full result (List[dict]), otherwise return the first item. By default False

Returns

Academic year and semester. Represented by pymyku.attribute.Schedule.ACADEMIC_YEAR and pymyku.attribute.Schedule.SEMESTER

Return type

Union[tuple, dict, list]

pymyku.utils.gen_request_headers(access_token='')

Generate request headers.

Sets the access token as x-access-token if provided.

Parameters

access_token (Optional[Union[str, Response, dict]]) – If the parameter is type Response or dict, the access token will be extracted. Represented by pymyku.attribute.Token.ACCESS_TOKEN

Returns

Request headers for MyKU API.

Return type

dict

pymyku.utils.gen_login_request_params(username, password)

Generate request parameters for posting login request.

Parameters
  • username (str) – Nontri account username (b##########)

  • password (str) – Nontri account password (Don’t worry, your password is not saved)

Returns

Parameters for login request.

Return type

dict

pymyku.utils.gen_request_args_f(function, raise_exception=True, **kwargs)

Generate request parameters requied for the given function.

Passing only login_response, schedule_response or client is also acceptable for some request parameters.

Parameters
  • function (callable) – Any request function from pymyku.request module.

  • raise_exception (Optional[bool]) – Whether to raise exception or not, by default True

Returns

Request parameters.

Return type

Dict[str, any]

Raises

ValueError – If required kwargs are not present.

pymyku.utils.encrypt(message)

Encrypt a message using the public key.

Parameters

message (str) – The message to encrypt.

Returns

The encrypted message.

Return type

str

Response attributes

class pymyku.attribute.User(value)

Enum representation for user data in login response. Login response can be obtained by calling pymyku.requests.login() or getting from client property pymyku.Client.login_response

LOGIN_NAME = 'loginName'

A representation for loginName from user data in login response.

USER_TYPE = 'userType'

A representation for userType from user data in login response.

ID_CODE = 'idCode'

A representation for idCode from user data in login response.

TITLE_TH = 'titleTh'

A representation for titleTh from user data in login response.

TITLE_EN = 'titleEn'

A representation for titleEn from user data in login response.

FIRST_NAME_TH = 'firstNameTh'

A representation for firstNameTh from user data in login response.

FIRST_NAME_EN = 'firstNameEn'

A representation for firstNameEn from user data in login response.

MIDDLE_NAME_TH = 'middleNameTh'

A representation for middleNameTh from user data in login response.

MIDDLE_NAME_EN = 'middleNameEn'

A representation for middleNameEn from user data in login response.

LAST_NAME_TH = 'lastNameTh'

A representation for lastNameTh from user data in login response.

LAST_NAME_EN = 'lastNameEn'

A representation for lastNameEn from user data in login response.

AVATAR = 'avatar'

A representation for avatar from user data in login response.

GENDER = 'gender'

A representation for gender from user data in login response.

class pymyku.attribute.Student(value)

Enum representation for student data in login response. Login response can be obtained by calling pymyku.requests.login() or getting from client property pymyku.Client.login_response

STD_ID = 'stdId'

A representation for stdId from student data in login response.

STD_CODE = 'stdCode'

A representation for stdCode from student data in login response.

COPEN_ID = 'copenId'

A representation for copenId from student data in login response.

COPEN_NAME_TH = 'copenNameTh'

A representation for copenNameTh from student data in login response.

COPEN_NAME_EN = 'copenNameEn'

A representation for copenNameEn from student data in login response.

CAMPUS_CODE = 'campusCode'

A representation for campusCode from student data in login response.

CAMPUS_NAME_TH = 'campusNameTh'

A representation for campusNameTh from student data in login response.

CAMPUS_NAME_EN = 'campusNameEn'

A representation for campusNameEn from student data in login response.

FACULTY_CODE = 'facultyCode'

A representation for facultyCode from student data in login response.

FACULTY_NAME_TH = 'facultyNameTh'

A representation for facultyNameTh from student data in login response.

FACULTY_NAME_EN = 'facultyNameEn'

A representation for facultyNameEn from student data in login response.

DEPARTMENT_CODE = 'departmentCode'

A representation for departmentCode from student data in login response.

DEPARTMENT_NAME_TH = 'departmentNameTh'

A representation for departmentNameTh from student data in login response.

DEPARTMENT_NAME_EN = 'departmentNameEn'

A representation for departmentNameEn from student data in login response.

MAJOR_CODE = 'majorCode'

A representation for majorCode from student data in login response.

MAJOR_NAME_TH = 'majorNameTh'

A representation for majorNameTh from student data in login response.

MAJOR_NAME_EN = 'majorNameEn'

A representation for majorNameEn from student data in login response.

NATION_CODE = 'nationCode'

A representation for nationCode from student data in login response.

NATIONALITY_NAME_TH = 'nationalityNameTh'

A representation for nationalityNameTh from student data in login response.

NATIONALITY_NAME_EN = 'nationalityNameEn'

A representation for nationalityNameEn from student data in login response.

STUDENT_STATUS_CODE = 'studentStatusCode'

A representation for studentStatusCode from student data in login response.

STUDENT_STATUS_NAME_TH = 'studentStatusNameTh'

A representation for studentStatusNameTh from student data in login response.

STUDENT_STATUS_NAME_EN = 'studentStatusNameEn'

A representation for studentStatusNameEn from student data in login response.

STUDENT_TYPE_CODE = 'studentTypeCode'

A representation for studentTypeCode from student data in login response.

STUDENT_TYPE_NAME_TH = 'studentTypeNameTh'

A representation for studentTypeNameTh from student data in login response.

STUDENT_TYPE_NAME_EN = 'studentTypeNameEn'

A representation for studentTypeNameEn from student data in login response.

EDULEVEL_CODE = 'edulevelCode'

A representation for edulevelCode from student data in login response.

EDULEVEL_NAME_TH = 'edulevelNameTh'

A representation for edulevelNameTh from student data in login response.

EDULEVEL_NAME_EN = 'edulevelNameEn'

A representation for edulevelNameEn from student data in login response.

STUDENT_YEAR = 'studentYear'

A representation for studentYear from student data in login response.

ADVISOR_ID = 'advisorId'

A representation for advisorId from student data in login response.

ADVISOR_NAME_TH = 'advisorNameTh'

A representation for advisorNameTh from student data in login response.

ADVISOR_NAME_EN = 'advisorNameEn'

A representation for advisorNameEn from student data in login response.

POSITION_TH = 'positionTh'

A representation for positionTh from student data in login response.

EMAIL = 'email'

A representation for email from student data in login response.

MOBILE_NO = 'mobileNo'

A representation for mobileNo from student data in login response.

class pymyku.attribute.Token(value)

Enum representation for tokens in login response. Login response can be obtained by calling pymyku.requests.login() or getting from client property pymyku.Client.login_response

ACCESS_TOKEN = 'accesstoken'

A representation for accessToken from login response.

RENEW_TOKEN = 'renewtoken'

A representation for refreshToken from login response.

class pymyku.attribute.Schedule(value)

Enum representation for schedule data in schedule response Schedule response can be obtained by calling pymyku.requests.get_schedule() or getting from client property pymyku.Client.schedule_response

ACADEMIC_YEAR = 'academicYr'

A representation for scheduleId from schedule response.

SEMESTER = 'semester'

A representation for semester from schedule response.

class pymyku.attribute.FetchedResponses(value)

Enum representation for fetched responses in client object

LOGIN_RESPONSE = 0

A representation for login response in pymyku.Client. Login response can be obtained by getting from client property pymyku.Client.login_response

SCHEDULE_RESPONSE = 1

A representation for schedule response in pymyku.Client. Schedule response can be obtained by getting from client property pymyku.Client.schedule_response

Types

class pymyku.type.Enum(value)

Generic enumeration.

Derive from this class to define new enumerations.

name

The name of the Enum member.

value

The value of the Enum member.

class pymyku.type.EnumMeta(cls, bases, classdict)

Metaclass for Enum

class pymyku.type.Response

The Response object, which contains a server’s response to an HTTP request.

status_code

Integer Code of responded HTTP Status, e.g. 404 or 200.

headers

Case-insensitive Dictionary of Response Headers. For example, headers['content-encoding'] will return the value of a 'Content-Encoding' response header.

raw

File-like object representation of response (for advanced usage). Use of raw requires that stream=True be set on the request. This requirement does not apply for use internally to Requests.

url

Final URL location of Response.

encoding

Encoding to decode with when accessing r.text.

history

A list of Response objects from the history of the Request. Any redirect responses will end up here. The list is sorted from the oldest to the most recent request.

reason

Textual reason of responded HTTP Status, e.g. “Not Found” or “OK”.

cookies

A CookieJar of Cookies the server sent back.

elapsed

The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the stream keyword argument.

request

The PreparedRequest object to which this is a response.

property ok

Returns True if status_code is less than 400, False if not.

This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code is between 200 and 400, this will return True. This is not a check to see if the response code is 200 OK.

property is_redirect

True if this Response is a well-formed HTTP redirect that could have been processed automatically (by Session.resolve_redirects()).

property is_permanent_redirect

True if this Response one of the permanent versions of redirect.

property next

Returns a PreparedRequest for the next request in a redirect chain, if there is one.

property apparent_encoding

The apparent encoding, provided by the charset_normalizer or chardet libraries.

iter_content(chunk_size=1, decode_unicode=False)

Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.

chunk_size must be of type int or None. A value of None will function differently depending on the value of stream. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk.

If decode_unicode is True, content will be decoded using the best available encoding based on the response.

for ... in iter_lines(chunk_size=512, decode_unicode=False, delimiter=None)

Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.

Note

This method is not reentrant safe.

property content

Content of the response, in bytes.

property text

Content of the response, in unicode.

If Response.encoding is None, encoding will be guessed using charset_normalizer or chardet.

The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set r.encoding appropriately before accessing this property.

json(**kwargs)

Returns the json-encoded content of a response, if any.

Parameters

**kwargs – Optional arguments that json.loads takes.

Raises

requests.exceptions.JSONDecodeError – If the response body does not contain valid json.

Returns the parsed header links of the response, if any.

raise_for_status()

Raises HTTPError, if one occurred.

close()

Releases the connection back to the pool. Once this method has been called the underlying raw object must not be accessed again.

Note: Should not normally need to be called explicitly.

class pymyku.type.ClientType

Abstract class for client

URLs

See also: API Responses

pymyku.url.LOGIN = 'https://myapi.ku.th/auth/login'

API for logging in to MyKU. API response – url.LOGIN

pymyku.url.LOGOUT = 'https://myapi.ku.th/auth/logout'

API for logging out from MyKU (unsure if this works). API response – url.LOGOUT

pymyku.url.SCHEDULE = 'https://myapi.ku.th/common/getschedule'

API for getting schedule data that contains academic year and semester. API response – url.SCHEDULE

pymyku.url.ANNOUNCE = 'https://myapi.ku.th/advisor/getAnnounceStd'

API for getting announcement data. API response – url.ANNOUNCE

pymyku.url.CHECK_GRADES = 'https://myapi.ku.th/std-profile/checkGrades'

API for getting grades for each semester. API response – url.CHECK_GRADES

pymyku.url.GROUP_COURSE = 'https://myapi.ku.th/std-profile/getGroupCourse'

API for getting group course. API response – url.GROUP_COURSE

pymyku.url.STUDENT_ADDRESS = 'https://myapi.ku.th/std-profile/getStdAddress'

API for getting student address information. API response – url.STUDENT_ADDRESS

pymyku.url.STUDENT_PERSONAL = 'https://myapi.ku.th/std-profile/getStdPersonal'

API for getting student personal information. API response – url.STUDENT_PERSONAL

pymyku.url.STUDENT_EDUCATION = 'https://myapi.ku.th/std-profile/getStdEducation'

API for getting student academic information. API response – url.STUDENT_EDUCATION

pymyku.url.GPAX = 'https://myapi.ku.th/stddashboard/gpax'

API for getting gpx. API response – url.GPAX

pymyku.url.SEARCH_ENROLL = 'https://myapi.ku.th/enroll/searchEnrollResult'

API for getting student enrollment data. API response – url.SEARCH_ENROLL

pymyku.url.SEARCH_SUBJECT = 'https://myapi.ku.th/enroll/searchSubjectOpenEnr'

API for searching subject by subject code. API response – url.SEARCH_SUBJECT

pymyku.url.SEARCH_SUBJECT_OPEN = 'https://myapi.ku.th/enroll/openSubjectForEnroll'

API for searching opening subject by subject code. API response – url.SEARCH_SUBJECT_OPEN

pymyku.url.SEARCH_SECTION_DETAIL = 'https://myapi.ku.th/enroll/searchSectionDetail'

API for getting section detail by section id. API response – url.SEARCH_SECTION_DETAIL

Exceptions

exception pymyku.exception.HTTPError(*args, **kwargs)

An HTTP error occurred.

exception pymyku.exception.TokenExpired(*args, **kwargs)

The access token has expired.

Constants

pymyku.constant.APP_KEY = 'txCR5732xYYWDGdd49M3R19o1OVwdRFc'

MyKU app key.

pymyku.constant.STUDENT_PARAM_NAMES = ('std_id', 'std_code', 'campus_code', 'faculty_code', 'major_code', 'student_status_code', 'student_year')

Key in student data from login response (snake case).

pymyku.constant.STUDENT_PARAM_RES_NAMES = ('stdId', 'stdCode', 'campusCode', 'facultyCode', 'majorCode', 'studentStatusCode', 'studentYear')

Key in student data from login response (actual).

pymyku.constant.STUDENT_PARAM_DICT = {'campus_code': 'campusCode', 'faculty_code': 'facultyCode', 'major_code': 'majorCode', 'std_code': 'stdCode', 'std_id': 'stdId', 'student_status_code': 'studentStatusCode', 'student_year': 'studentYear'}

Dictionary to convert snake case student param to actual name.