ut_course_catalog package

Top-level package for ut-course-catalog.

class ut_course_catalog.ClassForm(value)[source]

Bases: enum.Enum

An enumeration.

その他 = 'Z'
卒業論文 = 'T'
実習 = 'P'
実験 = 'E'
演習 = 'S'
講義 = 'L'
class ut_course_catalog.CommonCode[source]

Bases: str

property class_form: ut_course_catalog.ja.ClassForm
property department_code: str
property department_name: str
property faculty: ut_course_catalog.ja.Faculty
property institution: ut_course_catalog.ja.Institution
property language: ut_course_catalog.common.Language
property large_category: str
property level: str
property middle_category: str
static parse_department(faculty: ut_course_catalog.ja.Faculty, department_code: str)[source]
property reference_number: str
property small_category: str
class ut_course_catalog.Details(時間割コード: str, 共通科目コード: CommonCode, コース名: str, 教員: str, 学期: set[Semester], 曜限: set[tuple[Weekday, int]], ねらい: str, 教室: str, 単位数: Decimal, 他学部履修可: bool, 講義使用言語: str, 実務経験のある教員による授業科目: bool, 開講所属: Faculty, 授業計画: Optional[str], 授業の方法: Optional[str], 成績評価方法: Optional[str], 教科書: Optional[str], 参考書: Optional[str], 履修上の注意: Optional[str])[source]

Bases: tuple

Details of a course. Contains all available information for a course on the website. (UTAS may have more information)

property ねらい

Alias for field number 6

property コース名

Alias for field number 2

property 他学部履修可

Alias for field number 9

property 共通科目コード

Alias for field number 1

property 単位数

Alias for field number 8

property 参考書

Alias for field number 17

property 学期

Alias for field number 4

property 実務経験のある教員による授業科目

Alias for field number 11

property 履修上の注意

Alias for field number 18

property 成績評価方法

Alias for field number 15

property 授業の方法

Alias for field number 14

property 授業計画

Alias for field number 13

property 教員

Alias for field number 3

property 教室

Alias for field number 7

property 教科書

Alias for field number 16

property 時間割コード

Alias for field number 0

property 曜限

Alias for field number 5

property 講義使用言語

Alias for field number 10

property 開講所属

Alias for field number 12

class ut_course_catalog.Faculty(value)[source]

Bases: enum.Enum

Faculty in the University of Tokyo.

classmethod value_of(value) Faculty[source]

Converts a commonly used expression in the website to a Faculty enum value.

人文社会系研究科 = 11
公共政策学教育部 = 25
医学系研究科 = 19
医学部 = 2
学際情報学府 = 24
工学系研究科 = 17
工学部 = 3
情報理工学系研究科 = 23
教育学研究科 = 12
教育学部 = 9
教養学部 = 8
教養学部前期課程 = 26
数理科学研究科 = 21
文学部 = 4
新領域創成科学研究科 = 22
法学政治学研究科 = 13
法学部 = 1
理学系研究科 = 16
理学部 = 5
経済学研究科 = 14
経済学部 = 7
総合文化研究科 = 15
薬学系研究科 = 20
薬学部 = 10
農学生命科学研究科 = 18
農学部 = 6
class ut_course_catalog.Institution(value)[source]

Bases: enum.Enum

Institution in the University of Tokyo.

All = 'all'
大学院 = 'g'

Graduate

学部前期課程 = 'jd'

Junior Division

学部後期課程 = 'ug'

Senior Division

class ut_course_catalog.Language(value)[source]

Bases: enum.Enum

Language of a course.

English = 'en'
Japanese = 'ja'
JapaneseAndEnglish = 'ja,en'
OnlyOtherLanguages = 'only_other'
OtherLanguagesToo = 'other'
Others = 'others'
class ut_course_catalog.SearchParams(keyword: Optional[str] = None, 課程: ut_course_catalog.ja.Institution = Institution.All, 開講所属: Optional[ut_course_catalog.ja.Faculty] = None, 学年: Optional[Union[Iterable[int], int]] = None, 学期: Optional[Union[Iterable[ut_course_catalog.common.Semester], ut_course_catalog.common.Semester]] = None, 曜日: Optional[Union[Iterable[ut_course_catalog.common.Weekday], ut_course_catalog.common.Weekday]] = None, 時限: Optional[Union[Iterable[int], int]] = None, 講義使用言語: Optional[Union[Iterable[str], str]] = None, 横断型教育プログラム: Optional[Union[Iterable[str], str]] = None, 実務経験のある教員による授業科目: Optional[Union[Iterable[bool], bool]] = None, 分野_NDC: Optional[Union[Iterable[str], str]] = None)[source]

