usos-api 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {usos_api-0.3.0 → usos_api-0.3.2}/PKG-INFO +6 -5
  2. {usos_api-0.3.0 → usos_api-0.3.2}/pyproject.toml +5 -5
  3. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/auth.py +10 -2
  4. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/client.py +7 -2
  5. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/connection.py +11 -3
  6. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/helper.py +2 -11
  7. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/course.py +14 -4
  8. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/term.py +1 -1
  9. usos_api-0.3.2/usos_api/services/courses.py +84 -0
  10. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/grades.py +5 -1
  11. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/groups.py +1 -1
  12. usos_api-0.3.0/usos_api/services/courses.py +0 -52
  13. {usos_api-0.3.0 → usos_api-0.3.2}/README.md +0 -0
  14. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/__init__.py +0 -0
  15. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/exceptions.py +0 -0
  16. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/logger.py +0 -0
  17. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/__init__.py +0 -0
  18. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/api_documentation.py +0 -0
  19. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/consumer.py +0 -0
  20. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/grade.py +0 -0
  21. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/group.py +0 -0
  22. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/lang_dict.py +0 -0
  23. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/programme.py +0 -0
  24. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/registration.py +0 -0
  25. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/models/user.py +0 -0
  26. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/__init__.py +0 -0
  27. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/api_documentation.py +0 -0
  28. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/api_server.py +0 -0
  29. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/registrations.py +0 -0
  30. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/terms.py +0 -0
  31. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/services/users.py +0 -0
  32. {usos_api-0.3.0 → usos_api-0.3.2}/usos_api/utils/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usos-api
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Asynchronous USOS API for Python
5
5
  Home-page: https://github.com/Antoni-Czaplicki/usos-api
6
6
  Author: Antoni-Czaplicki
@@ -10,10 +10,11 @@ Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
- Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
14
- Requires-Dist: oauthlib (>=3.2.2,<4.0.0)
15
- Requires-Dist: pydantic (>=2.8.2,<3.0.0)
16
- Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: aiohttp (>=3.11,<4.0)
15
+ Requires-Dist: oauthlib (>=3.2,<4.0)
16
+ Requires-Dist: pydantic (>=2.10,<3.0)
17
+ Requires-Dist: python-dotenv (>=1.0,<2.0)
17
18
  Project-URL: Documentation, https://usos-api.readthedocs.io
18
19
  Project-URL: Repository, https://github.com/Antoni-Czaplicki/usos-api
19
20
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "usos-api"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "Asynchronous USOS API for Python"
5
5
  authors = ["Antoni-Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com>"]
6
6
  readme = "README.md"
@@ -10,10 +10,10 @@ documentation = "https://usos-api.readthedocs.io"
10
10
 
11
11
  [tool.poetry.dependencies]
12
12
  python = "^3.10"
13
- aiohttp = "^3.9.5"
14
- pydantic = "^2.8.2"
15
- oauthlib = "^3.2.2"
16
- python-dotenv = "^1.0.1"
13
+ aiohttp = "^3.11"
14
+ pydantic = "^2.10"
15
+ oauthlib = "^3.2"
16
+ python-dotenv = "^1.0"
17
17
 
18
18
  [tool.poetry.group.dev.dependencies]
19
19
  black = "*"
@@ -21,13 +21,20 @@ class AuthManager:
21
21
  # List of available scopes can be found at https://apps.usos.edu.pl/developers/api/authorization/#scopes
22
22
  SCOPES = "|".join(["offline_access", "studies"])
23
23
 
24
- def __init__(self, api_base_address: str, consumer_key: str, consumer_secret: str):
24
+ def __init__(
25
+ self,
26
+ api_base_address: str,
27
+ consumer_key: str,
28
+ consumer_secret: str,
29
+ trust_env: bool = False,
30
+ ):
25
31
  """
26
32
  Initialize the authentication manager.
27
33
 
28
34
  :param api_base_address: The base address of the USOS API.
29
35
  :param consumer_key: Consumer key obtained from the USOS API.
30
36
  :param consumer_secret: Consumer secret obtained from the USOS API.
37
+ :param trust_env: Whether to trust the environment variables for the connection, see https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession for more information.
31
38
  """
