pydemy 0.1.0__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.
- pydemy-0.1.0/LICENCE +21 -0
- pydemy-0.1.0/PKG-INFO +110 -0
- pydemy-0.1.0/README.md +77 -0
- pydemy-0.1.0/pydemy/__init__.py +8 -0
- pydemy-0.1.0/pydemy/client.py +275 -0
- pydemy-0.1.0/pydemy/exceptions.py +7 -0
- pydemy-0.1.0/pydemy/models/__init__.py +0 -0
- pydemy-0.1.0/pydemy/models/chapter.py +21 -0
- pydemy-0.1.0/pydemy/models/course.py +67 -0
- pydemy-0.1.0/pydemy/models/course_category.py +32 -0
- pydemy-0.1.0/pydemy/models/course_review.py +18 -0
- pydemy-0.1.0/pydemy/models/course_subcategory.py +157 -0
- pydemy-0.1.0/pydemy/models/filters/__init__.py +0 -0
- pydemy-0.1.0/pydemy/models/filters/course_filters.py +127 -0
- pydemy-0.1.0/pydemy/models/filters/review_filters.py +17 -0
- pydemy-0.1.0/pydemy/models/lecture.py +43 -0
- pydemy-0.1.0/pydemy/models/mixins/__init__.py +0 -0
- pydemy-0.1.0/pydemy/models/mixins/serializers.py +26 -0
- pydemy-0.1.0/pydemy/models/quiz.py +28 -0
- pydemy-0.1.0/pydemy/models/user.py +11 -0
- pydemy-0.1.0/pydemy.egg-info/PKG-INFO +110 -0
- pydemy-0.1.0/pydemy.egg-info/SOURCES.txt +26 -0
- pydemy-0.1.0/pydemy.egg-info/dependency_links.txt +1 -0
- pydemy-0.1.0/pydemy.egg-info/requires.txt +8 -0
- pydemy-0.1.0/pydemy.egg-info/top_level.txt +1 -0
- pydemy-0.1.0/pyproject.toml +47 -0
- pydemy-0.1.0/setup.cfg +4 -0
- pydemy-0.1.0/setup.py +18 -0
pydemy-0.1.0/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Robel Asefa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pydemy-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pydemy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for interacting with the Udemy Affiliate API.
|
|
5
|
+
Home-page: https://github.com/robelasefa/pydemy
|
|
6
|
+
Author: Robel Asefa
|
|
7
|
+
Author-email: Robel Asefa <mertigenet@gmail.com>
|
|
8
|
+
Project-URL: Homepage, https://github.com/robelasefa/pydemy
|
|
9
|
+
Project-URL: Issues, https://github.com/robelasefa/pydemy/issues
|
|
10
|
+
Keywords: udemy,api,courses,education
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Education
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
20
|
+
Classifier: Operating System :: POSIX
|
|
21
|
+
Classifier: Operating System :: Unix
|
|
22
|
+
Classifier: Operating System :: MacOS
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENCE
|
|
26
|
+
Requires-Dist: requests~=2.32.3
|
|
27
|
+
Requires-Dist: pydantic~=2.8.2
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: black; extra == "dev"
|
|
30
|
+
Requires-Dist: isort; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff; extra == "dev"
|
|
32
|
+
Requires-Dist: pylint; extra == "dev"
|
|
33
|
+
|
|
34
|
+
# Pydemy
|
|
35
|
+
|
|
36
|
+
Pydemy provides a convenient way to interact with the **[Udemy Affiliate API](https://www.udemy.com/developers/affiliate)** from your Python applications. You can use Pydemy to search for courses, retrieve course details, fetch reviews, and potentially explore other functionalities offered by the API.
|
|
37
|
+
|
|
38
|
+
## Udemy API Support
|
|
39
|
+
|
|
40
|
+
Pydemy currently supports the **Udemy Affiliate API v2.0**. This API allows developers to access public information about Udemy courses.
|
|
41
|
+
|
|
42
|
+
**Note**: The [Udemy Instructor API](https://www.udemy.com/developers/instructor/), which provides functionalities specific to course creation and management, is not currently supported by Pydemy.
|
|
43
|
+
|
|
44
|
+
## Main Features
|
|
45
|
+
|
|
46
|
+
- **Search for Courses**: Easily search for courses based on various criteria like keywords, categories, or
|
|
47
|
+
price filters.
|
|
48
|
+
- **Get Detailed Course Information**: Retrieve comprehensive details about a specific course, including
|
|
49
|
+
title, instructor, ratings, curriculum, and more.
|
|
50
|
+
- **Fetch Course Reviews**: Gain valuable insights into student experiences by fetching and analyzing reviews
|
|
51
|
+
for particular course.
|
|
52
|
+
|
|
53
|
+
## Getting Started
|
|
54
|
+
|
|
55
|
+
1. **Obtain API Credentials**:
|
|
56
|
+
Visit [Udemy API Clients](https://www.udemy.com/user/edit-api-clients/) to create a new API client and obtain your `clientID` and `clientSecret`.
|
|
57
|
+
|
|
58
|
+
2. **Installation**:
|
|
59
|
+
Install the library using pip:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install pydemy
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
3. **Usage**:
|
|
66
|
+
Import the `UdemyClient` class:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from pydemy import UdemyClient
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Initialize the client with your API credentials:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
client_id = "YOUR_CLIENT_ID"
|
|
76
|
+
client_secret = "YOUR_CLIENT_SECRET"
|
|
77
|
+
|
|
78
|
+
client = UdemyClient(client_id=client_id, client_secret=client_secret)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quickstart
|
|
82
|
+
|
|
83
|
+
Here is an example that demonstrates how to use the `UdemyClient` instance to retrieve information about public courses.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
client = UdemyClient(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
|
|
87
|
+
|
|
88
|
+
# Get a list of public courses (replace '4534650' with a specific course ID for details)
|
|
89
|
+
courses = client.get_public_curriculum_list(course_id=4534650)
|
|
90
|
+
|
|
91
|
+
# Print course titles
|
|
92
|
+
for course in courses:
|
|
93
|
+
print(course.title)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
We welcome contributions from the community! If you have bug fixes, improvements, or new features, feel free to submit a pull request. For detailed guidelines on contributing, please refer to the [CONTRIBUTING.rst](https://github.com/robelasefa/pydemy/blob/main/CONTRIBUTING.rst) file.
|
|
99
|
+
|
|
100
|
+
Here's a brief overview:
|
|
101
|
+
|
|
102
|
+
- Fork the repository.
|
|
103
|
+
- Create a new branch for your changes.
|
|
104
|
+
- Implement your changes and add unit tests if applicable.
|
|
105
|
+
- Follow consistent coding style.
|
|
106
|
+
- Submit a pull request with a clear description of your changes.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
This project is licensed under the MIT License - see the **[LICENSE.md](https://github.com/robelasefa/pydemy/blob/main/LICENSE)** file for details.
|
pydemy-0.1.0/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Pydemy
|
|
2
|
+
|
|
3
|
+
Pydemy provides a convenient way to interact with the **[Udemy Affiliate API](https://www.udemy.com/developers/affiliate)** from your Python applications. You can use Pydemy to search for courses, retrieve course details, fetch reviews, and potentially explore other functionalities offered by the API.
|
|
4
|
+
|
|
5
|
+
## Udemy API Support
|
|
6
|
+
|
|
7
|
+
Pydemy currently supports the **Udemy Affiliate API v2.0**. This API allows developers to access public information about Udemy courses.
|
|
8
|
+
|
|
9
|
+
**Note**: The [Udemy Instructor API](https://www.udemy.com/developers/instructor/), which provides functionalities specific to course creation and management, is not currently supported by Pydemy.
|
|
10
|
+
|
|
11
|
+
## Main Features
|
|
12
|
+
|
|
13
|
+
- **Search for Courses**: Easily search for courses based on various criteria like keywords, categories, or
|
|
14
|
+
price filters.
|
|
15
|
+
- **Get Detailed Course Information**: Retrieve comprehensive details about a specific course, including
|
|
16
|
+
title, instructor, ratings, curriculum, and more.
|
|
17
|
+
- **Fetch Course Reviews**: Gain valuable insights into student experiences by fetching and analyzing reviews
|
|
18
|
+
for particular course.
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
1. **Obtain API Credentials**:
|
|
23
|
+
Visit [Udemy API Clients](https://www.udemy.com/user/edit-api-clients/) to create a new API client and obtain your `clientID` and `clientSecret`.
|
|
24
|
+
|
|
25
|
+
2. **Installation**:
|
|
26
|
+
Install the library using pip:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install pydemy
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
3. **Usage**:
|
|
33
|
+
Import the `UdemyClient` class:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from pydemy import UdemyClient
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Initialize the client with your API credentials:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
client_id = "YOUR_CLIENT_ID"
|
|
43
|
+
client_secret = "YOUR_CLIENT_SECRET"
|
|
44
|
+
|
|
45
|
+
client = UdemyClient(client_id=client_id, client_secret=client_secret)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quickstart
|
|
49
|
+
|
|
50
|
+
Here is an example that demonstrates how to use the `UdemyClient` instance to retrieve information about public courses.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
client = UdemyClient(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
|
|
54
|
+
|
|
55
|
+
# Get a list of public courses (replace '4534650' with a specific course ID for details)
|
|
56
|
+
courses = client.get_public_curriculum_list(course_id=4534650)
|
|
57
|
+
|
|
58
|
+
# Print course titles
|
|
59
|
+
for course in courses:
|
|
60
|
+
print(course.title)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
|
|
65
|
+
We welcome contributions from the community! If you have bug fixes, improvements, or new features, feel free to submit a pull request. For detailed guidelines on contributing, please refer to the [CONTRIBUTING.rst](https://github.com/robelasefa/pydemy/blob/main/CONTRIBUTING.rst) file.
|
|
66
|
+
|
|
67
|
+
Here's a brief overview:
|
|
68
|
+
|
|
69
|
+
- Fork the repository.
|
|
70
|
+
- Create a new branch for your changes.
|
|
71
|
+
- Implement your changes and add unit tests if applicable.
|
|
72
|
+
- Follow consistent coding style.
|
|
73
|
+
- Submit a pull request with a clear description of your changes.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
This project is licensed under the MIT License - see the **[LICENSE.md](https://github.com/robelasefa/pydemy/blob/main/LICENSE)** file for details.
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"""Interact with the Udemy API for courses, reviews, curriculum, and more."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Union, cast
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from requests.auth import HTTPBasicAuth
|
|
7
|
+
from requests.exceptions import RequestException
|
|
8
|
+
|
|
9
|
+
from pydemy.exceptions import UdemyAPIError
|
|
10
|
+
from pydemy.models.chapter import Chapter
|
|
11
|
+
from pydemy.models.course import Course, Instructor, Locale, PriceDetail
|
|
12
|
+
from pydemy.models.course_review import CourseReview
|
|
13
|
+
from pydemy.models.filters.course_filters import CourseFilter
|
|
14
|
+
from pydemy.models.filters.review_filters import ReviewFilter
|
|
15
|
+
from pydemy.models.lecture import Asset, Lecture
|
|
16
|
+
from pydemy.models.quiz import Quiz
|
|
17
|
+
from pydemy.models.user import User
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class UdemyClient:
|
|
21
|
+
"""Udemy API client for interacting with courses, reviews, curriculum, and more."""
|
|
22
|
+
|
|
23
|
+
__base_url = "https://www.udemy.com/api-2.0/"
|
|
24
|
+
|
|
25
|
+
def __init__(self, client_id: str, client_secret: str, timeout: int = 5) -> None:
|
|
26
|
+
"""
|
|
27
|
+
Initializes a PyUdemy object.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
client_id (str): Your Udemy client ID.
|
|
31
|
+
client_secret (str): Your Udemy client secret.
|
|
32
|
+
timeout (int, optional): The timeout value in seconds for requests to the Udemy API.
|
|
33
|
+
Defaults to 5.
|
|
34
|
+
Raises:
|
|
35
|
+
`UdemyAPIError`: If either client_id or client_secret is not provided.
|
|
36
|
+
"""
|
|
37
|
+
if not client_id:
|
|
38
|
+
raise UdemyAPIError("The argument client_id is required.")
|
|
39
|
+
if not client_secret:
|
|
40
|
+
raise UdemyAPIError("The argument client_secret is required.")
|
|
41
|
+
|
|
42
|
+
self.__client_id = client_id
|
|
43
|
+
self.__client_secret = client_secret
|
|
44
|
+
self.__auth = HTTPBasicAuth(self.__client_id, self.__client_secret)
|
|
45
|
+
self.__timeout = timeout
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def _parse_entry(entry_dict: Dict[str, Any]) -> Dict[str, Any]:
|
|
49
|
+
"""
|
|
50
|
+
Parses an entry dictionary from the Udemy API response, removing the `_class` key
|
|
51
|
+
and transforming it for creating Pydantic objects.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
entry_dict (Dict[str, Any]): A dictionary representing an entry from the Udemy API
|
|
55
|
+
response.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Dict[str, Any]: A modified dictionary suitable for creating a Pydantic object.
|
|
59
|
+
"""
|
|
60
|
+
parsed_data = entry_dict.copy() # Avoid modifying the original dict
|
|
61
|
+
parsed_data.pop("_class", None)
|
|
62
|
+
|
|
63
|
+
def parse_nested_model(field_name, model_class):
|
|
64
|
+
if field_name in parsed_data and isinstance(parsed_data[field_name], dict):
|
|
65
|
+
if model_class:
|
|
66
|
+
parsed_data[field_name] = model_class(**parsed_data[field_name])
|
|
67
|
+
else:
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
if "_class" in entry_dict:
|
|
71
|
+
# Handle top-level model selection
|
|
72
|
+
model_class = {
|
|
73
|
+
"course": Course,
|
|
74
|
+
"course_review": CourseReview,
|
|
75
|
+
"lecture": Lecture,
|
|
76
|
+
}.get(entry_dict["_class"])
|
|
77
|
+
|
|
78
|
+
if model_class:
|
|
79
|
+
for field, value in entry_dict.items():
|
|
80
|
+
# Parse nested models based on defined classes
|
|
81
|
+
parse_nested_model(field, User if field == "user" else None)
|
|
82
|
+
parse_nested_model(field, PriceDetail if field == "price_detail" else None)
|
|
83
|
+
parse_nested_model(
|
|
84
|
+
field, Instructor if field == "visible_instructors" else None
|
|
85
|
+
)
|
|
86
|
+
parse_nested_model(field, Locale if field == "locale" else None)
|
|
87
|
+
parse_nested_model(field, Asset if field == "asset" else None)
|
|
88
|
+
|
|
89
|
+
# Handle lists of nested models
|
|
90
|
+
if isinstance(value, list) and any(isinstance(item, dict) for item in value):
|
|
91
|
+
model_class_list = {
|
|
92
|
+
"visible_instructors": Instructor,
|
|
93
|
+
}.get(field)
|
|
94
|
+
if model_class_list:
|
|
95
|
+
parsed_data[field] = [
|
|
96
|
+
model_class_list(**item) if item else item for item in value
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
return parsed_data
|
|
100
|
+
|
|
101
|
+
def get_courses(self, filters: CourseFilter = CourseFilter()) -> List[Course]:
|
|
102
|
+
"""
|
|
103
|
+
Returns a list of Udemy courses based on provided search parameters.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
filters (`CourseFilter`, optional): A namedtuple containing optional filters.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
A list of `Course` objects representing the retrieved courses.
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
`UdemyAPIError`: If there's an error communicating with the API or the response status
|
|
113
|
+
code indicates an error.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
url = self.__base_url + "courses/"
|
|
117
|
+
query_params = {
|
|
118
|
+
key: str(value) for key, value in filters.model_dump(exclude_unset=True).items()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
response = requests.get(
|
|
123
|
+
url=url, auth=self.__auth, params=query_params, timeout=self.__timeout
|
|
124
|
+
)
|
|
125
|
+
response.raise_for_status() # Raise exception for non-200 status codes
|
|
126
|
+
data = response.json()
|
|
127
|
+
|
|
128
|
+
# Extract course entries based on the response format
|
|
129
|
+
course_entries = cast(dict, data).get("results", [data])
|
|
130
|
+
if not isinstance(course_entries, list):
|
|
131
|
+
raise UdemyAPIError(f"Unexpected response format: {data}")
|
|
132
|
+
|
|
133
|
+
courses = []
|
|
134
|
+
for course_entry in course_entries:
|
|
135
|
+
parsed_entry = self._parse_entry(course_entry)
|
|
136
|
+
course = Course(**parsed_entry)
|
|
137
|
+
courses.append(course)
|
|
138
|
+
|
|
139
|
+
return courses
|
|
140
|
+
|
|
141
|
+
except RequestException as exc:
|
|
142
|
+
raise UdemyAPIError(f"Error communicating with the API: {exc}") from exc
|
|
143
|
+
except Exception as exc:
|
|
144
|
+
raise UdemyAPIError(f"Unexpected error: {exc}") from exc
|
|
145
|
+
|
|
146
|
+
def get_course_details(self, course_id: int) -> Course:
|
|
147
|
+
"""
|
|
148
|
+
Retrieves details of a specified course by its ID and returns a `Course` object.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
course_id (int): The ID of the course to retrieve details for.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
A `Course` object representing the retrieved course details.
|
|
155
|
+
|
|
156
|
+
Raises:
|
|
157
|
+
`UdemyAPIError`: If there's an error communicating with the API or the response
|
|
158
|
+
status code indicates an error.
|
|
159
|
+
"""
|
|
160
|
+
url = self.__base_url + f"courses/{course_id}/"
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
response = requests.get(url=url, auth=self.__auth, timeout=self.__timeout)
|
|
164
|
+
response.raise_for_status() # Raise exception for non-200 status codes
|
|
165
|
+
course_data = response.json()
|
|
166
|
+
parsed_course_data = self._parse_entry(course_data)
|
|
167
|
+
course = Course(**parsed_course_data)
|
|
168
|
+
|
|
169
|
+
return course
|
|
170
|
+
|
|
171
|
+
except RequestException as exc:
|
|
172
|
+
raise UdemyAPIError(f"Error communicating with the API: {exc}") from exc
|
|
173
|
+
except Exception as exc:
|
|
174
|
+
raise UdemyAPIError(f"Unexpected error: {exc}") from exc
|
|
175
|
+
|
|
176
|
+
def get_course_reviews(
|
|
177
|
+
self, course_id: int, filters: ReviewFilter = ReviewFilter()
|
|
178
|
+
) -> List[CourseReview]:
|
|
179
|
+
"""
|
|
180
|
+
Retrieves a list of reviews for a course, with optional filters.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
course_id (int): The ID of the course to retrieve reviews for.
|
|
184
|
+
filters (ReviewFilter, optional): A namedtuple containing optional filters.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
A list of `CourseReview` objects representing the retrieved reviews.
|
|
188
|
+
|
|
189
|
+
Raises:
|
|
190
|
+
`UdemyAPIError`: If there's an error communicating with the API or the response
|
|
191
|
+
status code indicates an error.
|
|
192
|
+
"""
|
|
193
|
+
url = self.__base_url + f"courses/{course_id}/reviews/"
|
|
194
|
+
query_params = {
|
|
195
|
+
key: str(value) for key, value in filters.model_dump(exclude_unset=True).items()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
try:
|
|
199
|
+
response = requests.get(
|
|
200
|
+
url=url, auth=self.__auth, params=query_params, timeout=self.__timeout
|
|
201
|
+
)
|
|
202
|
+
response.raise_for_status() # Raise exception for non-200 status codes
|
|
203
|
+
data = response.json()
|
|
204
|
+
|
|
205
|
+
# Extract course entries based on the response format
|
|
206
|
+
review_entries = cast(dict, data).get("results", [data])
|
|
207
|
+
if not isinstance(review_entries, list):
|
|
208
|
+
raise UdemyAPIError(f"Unexpected response format: {data}")
|
|
209
|
+
|
|
210
|
+
reviews = []
|
|
211
|
+
for review_entry in review_entries:
|
|
212
|
+
parsed_entry = self._parse_entry(review_entry)
|
|
213
|
+
review = CourseReview(**parsed_entry)
|
|
214
|
+
reviews.append(review)
|
|
215
|
+
|
|
216
|
+
return reviews
|
|
217
|
+
|
|
218
|
+
except RequestException as exc:
|
|
219
|
+
raise UdemyAPIError(f"Error communicating with the API: {exc}") from exc
|
|
220
|
+
except Exception as exc:
|
|
221
|
+
raise UdemyAPIError(f"Unexpected error: {exc}") from exc
|
|
222
|
+
|
|
223
|
+
def get_course_public_curriculum(
|
|
224
|
+
self, course_id: int, page: int = 1, page_size: int = 10
|
|
225
|
+
) -> List[Union[Chapter, Quiz, Lecture]]:
|
|
226
|
+
"""
|
|
227
|
+
Retrieves the public curriculum list of a specified course.
|
|
228
|
+
|
|
229
|
+
Parses the response data into `Chapter`, `Quiz` or `Lecture` objects based on the `_class`
|
|
230
|
+
attribute.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
course_id (int): The ID of the course to retrieve the public curriculum list for.
|
|
234
|
+
page (int, optional): Pagination parameter for retrieving specific pages.
|
|
235
|
+
Defaults to None.
|
|
236
|
+
page_size (int, optional): Pagination parameter for specifying the number of items per
|
|
237
|
+
page. Defaults to None.
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
A list of `Chapter`, `Quiz` or `Lecture` objects parsed from the API response.
|
|
241
|
+
|
|
242
|
+
Raises:
|
|
243
|
+
`UdemyAPIError`: If there's an error communicating with the API or the response
|
|
244
|
+
status code indicates an error.
|
|
245
|
+
"""
|
|
246
|
+
url = self.__base_url + f"courses/{course_id}/public-curriculum-items/"
|
|
247
|
+
query_params = {"page": page, "page_size": page_size}
|
|
248
|
+
|
|
249
|
+
try:
|
|
250
|
+
response = requests.get(
|
|
251
|
+
url=url, auth=self.__auth, params=query_params, timeout=self.__timeout
|
|
252
|
+
)
|
|
253
|
+
response.raise_for_status() # Raise exception for non-200 status codes
|
|
254
|
+
data = response.json()
|
|
255
|
+
|
|
256
|
+
# Extract course entries based on the response format
|
|
257
|
+
curriculum_entries = cast(dict, data).get("results", [data])
|
|
258
|
+
if not isinstance(curriculum_entries, list):
|
|
259
|
+
raise UdemyAPIError(f"Unexpected response format: {data}")
|
|
260
|
+
|
|
261
|
+
curriculums = []
|
|
262
|
+
for entry in curriculum_entries:
|
|
263
|
+
if entry["_class"] == ["chapter", "quiz"]:
|
|
264
|
+
curriculums.append(entry) # Chapters and Quizs can be directly added
|
|
265
|
+
elif entry["_class"] == "lecture":
|
|
266
|
+
parsed_entry = self._parse_entry(entry)
|
|
267
|
+
curriculums.append(parsed_entry)
|
|
268
|
+
else:
|
|
269
|
+
# Don't handle unexpected item types
|
|
270
|
+
pass
|
|
271
|
+
|
|
272
|
+
except RequestException as exc:
|
|
273
|
+
raise UdemyAPIError(f"Error communicating with the API: {exc}") from exc
|
|
274
|
+
except Exception as exc:
|
|
275
|
+
raise UdemyAPIError(f"Unexpected error: {exc}") from exc
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Pydantic model representing a Chapter object as inferred from the Udemy API response."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from .mixins.serializers import DateTimeSerializer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Chapter(DateTimeSerializer):
|
|
9
|
+
"""
|
|
10
|
+
Pydantic model for a Chapter object from the Udemy API response.
|
|
11
|
+
|
|
12
|
+
**Note:** This object structure is inferred from the API response and might not be explicitly
|
|
13
|
+
documented by Udemy.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
id: int
|
|
17
|
+
created: datetime
|
|
18
|
+
sort_order: int
|
|
19
|
+
title: str
|
|
20
|
+
description: str
|
|
21
|
+
is_published: bool
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pydantic model representing a Udemy Course object with nested models for price details,
|
|
3
|
+
instructors, and locale.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, List, Optional
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
from .user import User
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PriceDetail(BaseModel):
|
|
14
|
+
"""Pydantic model for a course's price details."""
|
|
15
|
+
|
|
16
|
+
amount: float
|
|
17
|
+
currency: str
|
|
18
|
+
price_string: str
|
|
19
|
+
currency_symbol: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Instructor(User):
|
|
23
|
+
"""Pydantic model for a course instructor inheriting from User."""
|
|
24
|
+
|
|
25
|
+
job_title: Optional[str] = None
|
|
26
|
+
image_50x50: Optional[str] = None
|
|
27
|
+
image_100x100: Optional[str] = None
|
|
28
|
+
initials: str
|
|
29
|
+
url: str
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Locale(BaseModel):
|
|
33
|
+
"""Pydantic model for a course's locale information."""
|
|
34
|
+
|
|
35
|
+
locale: str
|
|
36
|
+
title: str
|
|
37
|
+
english_title: str
|
|
38
|
+
simple_english_title: str
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Course(BaseModel):
|
|
42
|
+
"""Pydantic model representing a Udemy Course."""
|
|
43
|
+
|
|
44
|
+
id: int
|
|
45
|
+
title: str
|
|
46
|
+
url: str
|
|
47
|
+
is_paid: bool
|
|
48
|
+
price: Optional[str]
|
|
49
|
+
price_detail: Optional[PriceDetail]
|
|
50
|
+
price_serve_tracking_id: Optional[str]
|
|
51
|
+
visible_instructors: List[Instructor]
|
|
52
|
+
image_125_H: str
|
|
53
|
+
image_240x135: str
|
|
54
|
+
is_practice_test_course: bool
|
|
55
|
+
image_480x270: str
|
|
56
|
+
published_title: str
|
|
57
|
+
tracking_id: str = ""
|
|
58
|
+
locale: Locale
|
|
59
|
+
predictive_score: Optional[float] = None
|
|
60
|
+
relevancy_score: Optional[float] = None
|
|
61
|
+
input_features: Optional[Dict[str, Any]] = None
|
|
62
|
+
lecture_search_result: Optional[Dict[str, Any]] = None
|
|
63
|
+
curriculum_lectures: Optional[List[Dict[str, Any]]] = []
|
|
64
|
+
order_in_results: Optional[int] = None
|
|
65
|
+
curriculum_items: Optional[List[Dict[str, Any]]] = []
|
|
66
|
+
headline: Optional[str] = None
|
|
67
|
+
instructor_name: Optional[str] = None
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Pydantic model representing a Course Category with a static list of possible categories."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CourseCategory(BaseModel):
|
|
9
|
+
"""Pydantic model for a Course Category on the Udemy API."""
|
|
10
|
+
|
|
11
|
+
sort_order: int
|
|
12
|
+
title: str
|
|
13
|
+
title_cleaned: str
|
|
14
|
+
|
|
15
|
+
# Define a list of possible categories
|
|
16
|
+
POSSIBLE_CATEGORIES: List[str] = [
|
|
17
|
+
"Business",
|
|
18
|
+
"Design",
|
|
19
|
+
"Development",
|
|
20
|
+
"Finance & Accounting",
|
|
21
|
+
"Health & Fitness",
|
|
22
|
+
"IT & Software",
|
|
23
|
+
"Lifestyle",
|
|
24
|
+
"Marketing",
|
|
25
|
+
"Music",
|
|
26
|
+
"Office Productivity",
|
|
27
|
+
"Personal Development",
|
|
28
|
+
"Photography & Video",
|
|
29
|
+
"Teaching & Academics",
|
|
30
|
+
"Udemy Free Resource Center",
|
|
31
|
+
"Vodafone",
|
|
32
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Pydantic model representing a Udemy Course Review with a nested User model."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from .mixins.serializers import DateTimeSerializer
|
|
6
|
+
from .user import User
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CourseReview(DateTimeSerializer):
|
|
10
|
+
"""Pydantic model for a Course Review on the Udemy API."""
|
|
11
|
+
|
|
12
|
+
id: int
|
|
13
|
+
content: str
|
|
14
|
+
rating: float
|
|
15
|
+
created: datetime
|
|
16
|
+
modified: datetime
|
|
17
|
+
user_modified: datetime
|
|
18
|
+
user: User
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pydantic model representing a Course Subcategory with a nested CourseCategory model and a static
|
|
3
|
+
list of possible subcategories.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import List
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
from .course_category import CourseCategory
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CourseSubcategory(BaseModel):
|
|
14
|
+
"""Pydantic model for a Course Subcategory on the Udemy API."""
|
|
15
|
+
|
|
16
|
+
category: CourseCategory
|
|
17
|
+
sort_order: int
|
|
18
|
+
title: str
|
|
19
|
+
title_cleaned: str = Field(default_factory=lambda t: t.title.lower().replace(" ", "-"))
|
|
20
|
+
|
|
21
|
+
# Define a list of possible subcategories
|
|
22
|
+
POSSIBLE_SUBCATEGORIES: List[str] = [
|
|
23
|
+
"3D & Animation",
|
|
24
|
+
"Accounting & Bookkeeping",
|
|
25
|
+
"Affiliate Marketing",
|
|
26
|
+
"Apple",
|
|
27
|
+
"Architectural Design",
|
|
28
|
+
"Arts & Crafts",
|
|
29
|
+
"Beauty & Makeup",
|
|
30
|
+
"Branding",
|
|
31
|
+
"Business Analytics & Intelligence",
|
|
32
|
+
"Business Law",
|
|
33
|
+
"Business Strategy",
|
|
34
|
+
"Career Development",
|
|
35
|
+
"Commercial Photography",
|
|
36
|
+
"Communication",
|
|
37
|
+
"Compliance",
|
|
38
|
+
"Content Marketing",
|
|
39
|
+
"Creativity",
|
|
40
|
+
"Cryptocurrency & Blockchain",
|
|
41
|
+
"Dance",
|
|
42
|
+
"Data Science",
|
|
43
|
+
"Database Design & Development",
|
|
44
|
+
"Design Tools",
|
|
45
|
+
"Digital Marketing",
|
|
46
|
+
"Digital Photography",
|
|
47
|
+
"E-Commerce",
|
|
48
|
+
"Economics",
|
|
49
|
+
"Engineering",
|
|
50
|
+
"Entrepreneurship",
|
|
51
|
+
"Esoteric Practices",
|
|
52
|
+
"Essential Tech Skills",
|
|
53
|
+
"Fashion Design",
|
|
54
|
+
"Finance",
|
|
55
|
+
"Finance Cert & Exam Prep",
|
|
56
|
+
"Financial Modeling & Analysis",
|
|
57
|
+
"Fitness",
|
|
58
|
+
"Food & Beverage",
|
|
59
|
+
"Game Design",
|
|
60
|
+
"Game Development",
|
|
61
|
+
"Gaming",
|
|
62
|
+
"General Health",
|
|
63
|
+
"Google",
|
|
64
|
+
"Graphic Design & Illustration",
|
|
65
|
+
"Growth Hacking",
|
|
66
|
+
"Happiness",
|
|
67
|
+
"Hardware",
|
|
68
|
+
"Home Improvement & Gardening",
|
|
69
|
+
"Human Resources",
|
|
70
|
+
"Humanities",
|
|
71
|
+
"Industry",
|
|
72
|
+
"Influence",
|
|
73
|
+
"Instruments",
|
|
74
|
+
"Interior Design",
|
|
75
|
+
"Investing & Trading",
|
|
76
|
+
"IT Certifications",
|
|
77
|
+
"Language Learning",
|
|
78
|
+
"Leadership",
|
|
79
|
+
"Management",
|
|
80
|
+
"Marketing Analytics & Automation",
|
|
81
|
+
"Marketing Fundamentals",
|
|
82
|
+
"Martial Arts & Self Defense",
|
|
83
|
+
"Math",
|
|
84
|
+
"Media",
|
|
85
|
+
"Meditation",
|
|
86
|
+
"Memory & Study Skills",
|
|
87
|
+
"Mental Health",
|
|
88
|
+
"Microsoft",
|
|
89
|
+
"Mobile Development",
|
|
90
|
+
"Money Management Tools",
|
|
91
|
+
"Motivation",
|
|
92
|
+
"Music Fundamentals",
|
|
93
|
+
"Music Production",
|
|
94
|
+
"Music Software",
|
|
95
|
+
"Music Techniques",
|
|
96
|
+
"Network & Security",
|
|
97
|
+
"No-Code Development",
|
|
98
|
+
"Nutrition & Diet",
|
|
99
|
+
"Online Education",
|
|
100
|
+
"Operating Systems & Servers",
|
|
101
|
+
"Operations",
|
|
102
|
+
"Oracle",
|
|
103
|
+
"Other Business",
|
|
104
|
+
"Other Design",
|
|
105
|
+
"Other Finance & Accounting",
|
|
106
|
+
"Other Health & Fitness",
|
|
107
|
+
"Other IT & Software",
|
|
108
|
+
"Other Lifestyle",
|
|
109
|
+
"Other Marketing",
|
|
110
|
+
"Other Music",
|
|
111
|
+
"Other Office Productivity",
|
|
112
|
+
"Other Personal Development",
|
|
113
|
+
"Other Photography & Video",
|
|
114
|
+
"Other Teaching & Academics",
|
|
115
|
+
"Paid Advertising",
|
|
116
|
+
"Parenting & Relationships",
|
|
117
|
+
"Personal Brand Building",
|
|
118
|
+
"Personal Growth & Wellness",
|
|
119
|
+
"Personal Productivity",
|
|
120
|
+
"Personal Transformation",
|
|
121
|
+
"Pet Care & Training",
|
|
122
|
+
"Photography",
|
|
123
|
+
"Photography Tools",
|
|
124
|
+
"Portrait Photography",
|
|
125
|
+
"Product Marketing",
|
|
126
|
+
"Productivity & Professional Skills",
|
|
127
|
+
"Programming Languages",
|
|
128
|
+
"Project Management",
|
|
129
|
+
"Public Relations",
|
|
130
|
+
"Real Estate",
|
|
131
|
+
"Religion & Spirituality",
|
|
132
|
+
"Safety & First Aid",
|
|
133
|
+
"Sales",
|
|
134
|
+
"SAP",
|
|
135
|
+
"Science",
|
|
136
|
+
"Search Engine Optimization",
|
|
137
|
+
"Self Esteem & Confidence",
|
|
138
|
+
"Social Media Marketing",
|
|
139
|
+
"Social Science",
|
|
140
|
+
"Software Development Tools",
|
|
141
|
+
"Software Engineering",
|
|
142
|
+
"Software Testing",
|
|
143
|
+
"Sports",
|
|
144
|
+
"Stress Management",
|
|
145
|
+
"Taxes",
|
|
146
|
+
"Teacher Training",
|
|
147
|
+
"Test Prep",
|
|
148
|
+
"Travel",
|
|
149
|
+
"User Experience Design",
|
|
150
|
+
"Video & Mobile Marketing",
|
|
151
|
+
"Video Design",
|
|
152
|
+
"Vocal",
|
|
153
|
+
"Vodafone",
|
|
154
|
+
"Web Design",
|
|
155
|
+
"Web Development",
|
|
156
|
+
"Yoga",
|
|
157
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Pydantic models and enums for filtering course search results on Udemy API."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Optional, Self
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field, ValidationError, field_validator, model_validator
|
|
7
|
+
|
|
8
|
+
from ..course_category import CourseCategory
|
|
9
|
+
from ..course_subcategory import CourseSubcategory
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class _Price(Enum):
|
|
13
|
+
"""Enumeration representing the possible price options for courses."""
|
|
14
|
+
|
|
15
|
+
PRICE_PAID = "price-paid"
|
|
16
|
+
PRICE_FREE = "price-free"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class _InstructionalLevel(Enum):
|
|
20
|
+
"""Enumeration representing the available instructional levels for courses."""
|
|
21
|
+
|
|
22
|
+
ALL = "all"
|
|
23
|
+
BEGINNER = "beginner"
|
|
24
|
+
INTERMEDIATE = "intermediate"
|
|
25
|
+
EXPERT = "expert"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class _Ordering(Enum):
|
|
29
|
+
"""Enumeration representing the sorting options for course search results."""
|
|
30
|
+
|
|
31
|
+
RELEVANCE = "relevance"
|
|
32
|
+
MOST_REVIEWED = "most-reviewed"
|
|
33
|
+
HIGHEST_RATED = "highest-rated"
|
|
34
|
+
NEWEST = "newest"
|
|
35
|
+
PRICE_LOW_TO_HIGH = "price-low-to-high"
|
|
36
|
+
PRICE_HIGH_TO_LOW = "price-high-to-low"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _Duration(Enum):
|
|
40
|
+
"""Enumeration representing the estimated duration categories for courses."""
|
|
41
|
+
|
|
42
|
+
SHORT = "short"
|
|
43
|
+
MEDIUM = "medium"
|
|
44
|
+
LONG = "long"
|
|
45
|
+
EXTRA_LONG = "extraLong"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class CourseFilter(BaseModel):
|
|
49
|
+
"""Pydantic model for filtering course search results on the Udemy API."""
|
|
50
|
+
|
|
51
|
+
page: Optional[int] = 1
|
|
52
|
+
page_size: Optional[int] = 10
|
|
53
|
+
search: str = ""
|
|
54
|
+
category: Optional[CourseCategory] = None
|
|
55
|
+
subcategory: Optional[CourseSubcategory] = None
|
|
56
|
+
price: _Price = None
|
|
57
|
+
is_affiliate_agreed: bool = False
|
|
58
|
+
is_fixed_priced_deals_agreed: bool = False
|
|
59
|
+
is_percentage_deals_agreed: bool = False
|
|
60
|
+
language: Optional[str] = Field(
|
|
61
|
+
default="en", pattern=r"^[a-z]{2}$"
|
|
62
|
+
) # Filter courses by alpha-2 language code
|
|
63
|
+
has_closed_caption: bool = False
|
|
64
|
+
has_coding_exercises: bool = False
|
|
65
|
+
has_simple_quiz: bool = False
|
|
66
|
+
instructional_level: _InstructionalLevel = None
|
|
67
|
+
ordering: _Ordering = None
|
|
68
|
+
ratings: str = None
|
|
69
|
+
duration: _Duration = None
|
|
70
|
+
|
|
71
|
+
@model_validator(mode="after")
|
|
72
|
+
def validate_page_and_size(self) -> Self:
|
|
73
|
+
"""
|
|
74
|
+
Validates that the combination of page and page_size does not exceed a limit.
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
ValueError: If the product of page and page_size is greater than 10000.
|
|
78
|
+
"""
|
|
79
|
+
if (self.page or 0) * (self.page_size or 0) > 10000:
|
|
80
|
+
raise ValueError("page * page_size cannot be greater than 10000")
|
|
81
|
+
return self
|
|
82
|
+
|
|
83
|
+
@field_validator("category")
|
|
84
|
+
@classmethod
|
|
85
|
+
def validate_category(cls, category: Optional[CourseCategory]) -> Optional[CourseCategory]:
|
|
86
|
+
"""
|
|
87
|
+
Validates if the selected category is present in the available options.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
category (CourseCategory, optional): The selected course category.
|
|
91
|
+
|
|
92
|
+
Raises:
|
|
93
|
+
ValidationError: If the category is invalid.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
(CourseCategory, optional): The validated category.
|
|
97
|
+
"""
|
|
98
|
+
if category and category.title not in CourseCategory.POSSIBLE_CATEGORIES:
|
|
99
|
+
error_messgae = (
|
|
100
|
+
"Invalid course category selected. Please refer to the Udemy documentation "
|
|
101
|
+
"for available categories: https://www.udemy.com/developers/affiliate/models/course-category/" # pylint: disable=line-too-long
|
|
102
|
+
)
|
|
103
|
+
raise ValidationError(error_messgae)
|
|
104
|
+
return category
|
|
105
|
+
|
|
106
|
+
@model_validator(mode="after")
|
|
107
|
+
def validate_subcategory(self) -> Self:
|
|
108
|
+
"""
|
|
109
|
+
Validates if the selected subcategory is present in the available options
|
|
110
|
+
for the parent category.
|
|
111
|
+
|
|
112
|
+
Raises:
|
|
113
|
+
ValidationError: If the subcategory is invalid or the parent category is missing.
|
|
114
|
+
"""
|
|
115
|
+
category = self.category
|
|
116
|
+
subcategory = self.subcategory
|
|
117
|
+
|
|
118
|
+
if subcategory:
|
|
119
|
+
if not category:
|
|
120
|
+
raise ValidationError("Please select a parent category for subcategory.")
|
|
121
|
+
if category.title.capitalize() not in CourseSubcategory.POSSIBLE_SUBCATEGORIES:
|
|
122
|
+
error_messgae = (
|
|
123
|
+
"Invalid course subcategory selected. Please refer to the Udemy documentation "
|
|
124
|
+
"for available categories: https://www.udemy.com/developers/affiliate/models/course-subcategory/" # pylint: disable=line-too-long
|
|
125
|
+
)
|
|
126
|
+
raise ValidationError(error_messgae)
|
|
127
|
+
return self
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Pydantic model for filtering and retrieving course reviews from the Udemy API."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from ..user import User
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ReviewFilter(BaseModel):
|
|
11
|
+
"""Pydantic model for filtering course reviews on the Udemy API."""
|
|
12
|
+
|
|
13
|
+
page: Optional[int] = 1
|
|
14
|
+
page_size: Optional[int] = 10
|
|
15
|
+
is_text_review: bool = False
|
|
16
|
+
rating: str = None
|
|
17
|
+
user: User = None
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Pydantic models representing a Lecture and nested Asset object."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from .mixins.serializers import DateTimeSerializer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Asset(DateTimeSerializer):
|
|
10
|
+
"""
|
|
11
|
+
Pydantic model for an asset associated with a lecture (e.g., video) from the Udemy API
|
|
12
|
+
response.
|
|
13
|
+
|
|
14
|
+
**Note:** This object structure is inferred from the API response and might not be explicitly
|
|
15
|
+
documented by Udemy.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
id: int
|
|
19
|
+
asset_type: str
|
|
20
|
+
title: str
|
|
21
|
+
created: datetime
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Lecture(DateTimeSerializer):
|
|
25
|
+
"""
|
|
26
|
+
Pydantic model for a Lecture object from the Udemy API response.
|
|
27
|
+
|
|
28
|
+
**Note:** All attributes except "title" are present in the API response but not
|
|
29
|
+
explicitly documented by Udemy.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
id: int
|
|
33
|
+
title: str
|
|
34
|
+
created: datetime
|
|
35
|
+
description: str
|
|
36
|
+
title_cleaned: str
|
|
37
|
+
is_published: bool
|
|
38
|
+
transcript: Optional[str] = None
|
|
39
|
+
is_downloadable: bool
|
|
40
|
+
is_free: bool
|
|
41
|
+
asset: Asset
|
|
42
|
+
sort_order: int
|
|
43
|
+
can_be_previewed: bool
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Mixins for model serialization."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any, Dict
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, model_serializer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DateTimeSerializer(BaseModel):
|
|
10
|
+
"""Mixin class for serializing datetime fields to ISO 8601 format."""
|
|
11
|
+
|
|
12
|
+
@model_serializer()
|
|
13
|
+
def serialize_datetimes(self) -> Dict[str, Any]:
|
|
14
|
+
"""
|
|
15
|
+
Serializes the model to a dictionary.
|
|
16
|
+
|
|
17
|
+
Converts datetime fields to ISO 8601 format for JSON compatibility.
|
|
18
|
+
"""
|
|
19
|
+
model_dict = {}
|
|
20
|
+
for field_name, _ in self.model_fields.items():
|
|
21
|
+
field_value = getattr(self, field_name)
|
|
22
|
+
if isinstance(field_value, datetime):
|
|
23
|
+
model_dict[field_name] = field_value.isoformat()
|
|
24
|
+
else:
|
|
25
|
+
model_dict[field_name] = field_value
|
|
26
|
+
return model_dict
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Pydantic model representing a Quiz object as inferred from the Udemy API response."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Quiz(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
Pydantic model representing a Quiz object from the Udemy API response.
|
|
11
|
+
|
|
12
|
+
**Note:** This object structure is inferred from the API response and might not be explicitly
|
|
13
|
+
documented by Udemy.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
id: int
|
|
17
|
+
title: str
|
|
18
|
+
type: str
|
|
19
|
+
created: datetime
|
|
20
|
+
description: str
|
|
21
|
+
title_cleaned: str
|
|
22
|
+
is_published: bool
|
|
23
|
+
sort_order: int
|
|
24
|
+
object_index: int
|
|
25
|
+
is_draft: bool
|
|
26
|
+
version: int
|
|
27
|
+
duration: int
|
|
28
|
+
pass_percent: float
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pydemy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for interacting with the Udemy Affiliate API.
|
|
5
|
+
Home-page: https://github.com/robelasefa/pydemy
|
|
6
|
+
Author: Robel Asefa
|
|
7
|
+
Author-email: Robel Asefa <mertigenet@gmail.com>
|
|
8
|
+
Project-URL: Homepage, https://github.com/robelasefa/pydemy
|
|
9
|
+
Project-URL: Issues, https://github.com/robelasefa/pydemy/issues
|
|
10
|
+
Keywords: udemy,api,courses,education
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Education
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
20
|
+
Classifier: Operating System :: POSIX
|
|
21
|
+
Classifier: Operating System :: Unix
|
|
22
|
+
Classifier: Operating System :: MacOS
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENCE
|
|
26
|
+
Requires-Dist: requests~=2.32.3
|
|
27
|
+
Requires-Dist: pydantic~=2.8.2
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: black; extra == "dev"
|
|
30
|
+
Requires-Dist: isort; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff; extra == "dev"
|
|
32
|
+
Requires-Dist: pylint; extra == "dev"
|
|
33
|
+
|
|
34
|
+
# Pydemy
|
|
35
|
+
|
|
36
|
+
Pydemy provides a convenient way to interact with the **[Udemy Affiliate API](https://www.udemy.com/developers/affiliate)** from your Python applications. You can use Pydemy to search for courses, retrieve course details, fetch reviews, and potentially explore other functionalities offered by the API.
|
|
37
|
+
|
|
38
|
+
## Udemy API Support
|
|
39
|
+
|
|
40
|
+
Pydemy currently supports the **Udemy Affiliate API v2.0**. This API allows developers to access public information about Udemy courses.
|
|
41
|
+
|
|
42
|
+
**Note**: The [Udemy Instructor API](https://www.udemy.com/developers/instructor/), which provides functionalities specific to course creation and management, is not currently supported by Pydemy.
|
|
43
|
+
|
|
44
|
+
## Main Features
|
|
45
|
+
|
|
46
|
+
- **Search for Courses**: Easily search for courses based on various criteria like keywords, categories, or
|
|
47
|
+
price filters.
|
|
48
|
+
- **Get Detailed Course Information**: Retrieve comprehensive details about a specific course, including
|
|
49
|
+
title, instructor, ratings, curriculum, and more.
|
|
50
|
+
- **Fetch Course Reviews**: Gain valuable insights into student experiences by fetching and analyzing reviews
|
|
51
|
+
for particular course.
|
|
52
|
+
|
|
53
|
+
## Getting Started
|
|
54
|
+
|
|
55
|
+
1. **Obtain API Credentials**:
|
|
56
|
+
Visit [Udemy API Clients](https://www.udemy.com/user/edit-api-clients/) to create a new API client and obtain your `clientID` and `clientSecret`.
|
|
57
|
+
|
|
58
|
+
2. **Installation**:
|
|
59
|
+
Install the library using pip:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install pydemy
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
3. **Usage**:
|
|
66
|
+
Import the `UdemyClient` class:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from pydemy import UdemyClient
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Initialize the client with your API credentials:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
client_id = "YOUR_CLIENT_ID"
|
|
76
|
+
client_secret = "YOUR_CLIENT_SECRET"
|
|
77
|
+
|
|
78
|
+
client = UdemyClient(client_id=client_id, client_secret=client_secret)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quickstart
|
|
82
|
+
|
|
83
|
+
Here is an example that demonstrates how to use the `UdemyClient` instance to retrieve information about public courses.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
client = UdemyClient(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
|
|
87
|
+
|
|
88
|
+
# Get a list of public courses (replace '4534650' with a specific course ID for details)
|
|
89
|
+
courses = client.get_public_curriculum_list(course_id=4534650)
|
|
90
|
+
|
|
91
|
+
# Print course titles
|
|
92
|
+
for course in courses:
|
|
93
|
+
print(course.title)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
We welcome contributions from the community! If you have bug fixes, improvements, or new features, feel free to submit a pull request. For detailed guidelines on contributing, please refer to the [CONTRIBUTING.rst](https://github.com/robelasefa/pydemy/blob/main/CONTRIBUTING.rst) file.
|
|
99
|
+
|
|
100
|
+
Here's a brief overview:
|
|
101
|
+
|
|
102
|
+
- Fork the repository.
|
|
103
|
+
- Create a new branch for your changes.
|
|
104
|
+
- Implement your changes and add unit tests if applicable.
|
|
105
|
+
- Follow consistent coding style.
|
|
106
|
+
- Submit a pull request with a clear description of your changes.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
This project is licensed under the MIT License - see the **[LICENSE.md](https://github.com/robelasefa/pydemy/blob/main/LICENSE)** file for details.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
LICENCE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
pydemy/__init__.py
|
|
6
|
+
pydemy/client.py
|
|
7
|
+
pydemy/exceptions.py
|
|
8
|
+
pydemy.egg-info/PKG-INFO
|
|
9
|
+
pydemy.egg-info/SOURCES.txt
|
|
10
|
+
pydemy.egg-info/dependency_links.txt
|
|
11
|
+
pydemy.egg-info/requires.txt
|
|
12
|
+
pydemy.egg-info/top_level.txt
|
|
13
|
+
pydemy/models/__init__.py
|
|
14
|
+
pydemy/models/chapter.py
|
|
15
|
+
pydemy/models/course.py
|
|
16
|
+
pydemy/models/course_category.py
|
|
17
|
+
pydemy/models/course_review.py
|
|
18
|
+
pydemy/models/course_subcategory.py
|
|
19
|
+
pydemy/models/lecture.py
|
|
20
|
+
pydemy/models/quiz.py
|
|
21
|
+
pydemy/models/user.py
|
|
22
|
+
pydemy/models/filters/__init__.py
|
|
23
|
+
pydemy/models/filters/course_filters.py
|
|
24
|
+
pydemy/models/filters/review_filters.py
|
|
25
|
+
pydemy/models/mixins/__init__.py
|
|
26
|
+
pydemy/models/mixins/serializers.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pydemy
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pydemy"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Python library for interacting with the Udemy Affiliate API."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
keywords=["udemy", "api", "courses", "education"]
|
|
13
|
+
dependencies = ["requests~=2.32.3", "pydantic~=2.8.2"]
|
|
14
|
+
authors = [{ name = "Robel Asefa", email = "mertigenet@gmail.com" }]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Topic :: Education",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Operating System :: Microsoft :: Windows",
|
|
25
|
+
"Operating System :: POSIX",
|
|
26
|
+
"Operating System :: Unix",
|
|
27
|
+
"Operating System :: MacOS",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = ["black", "isort", "ruff", "pylint"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/robelasefa/pydemy"
|
|
35
|
+
Issues = "https://github.com/robelasefa/pydemy/issues"
|
|
36
|
+
|
|
37
|
+
[tool.black]
|
|
38
|
+
line-length = 99
|
|
39
|
+
target-version = ['py310']
|
|
40
|
+
|
|
41
|
+
[tool.isort]
|
|
42
|
+
profile = "black"
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
fix = false
|
|
46
|
+
output-format = "grouped"
|
|
47
|
+
line-length = 99
|
pydemy-0.1.0/setup.cfg
ADDED
pydemy-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r") as f:
|
|
4
|
+
long_description = f.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="pydemy",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
description="A Python library for interacting with the Udemy Affiliate API.",
|
|
10
|
+
long_description=long_description,
|
|
11
|
+
long_description_content_type="text/markdown",
|
|
12
|
+
author="Robel Asefa",
|
|
13
|
+
author_email="mertigenet@gmail.com",
|
|
14
|
+
url="https://github.com/robelasefa/pydemy",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
install_requires=["requests~=2.32.3", "pydantic~=2.8.2"],
|
|
17
|
+
license='MIT',
|
|
18
|
+
)
|