Bases: object

Search query parameters.

id() str[source]
keyword: Optional[str] = None
分野_NDC: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

学年: Optional[Union[Iterable[int], int]] = None

AND search, not OR.

学期: Optional[Union[Iterable[ut_course_catalog.common.Semester], ut_course_catalog.common.Semester]] = None

AND search, not OR.

実務経験のある教員による授業科目: Optional[Union[Iterable[bool], bool]] = None

AND search, not OR. Do not specify [True, False] though it is valid.

時限: Optional[Union[Iterable[int], int]] = None

AND search, not OR. Few courses have multiple periods.

曜日: Optional[Union[Iterable[ut_course_catalog.common.Weekday], ut_course_catalog.common.Weekday]] = None

AND search, not OR. Few courses have multiple periods.

横断型教育プログラム: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

課程: ut_course_catalog.ja.Institution = 'all'
講義使用言語: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

開講所属: Optional[ut_course_catalog.ja.Faculty] = None
class ut_course_catalog.Semester(value)[source]

Bases: enum.Enum

An enumeration.

A1 = 'A1'
A2 = 'A2'
S1 = 'S1'
S2 = 'S2'
W = 'W'
class ut_course_catalog.UTCourseCatalog(logger_level: int = 0, min_interval: Union[datetime.timedelta, int] = 1)[source]

Bases: object