32
39
  self.base_address = api_base_address.rstrip("/") + "/"
33
40
  self.consumer_key = consumer_key
@@ -35,6 +42,7 @@ class AuthManager:
35
42
  self.access_token = None
36
43
  self.access_token_secret = None
37
44
  self._session = None
45
+ self.trust_env = trust_env
38
46
  self._oauth_client = Client(consumer_key, consumer_secret)
39
47
 
40
48
  async def __aenter__(self) -> "AuthManager":
@@ -60,7 +68,7 @@ class AuthManager:
60
68
  """
61
69
  Open the manager.
62
70
  """
63
- self._session = aiohttp.ClientSession()
71
+ self._session = aiohttp.ClientSession(trust_env=self.trust_env)
64
72
 
65
73
  async def close(self):
66
74
  """
@@ -34,7 +34,11 @@ class USOSClient:
34
34
  """
35
35
 
36
36
  def __init__(
37
- self, api_base_address: str, consumer_key: str, consumer_secret: str
37
+ self,
38
+ api_base_address: str,
39
+ consumer_key: str,
40
+ consumer_secret: str,
41
+ trust_env: bool = False,
38
42
  ) -> None:
39
43
  """
40
44
  Initialize the USOS API client.
@@ -42,9 +46,10 @@ class USOSClient:
42
46
  :param api_base_address: The base address of the USOS API.
43
47
  :param consumer_key: Consumer key obtained from the USOS API.
44
48
  :param consumer_secret: Consumer secret obtained from the USOS API.
49
+ :param trust_env: Whether to trust the environment variables for the connection, see https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession for more information.
45
50
  """
46
51
  self.connection = USOSAPIConnection(
47
- api_base_address, consumer_key, consumer_secret
52
+ api_base_address, consumer_key, consumer_secret, trust_env
48
53
  )
49
54
  self.user_service = UserService(self.connection)
50
55
  self.group_service = GroupService(self.connection)
@@ -15,19 +15,27 @@ class USOSAPIConnection:
15
15
  A connection to the USOS API.
16
16
  """
17
17
 
18
- def __init__(self, api_base_address: str, consumer_key: str, consumer_secret: str):
18
+ def __init__(
19
+ self,
20
+ api_base_address: str,
21
+ consumer_key: str,
22
+ consumer_secret: str,
23
+ trust_env: bool = False,
24
+ ):
19
25
  """
20
26
  Initialize the USOS API connection.
21
27
 
22
28
  :param api_base_address: The base address of the USOS API.
23
29
  :param consumer_key: Consumer key obtained from the USOS API.
24
30
  :param consumer_secret: Consumer secret obtained from the USOS API.
31
+ :param trust_env: Whether to trust the environment variables for the connection, see https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession for more information.
25
32
  """
26
33
  self.base_address = api_base_address.rstrip("/") + "/"
27
34
  self.auth_manager = AuthManager(
28
- self.base_address, consumer_key, consumer_secret
35
+ self.base_address, consumer_key, consumer_secret, trust_env
29
36
  )
30
37
  self._session = None
38
+ self.trust_env = trust_env
31
39
 
32
40
  async def __aenter__(self) -> "USOSAPIConnection":
33
41
  """
@@ -52,7 +60,7 @@ class USOSAPIConnection:
52
60
  """
53
61
  Open the connection.
54
62
  """
55
- self._session = aiohttp.ClientSession()
63
+ self._session = aiohttp.ClientSession(trust_env=self.trust_env)
56
64
  await self.auth_manager.open()
57
65
 
58
66
  async def close(self):
@@ -22,18 +22,9 @@ class APIHelper:
22
22
  ects_by_term = await self.client.course_service.get_user_courses_ects()
23
23
  terms = await self.client.term_service.get_terms(list(ects_by_term.keys()))
24
24
  term_ids = [
25
- term.id for term in terms if not current_term_only or term.is_current
26
- ]
27
- course_ids = [
28
- course_id
29
- for term_id in term_ids
30
- for course_id in ects_by_term[term_id].keys()
25
+ term.id for term in terms if not current_term_only or term.is_ongoing
31
26
  ]
32
27
 
33
- courses = {
34
- course.id: course
35
- for course in await self.client.course_service.get_courses(course_ids)
36
- }
37
28
  grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids)
38
29
 
39
30
  user_grades = []
@@ -47,7 +38,7 @@ class APIHelper:
47
38
  for grade in grades:
48
39
  grade.weight = ects
49
40
  grade.course_edition = CourseEdition(
50
- course=courses[course_id], term=term
41
+ course_id=course_id, term_id=term.id
51
42
  )
52
43
  user_grades.append(grade)
53
44
 
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Optional
1
+ from typing import TYPE_CHECKING, Any, Optional
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
@@ -65,13 +65,23 @@ class CourseEdition(BaseModel):
65
65
  Class representing a course edition.
66
66
  """
67
67
 
68
- course: Course | None = None
69
- term: Term | None = None
68
+ course_id: str | None = None
69
+ course_name: LangDict | None = None
70
+ term_id: str | None = None
70
71
  homepage_url: str | None = None
72
+ profile_url: str | None = None
73
+ coordinators: list[dict[str, Any]] | None = None
74
+ lecturers: list[dict[str, Any]] | None = None
75
+ passing_status: str | None = None # passed, failed, not_yet_passed
76
+ user_groups: list[Group] | None = None
77
+
71
78
  description: LangDict | None = None
72
79
  bibliography: LangDict | None = None
73
80
  notes: LangDict | None = None
74
- course_units: list[CourseUnit] | None = None
81
+ course_units_ids: list[str] | None = None
82
+ participants: list[dict[str, Any]] | None = None
83
+ grades: list[dict[str, Any]] | None = None
84
+ attributes: list[dict[str, list[LangDict]]] | None = None
75
85
 
76
86
 
77
87
  class CourseEditionConducted(BaseModel):
@@ -14,7 +14,7 @@ class Term(BaseModel):
14
14
  is_active: bool | None = None
15
15
 
16
16
  @property
17
- def is_current(self) -> bool:
17
+ def is_ongoing(self) -> bool:
18
18
  """
19
19
  Check if the term is currently active.
20
20
  """
@@ -0,0 +1,84 @@
1
+ from typing import Optional
2
+
3
+ from ..connection import USOSAPIConnection
4
+ from ..models import Course, CourseEdition, Term
5
+
6
+
7
+ class CourseService:
8
+ """
9
+ A service for course-related operations.
10
+ """
11
+
12
+ def __init__(self, connection: USOSAPIConnection):
13
+ """
14
+ Initialize the course service.
15
+
16
+ :param connection: The connection to use.
17
+ """
18
+ self.connection = connection
19
+
20
+ async def get_user_courses_ects(self) -> dict[str, dict[str, float]]:
21
+ """
22
+ Get user courses ECTS.
23
+
24
+ :return: The user courses ECTS.
25
+ """
26
+ response = await self.connection.post("services/courses/user_ects_points")
27
+ return {
28
+ term: {course: float(points) for course, points in courses.items()}
29
+ for term, courses in response.items()
30
+ }
31
+
32
+ async def get_courses(
33
+ self, course_ids: list[str], fields: Optional[list[str]] = None
34
+ ) -> list[Course]:
35
+ """
36
+ Get courses by their IDs.
37
+
38
+ :param course_ids: The IDs of the courses to get.
39
+ :param fields: The fields to include in the response.
40
+ :return: A list of courses.
41
+ """
42
+ if not course_ids:
43
+ return []
44
+
45
+ course_ids_str = "|".join(course_ids)
46
+ fields_str = "|".join(fields) if fields else "id|name"
47
+
48
+ response = await self.connection.post(
49
+ "services/courses/courses", course_ids=course_ids_str, fields=fields_str
50
+ )
51
+
52
+ return [Course(**course_data) for course_data in response.values()]
53
+
54
+ async def get_user_course_editions(
55
+ self,
56
+ active_terms_only: bool = False,
57
+ ongoing_terms_only: bool = False,
58
+ ) -> list[CourseEdition]:
59
+ """
60
+ Get information on user's courses.
61
+
62
+ This is a BETA method. We're looking for beta-testers. Until we find them, there's a substantial probability it won't stay backwards-compatible!
63
+ If you are planning on using this method, please let us know. Then, we will work with you and move it out of beta as soon as we can.
64
+
65
+ :param active_terms_only: Return only these course editions which are related to the currently active academic terms. Apparently, this parameter does not always work as expected, so you can use `ongoing_terms_only` instead.
66
+ :param ongoing_terms_only: Return only these course editions which are related to the currently ongoing academic terms (filtered locally based on start and finish dates).
67
+ :return: A dictionary of selected fields and their values.
68
+ """
69
+ params = {
70
+ "fields": "course_editions[course_id|course_name|term_id|homepage_url|profile_url|coordinators|lecturers|passing_status|user_groups|grades|attributes]|terms",
71
+ "active_terms_only": str(active_terms_only).lower(),
72
+ }
73
+
74
+ response = await self.connection.post("services/courses/user", **params)
75
+
76
+ terms = {term["id"]: Term(**term) for term in response["terms"]}
77
+ ongoing_terms = {term_id for term_id, term in terms.items() if term.is_ongoing}
78
+
79
+ return [
80
+ CourseEdition(**course_edition)
81
+ for term_id, course_editions in response["course_editions"].items()
82
+ if not ongoing_terms_only or term_id in ongoing_terms
83
+ for course_edition in course_editions
84
+ ]
@@ -84,6 +84,7 @@ class GradeService:
84
84
  exam_session_number: Grade(**grade)
85
85
  for unit in units
86
86
  for exam_session_number, grade in unit.items()
87
+ if grade
87
88
  }
88
89
  return processed_units_grades
89
90
 
@@ -95,5 +96,8 @@ class GradeService:
95
96
  :return: The processed course grades.
96
97
  """