A parser for the [UTokyo Online Course Catalogue](https://catalog.he.u-tokyo.ac.jp).

async fetch_and_save_search_detail_all(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, filename: Optional[str] = None, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) Iterable[ut_course_catalog.ja.Details][source]

Fetch all search results by repeatedly calling fetch_search and fetch_detail and save them to a PKL file. The filename is params.id() + “.pkl” if not specified.

Parameters
  • params (SearchParams) – Search parameters

  • year (int, optional) – Year of the course, by default 2022

  • filename (Optional[str], optional) – Filename to save the results, by default None. If None, the filename is params.id() + “.pkl”.

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of details

Return type

AsyncIterable[Details]

Yields

Iterator[AsyncIterable[Details]] – Async iterable of details

async fetch_and_save_search_detail_all_pandas(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, filename: Optional[str] = None, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) pandas.core.frame.DataFrame[source]
async fetch_code(共通科目コード: str) str[source]

Fetch time table code of a course from its common code.

Returns

Time table code of the course

Return type

str

async fetch_common_code(時間割コード: str) ut_course_catalog.ja.CommonCode[source]

Fetch common code of a course from its time table code.

Returns

Common code of the course

Return type

CommonCode

async fetch_detail(code: str, year: int = 2022) ut_course_catalog.ja.Details[source]

Fetch details of a course.

Parameters
  • code (str) – Course (common) code.

  • year (int, optional) – Year of the course, by default 2022.

Returns

Details of the course.

Return type

Details

Raises

ParserError – Raises when the parser fails to parse the website.

Fetch search results from the website.

Parameters
  • params (SearchParams) – Search parameters.

  • page (int, optional) – page number, by default 1

Returns

Search results.

Return type

SearchResult

Raises

ParserError – Raises when failed to parse the website.

async fetch_search_all(params: ut_course_catalog.ja.SearchParams, *, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) AsyncIterable[ut_course_catalog.ja.SearchResultItem][source]

Fetch all search results by repeatedly calling fetch_search.

Parameters
  • params (SearchParams) – Search parameters

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of search results

Return type

AsyncIterable[SearchResultItem]

Yields

Iterator[AsyncIterable[SearchResultItem]] – Async iterable of search results

async fetch_search_detail_all(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None, on_detail_request: Optional[Callable[[ut_course_catalog.ja.Details], Optional[Awaitable]]] = None) Iterable[ut_course_catalog.ja.Details][source]

Fetch all search results by repeatedly calling fetch_search and fetch_detail.

Parameters
  • params (SearchParams) – Search parameters

  • year (int, optional) – Year of the course, by default 2022

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of details

Return type

AsyncIterable[Details]

Yields

Iterator[AsyncIterable[Details]] – Async iterable of details

get_filepath(params: ut_course_catalog.ja.SearchParams, filename: Optional[str]) pathlib.Path[source]
retry(func: tenacity.WrappedFn) tenacity.WrappedFn[source]
session: Optional[aiohttp.client.ClientSession]
class ut_course_catalog.Weekday(value)[source]

Bases: enum.IntEnum

An enumeration.

Fri = 4
Mon = 0
Sat = 5
Sun = 6
Thu = 3
Tue = 1
Wed = 2

Submodules

ut_course_catalog.analysis module

ut_course_catalog.common module

class ut_course_catalog.common.Language(value)[source]

Bases: enum.Enum

Language of a course.

English = 'en'
Japanese = 'ja'
JapaneseAndEnglish = 'ja,en'
OnlyOtherLanguages = 'only_other'
OtherLanguagesToo = 'other'
Others = 'others'
class ut_course_catalog.common.RateLimitter(min_interval: Union[datetime.timedelta, int])[source]

Bases: object

WrappedAwaitableFn

alias of Callable[[…], Awaitable[ut_course_catalog.common.WrappedFnResult]]

WrappedFn

alias of Callable[[…], ut_course_catalog.common.WrappedFnResult]

WrappedFnResult

alias of TypeVar(‘WrappedFnResult’)

property callable: bool
property last_called: datetime.datetime
property min_interval: datetime.timedelta
property next_call: datetime.datetime
async wait() None[source]
wraps(func: Union[WrappedFn, WrappedAwaitableFn]) WrappedAwaitableFn[source]
class ut_course_catalog.common.Semester(value)[source]

Bases: enum.Enum

An enumeration.

A1 = 'A1'
A2 = 'A2'
S1 = 'S1'
S2 = 'S2'
W = 'W'
class ut_course_catalog.common.Weekday(value)[source]

Bases: enum.IntEnum

An enumeration.

Fri = 4
Mon = 0
Sat = 5
Sun = 6
Thu = 3
Tue = 1
Wed = 2
ut_course_catalog.common.async_for_task(async_iterable: AsyncIterable[T]) Iterable[asyncio.Task[T]][source]
ut_course_catalog.common.async_iterable_to_iterable(async_iterable: AsyncIterable[ut_course_catalog.common.T]) Iterable[Coroutine[None, None, ut_course_catalog.common.T]][source]

ut_course_catalog.ja module

class ut_course_catalog.ja.ClassForm(value)[source]

Bases: enum.Enum

An enumeration.

その他 = 'Z'
卒業論文 = 'T'
実習 = 'P'
実験 = 'E'
演習 = 'S'
講義 = 'L'
class ut_course_catalog.ja.CommonCode[source]

Bases: str

property class_form: ut_course_catalog.ja.ClassForm
property department_code: str
property department_name: str
property faculty: ut_course_catalog.ja.Faculty
property institution: ut_course_catalog.ja.Institution
property language: ut_course_catalog.common.Language
property large_category: str
property level: str
property middle_category: str
static parse_department(faculty: ut_course_catalog.ja.Faculty, department_code: str)[source]
property reference_number: str
property small_category: str
class ut_course_catalog.ja.Details(時間割コード: str, 共通科目コード: CommonCode, コース名: str, 教員: str, 学期: set[Semester], 曜限: set[tuple[Weekday, int]], ねらい: str, 教室: str, 単位数: Decimal, 他学部履修可: bool, 講義使用言語: str, 実務経験のある教員による授業科目: bool, 開講所属: Faculty, 授業計画: Optional[str], 授業の方法: Optional[str], 成績評価方法: Optional[str], 教科書: Optional[str], 参考書: Optional[str], 履修上の注意: Optional[str])[source]

Bases: tuple

Details of a course. Contains all available information for a course on the website. (UTAS may have more information)

property ねらい

Alias for field number 6

property コース名

Alias for field number 2

property 他学部履修可

Alias for field number 9

property 共通科目コード

Alias for field number 1

property 単位数

Alias for field number 8

property 参考書

Alias for field number 17

property 学期

Alias for field number 4

property 実務経験のある教員による授業科目

Alias for field number 11

property 履修上の注意

Alias for field number 18

property 成績評価方法

Alias for field number 15

property 授業の方法

Alias for field number 14

property 授業計画

Alias for field number 13

property 教員

Alias for field number 3

property 教室

Alias for field number 7

property 教科書

Alias for field number 16

property 時間割コード

Alias for field number 0

property 曜限

Alias for field number 5

property 講義使用言語

Alias for field number 10

property 開講所属

Alias for field number 12

class ut_course_catalog.ja.Faculty(value)[source]

Bases: enum.Enum

Faculty in the University of Tokyo.

classmethod value_of(value) Faculty[source]

Converts a commonly used expression in the website to a Faculty enum value.

人文社会系研究科 = 11
公共政策学教育部 = 25
医学系研究科 = 19
医学部 = 2
学際情報学府 = 24
工学系研究科 = 17
工学部 = 3
情報理工学系研究科 = 23
教育学研究科 = 12
教育学部 = 9
教養学部 = 8
教養学部前期課程 = 26
数理科学研究科 = 21
文学部 = 4
新領域創成科学研究科 = 22
法学政治学研究科 = 13
法学部 = 1
理学系研究科 = 16
理学部 = 5
経済学研究科 = 14
経済学部 = 7
総合文化研究科 = 15
薬学系研究科 = 20
薬学部 = 10
農学生命科学研究科 = 18
農学部 = 6
class ut_course_catalog.ja.Institution(value)[source]

Bases: enum.Enum

Institution in the University of Tokyo.

All = 'all'
大学院 = 'g'

Graduate

学部前期課程 = 'jd'

Junior Division

学部後期課程 = 'ug'

Senior Division

exception ut_course_catalog.ja.ParserError[source]

Bases: Exception

class ut_course_catalog.ja.SearchParams(keyword: Optional[str] = None, 課程: ut_course_catalog.ja.Institution = Institution.All, 開講所属: Optional[ut_course_catalog.ja.Faculty] = None, 学年: Optional[Union[Iterable[int], int]] = None, 学期: Optional[Union[Iterable[ut_course_catalog.common.Semester], ut_course_catalog.common.Semester]] = None, 曜日: Optional[Union[Iterable[ut_course_catalog.common.Weekday], ut_course_catalog.common.Weekday]] = None, 時限: Optional[Union[Iterable[int], int]] = None, 講義使用言語: Optional[Union[Iterable[str], str]] = None, 横断型教育プログラム: Optional[Union[Iterable[str], str]] = None, 実務経験のある教員による授業科目: Optional[Union[Iterable[bool], bool]] = None, 分野_NDC: Optional[Union[Iterable[str], str]] = None)[source]

Bases: object

Search query parameters.

id() str[source]
keyword: Optional[str] = None
分野_NDC: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

学年: Optional[Union[Iterable[int], int]] = None

AND search, not OR.

学期: Optional[Union[Iterable[ut_course_catalog.common.Semester], ut_course_catalog.common.Semester]] = None

AND search, not OR.

実務経験のある教員による授業科目: Optional[Union[Iterable[bool], bool]] = None

AND search, not OR. Do not specify [True, False] though it is valid.

時限: Optional[Union[Iterable[int], int]] = None

AND search, not OR. Few courses have multiple periods.

曜日: Optional[Union[Iterable[ut_course_catalog.common.Weekday], ut_course_catalog.common.Weekday]] = None

AND search, not OR. Few courses have multiple periods.

横断型教育プログラム: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

課程: ut_course_catalog.ja.Institution = 'all'
講義使用言語: Optional[Union[Iterable[str], str]] = None

AND search, not OR.

開講所属: Optional[ut_course_catalog.ja.Faculty] = None
class ut_course_catalog.ja.SearchResult(items: list[SearchResultItem], current_items_first_index: int, current_items_last_index: int, current_items_count: int, total_items_count: int, current_page: int, total_pages: int)[source]

Bases: tuple

Result of a search query.

property current_items_count

Alias for field number 3

property current_items_first_index

Alias for field number 1

property current_items_last_index

Alias for field number 2

property current_page

Alias for field number 5

property items

Alias for field number 0

property total_items_count

Alias for field number 4

property total_pages

Alias for field number 6

class ut_course_catalog.ja.SearchResultItem(時間割コード: str, 共通科目コード: CommonCode, コース名: str, 教員: str, 学期: set[Semester], 曜限: set[tuple[Weekday, int]], ねらい: str)[source]

Bases: tuple

Summary of a course in search results. Call fetch_details to get more information.

property ねらい

Alias for field number 6

property コース名

Alias for field number 2

property 共通科目コード

Alias for field number 1

property 学期

Alias for field number 4

property 教員

Alias for field number 3

property 時間割コード

Alias for field number 0

property 曜限

Alias for field number 5

class ut_course_catalog.ja.UTCourseCatalog(logger_level: int = 0, min_interval: Union[datetime.timedelta, int] = 1)[source]

Bases: object

A parser for the [UTokyo Online Course Catalogue](https://catalog.he.u-tokyo.ac.jp).

async fetch_and_save_search_detail_all(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, filename: Optional[str] = None, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) Iterable[ut_course_catalog.ja.Details][source]

Fetch all search results by repeatedly calling fetch_search and fetch_detail and save them to a PKL file. The filename is params.id() + “.pkl” if not specified.

Parameters
  • params (SearchParams) – Search parameters

  • year (int, optional) – Year of the course, by default 2022

  • filename (Optional[str], optional) – Filename to save the results, by default None. If None, the filename is params.id() + “.pkl”.

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of details

Return type

AsyncIterable[Details]

Yields

Iterator[AsyncIterable[Details]] – Async iterable of details

async fetch_and_save_search_detail_all_pandas(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, filename: Optional[str] = None, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) pandas.core.frame.DataFrame[source]
async fetch_code(共通科目コード: str) str[source]

Fetch time table code of a course from its common code.

Returns

Time table code of the course

Return type

str

async fetch_common_code(時間割コード: str) ut_course_catalog.ja.CommonCode[source]

Fetch common code of a course from its time table code.

Returns

Common code of the course

Return type

CommonCode

async fetch_detail(code: str, year: int = 2022) ut_course_catalog.ja.Details[source]

Fetch details of a course.

Parameters
  • code (str) – Course (common) code.

  • year (int, optional) – Year of the course, by default 2022.

Returns

Details of the course.

Return type

Details

Raises

ParserError – Raises when the parser fails to parse the website.

Fetch search results from the website.

Parameters
  • params (SearchParams) – Search parameters.

  • page (int, optional) – page number, by default 1

Returns

Search results.

Return type

SearchResult

Raises

ParserError – Raises when failed to parse the website.

async fetch_search_all(params: ut_course_catalog.ja.SearchParams, *, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None) AsyncIterable[ut_course_catalog.ja.SearchResultItem][source]

Fetch all search results by repeatedly calling fetch_search.

Parameters
  • params (SearchParams) – Search parameters

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of search results

Return type

AsyncIterable[SearchResultItem]

Yields

Iterator[AsyncIterable[SearchResultItem]] – Async iterable of search results

async fetch_search_detail_all(params: ut_course_catalog.ja.SearchParams, *, year: int = 2022, use_tqdm: bool = True, on_initial_request: Optional[Callable[[ut_course_catalog.ja.SearchResult], Optional[Awaitable]]] = None, on_detail_request: Optional[Callable[[ut_course_catalog.ja.Details], Optional[Awaitable]]] = None) Iterable[ut_course_catalog.ja.Details][source]

Fetch all search results by repeatedly calling fetch_search and fetch_detail.

Parameters
  • params (SearchParams) – Search parameters

  • year (int, optional) – Year of the course, by default 2022

  • use_tqdm (bool, optional) – Whether to use tqdm, by default True

  • on_initial_request (Optional[Callable[[SearchResult], Optional[Awaitable]]], optional) – Callback function to be called on the initial request, by default None

Returns

Async iterable of details

Return type

AsyncIterable[Details]

Yields

Iterator[AsyncIterable[Details]] – Async iterable of details

get_filepath(params: ut_course_catalog.ja.SearchParams, filename: Optional[str]) pathlib.Path[source]
retry(func: tenacity.WrappedFn) tenacity.WrappedFn[source]
session: Optional[aiohttp.client.ClientSession]

ut_course_catalog.pandas module

ut_course_catalog.pandas.to_dataframe(items: Iterable[NamedTuple]) pandas.core.frame.DataFrame[source]
ut_course_catalog.pandas.to_series(item: NamedTuple) pandas.core.series.Series[source]