97
98
  return [
98
- Grade(**grade) for session in course_grades for grade in session.values()
99
+ Grade(**grade)
100
+ for session in course_grades
101
+ for grade in session.values()
102
+ if grade
99
103
  ]
@@ -10,7 +10,7 @@ def _filter_ongoing_terms(terms: list[Term]) -> list[Term]:
10
10
  :param terms: The terms to filter.
11
11
  :return: The ongoing terms.
12
12
  """
13
- return [term for term in terms if term.is_current]
13
+ return [term for term in terms if term.is_ongoing]
14
14
 
15
15
 
16
16
  def _deserialize_term(data: dict) -> Term:
@@ -1,52 +0,0 @@
1
- from typing import Optional
2
-
3
- from ..connection import USOSAPIConnection
4
- from ..models import Course
5
-
6
-
7
- class CourseService:
8
- """
9
- A service for course-related operations.
10
- """
11
-
12
- def __init__(self, connection: USOSAPIConnection):
13
- """
14
- Initialize the course service.
15
-
16
- :param connection: The connection to use.
17
- """
18
- self.connection = connection
19
-
20
- async def get_user_courses_ects(self) -> dict[str, dict[str, float]]:
21
- """
22
- Get user courses ECTS.
23
-
24
- :return: The user courses ECTS.
25
- """
26
- response = await self.connection.post("services/courses/user_ects_points")
27
- return {
28
- term: {course: float(points) for course, points in courses.items()}
29
- for term, courses in response.items()
30
- }
31
-
32
- async def get_courses(
33
- self, course_ids: list[str], fields: Optional[list[str]] = None
34
- ) -> list[Course]:
35
- """
36
- Get courses by their IDs.
37
-
38
- :param course_ids: The IDs of the courses to get.
39
- :param fields: The fields to include in the response.
40
- :return: A list of courses.
41
- """
42
- if not course_ids:
43
- return []
44
-
45
- course_ids_str = "|".join(course_ids)
46
- fields_str = "|".join(fields) if fields else "id|name"
47
-
48
- response = await self.connection.post(
49
- "services/courses/courses", course_ids=course_ids_str, fields=fields_str
50
- )
51
-
52
- return [Course(**course_data) for course_data in response.values()]
File without changes
File without changes
File without changes