films-sdk-sbre 0.0.1__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.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: films_sdk_sbre
3
+ Version: 0.0.1
4
+ Summary: SDK Python pour accéder à l’API MovieLens (Data Analysts/Data Scientists friendly)
5
+ Author: [BELLO Soboure]
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.13
11
+ Requires-Dist: httpx>=0.28.1
12
+ Requires-Dist: pydantic>=2.11.3
13
+ Requires-Dist: backoff>=2.2.1
14
+ Requires-Dist: numpy>=2.2.4
15
+ Requires-Dist: pandas>=2.2.3
16
+ Requires-Dist: python-dotenv
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["setuptools>=80.9.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "films_sdk_sbre"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="[BELLO Soboure]" },
10
+ ]
11
+ description = "SDK Python pour accéder à l’API MovieLens (Data Analysts/Data Scientists friendly)"
12
+ requires-python = ">=3.13"
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ 'httpx>=0.28.1',
21
+ 'pydantic>=2.11.3',
22
+ 'backoff>=2.2.1',
23
+ 'numpy>=2.2.4',
24
+ 'pandas>=2.2.3',
25
+ 'python-dotenv',
26
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ from .film_client import MovieClient
2
+ from .film_config import MovieConfig
@@ -0,0 +1,129 @@
1
+ import httpx
2
+ from typing import Optional, List, Literal, Union
3
+
4
+ from .schemas import MovieSimple, MovieDetailed, RatingSimple, TagSimple, LinkSimple, AnalyticsResponse
5
+ from .film_config import MovieConfig
6
+
7
+ import pandas as pd
8
+
9
+
10
+ class MovieClient:
11
+ def __init__(self, config: Optional[MovieConfig] = None):
12
+ self.config = config or MovieConfig()
13
+ self.movie_base_url = self.config.movie_base_url
14
+
15
+ def _format_output(self, data, model, output_format: Literal["pydantic", "dict", "pandas"]):
16
+ if output_format == "pydantic":
17
+ return [model(**item) for item in data]
18
+ elif output_format == "dict":
19
+ return data
20
+ elif output_format == "pandas":
21
+ import pandas as pd
22
+ return pd.DataFrame(data)
23
+ else:
24
+ raise ValueError("Invalid output_format. Choose from 'pydantic', 'dict', or 'pandas'.")
25
+
26
+ def health_check(self) -> dict:
27
+ url = f"{self.movie_base_url}/"
28
+ response = httpx.get(url)
29
+ response.raise_for_status()
30
+ return response.json()
31
+
32
+ def get_movie(self, movie_id: int) -> MovieDetailed:
33
+ url = f"{self.movie_base_url}/movies/{movie_id}"
34
+ response = httpx.get(url)
35
+ response.raise_for_status()
36
+ return MovieDetailed(**response.json())
37
+
38
+ def list_movies(
39
+ self,
40
+ skip: int = 0,
41
+ limit: int = 100,
42
+ title: Optional[str] = None,
43
+ genre: Optional[str] = None,
44
+ output_format: Literal["pydantic", "dict", "pandas"] = "pydantic"
45
+ ) -> Union[List[MovieSimple], List[dict], "pd.DataFrame"]:
46
+ url = f"{self.movie_base_url}/movies"
47
+ params = {"skip": skip, "limit": limit}
48
+ if title:
49
+ params["title"] = title
50
+ if genre:
51
+ params["genre"] = genre
52
+ response = httpx.get(url, params=params)
53
+ response.raise_for_status()
54
+ return self._format_output(response.json(), MovieSimple, output_format)
55
+
56
+ def get_rating(self, user_id: int, movie_id: int) -> RatingSimple:
57
+ url = f"{self.movie_base_url}/ratings/{user_id}/{movie_id}"
58
+ response = httpx.get(url)
59
+ response.raise_for_status()
60
+ return RatingSimple(**response.json())
61
+
62
+ def list_ratings(
63
+ self,
64
+ skip: int = 0,
65
+ limit: int = 100,
66
+ movie_id: Optional[int] = None,
67
+ user_id: Optional[int] = None,
68
+ min_rating: Optional[float] = None,
69
+ output_format: Literal["pydantic", "dict", "pandas"] = "pydantic"
70
+ ) -> Union[List[RatingSimple], List[dict], "pd.DataFrame"]:
71
+ url = f"{self.movie_base_url}/ratings"
72
+ params = {"skip": skip, "limit": limit}
73
+ if movie_id:
74
+ params["movie_id"] = movie_id
75
+ if user_id:
76
+ params["user_id"] = user_id
77
+ if min_rating:
78
+ params["min_rating"] = min_rating
79
+ response = httpx.get(url, params=params)
80
+ response.raise_for_status()
81
+ return self._format_output(response.json(), RatingSimple, output_format)
82
+
83
+ def get_tag(self, user_id: int, movie_id: int, tag_text: str) -> TagSimple:
84
+ url = f"{self.movie_base_url}/tags/{user_id}/{movie_id}/{tag_text}"
85
+ response = httpx.get(url)
86
+ response.raise_for_status()
87
+ return TagSimple(**response.json())
88
+
89
+ def list_tags(
90
+ self,
91
+ skip: int = 0,
92
+ limit: int = 100,
93
+ movie_id: Optional[int] = None,
94
+ user_id: Optional[int] = None,
95
+ output_format: Literal["pydantic", "dict", "pandas"] = "pydantic"
96
+ ) -> Union[List[TagSimple], List[dict], "pd.DataFrame"]:
97
+ url = f"{self.movie_base_url}/tags"
98
+ params = {"skip": skip, "limit": limit}
99
+ if movie_id:
100
+ params["movie_id"] = movie_id
101
+ if user_id:
102
+ params["user_id"] = user_id
103
+ response = httpx.get(url, params=params)
104
+ response.raise_for_status()
105
+ return self._format_output(response.json(), TagSimple, output_format)
106
+
107
+ def get_link(self, movie_id: int) -> LinkSimple:
108
+ url = f"{self.movie_base_url}/links/{movie_id}"
109
+ response = httpx.get(url)
110
+ response.raise_for_status()
111
+ return LinkSimple(**response.json())
112
+
113
+ def list_links(
114
+ self,
115
+ skip: int = 0,
116
+ limit: int = 100,
117
+ output_format: Literal["pydantic", "dict", "pandas"] = "pydantic"
118
+ ) -> Union[List[LinkSimple], List[dict], "pd.DataFrame"]:
119
+ url = f"{self.movie_base_url}/links"
120
+ params = {"skip": skip, "limit": limit}
121
+ response = httpx.get(url, params=params)
122
+ response.raise_for_status()
123
+ return self._format_output(response.json(), LinkSimple, output_format)
124
+
125
+ def get_analytics(self) -> AnalyticsResponse:
126
+ url = f"{self.movie_base_url}/analytics"
127
+ response = httpx.get(url)
128
+ response.raise_for_status()
129
+ return AnalyticsResponse(**response.json())
@@ -0,0 +1,46 @@
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv()
5
+
6
+ class MovieConfig:
7
+ """Classe de configuration contenant des arguments pour le client SDK.
8
+
9
+ Contient la configuration de l'URL de base et du backoff progressif.
10
+ """
11
+
12
+ movie_base_url: str
13
+ movie_backoff: bool
14
+ movie_backoff_max_time: int
15
+
16
+ def __init__(
17
+ self,
18
+ movie_base_url: str = None,
19
+ backoff: bool = True,
20
+ backoff_max_time: int = 30,
21
+ ):
22
+ """Constructeur pour la classe de configuration.
23
+
24
+ Contient des valeurs d'initialisation pour écraser les valeurs par défaut.
25
+
26
+ Args:
27
+ movie_base_url (optional):
28
+ L'URL de base à utiliser pour tous les appels d'API. Transmettez-la ou définissez-la dans une variable d'environnement.
29
+ movie_backoff:
30
+ Un booléen qui détermine si le SDK doit réessayer l'appel en utilisant un backoff lorsque des erreurs se produisent.
31
+ movie_backoff_max_time:
32
+ Le nombre maximal de secondes pendant lesquelles le SDK doit continuer à essayer un appel API avant de s'arrêter.
33
+ """
34
+
35
+ self.movie_base_url = movie_base_url or os.getenv("MOVIE_API_BASE_URL")
36
+ print(f"MOVIE_API_BASE_URL in MovieConfig init: {self.movie_base_url}")
37
+
38
+ if not self.movie_base_url:
39
+ raise ValueError("L'URL de base est requise. Définissez la variable d'environnement MOVIE_API_BASE_URL.")
40
+
41
+ self.movie_backoff = backoff
42
+ self.movie_backoff_max_time = backoff_max_time
43
+
44
+ def __str__(self):
45
+ """Fonction Stringify pour renvoyer le contenu de l'objet de configuration pour la journalisation"""
46
+ return f"{self.movie_base_url} {self.movie_backoff} {self.movie_backoff_max_time}"
@@ -0,0 +1 @@
1
+ from .schemas import *
@@ -0,0 +1,97 @@
1
+ from pydantic import BaseModel
2
+ from typing import Optional, List
3
+
4
+
5
+ # --- Schémas secondaires ---
6
+
7
+ class RatingBase(BaseModel):
8
+ userId: int
9
+ movieId: int
10
+ rating: float
11
+ timestamp: int
12
+
13
+ class Config:
14
+ orm_mode = True
15
+
16
+
17
+ class TagBase(BaseModel):
18
+ userId: int
19
+ movieId: int
20
+ tag: str
21
+ timestamp: int
22
+
23
+ class Config:
24
+ orm_mode = True
25
+
26
+
27
+ class LinkBase(BaseModel):
28
+ imdbId: Optional[str]
29
+ tmdbId: Optional[int]
30
+
31
+ class Config:
32
+ orm_mode = True
33
+
34
+
35
+ # --- Schéma principal pour Movie ---
36
+ class MovieBase(BaseModel):
37
+ movieId: int
38
+ title: str
39
+ genres: Optional[str] = None
40
+
41
+ class Config:
42
+ orm_mode = True
43
+
44
+
45
+ class MovieDetailed(MovieBase):
46
+ ratings: List[RatingBase] = []
47
+ tags: List[TagBase] = []
48
+ link: Optional[LinkBase] = None
49
+
50
+
51
+ # --- Schéma pour liste de films (sans détails imbriqués) ---
52
+ class MovieSimple(BaseModel):
53
+ movieId: int
54
+ title: str
55
+ genres: Optional[str]
56
+
57
+ class Config:
58
+ orm_mode = True
59
+
60
+
61
+ # --- Pour les endpoints de /ratings et /tags si appelés seuls ---
62
+ class RatingSimple(BaseModel):
63
+ userId: int
64
+ movieId: int
65
+ rating: float
66
+ timestamp: int
67
+
68
+ class Config:
69
+ orm_mode = True
70
+
71
+
72
+ class TagSimple(BaseModel):
73
+ userId: int
74
+ movieId: int
75
+ tag: str
76
+ timestamp: int
77
+
78
+ class Config:
79
+ orm_mode = True
80
+
81
+
82
+ class LinkSimple(BaseModel):
83
+ movieId: int
84
+ imdbId: Optional[str]
85
+ tmdbId: Optional[int]
86
+
87
+ class Config:
88
+ orm_mode = True
89
+
90
+ class AnalyticsResponse(BaseModel):
91
+ movie_count: int
92
+ rating_count: int
93
+ tag_count: int
94
+ link_count: int
95
+
96
+ class Config:
97
+ orm_mode = True
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: films_sdk_sbre
3
+ Version: 0.0.1
4
+ Summary: SDK Python pour accéder à l’API MovieLens (Data Analysts/Data Scientists friendly)
5
+ Author: [BELLO Soboure]
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.13
11
+ Requires-Dist: httpx>=0.28.1
12
+ Requires-Dist: pydantic>=2.11.3
13
+ Requires-Dist: backoff>=2.2.1
14
+ Requires-Dist: numpy>=2.2.4
15
+ Requires-Dist: pandas>=2.2.3
16
+ Requires-Dist: python-dotenv
@@ -0,0 +1,11 @@
1
+ pyproject.toml
2
+ src/films_sdk_sbre/__init__.py
3
+ src/films_sdk_sbre/film_client.py
4
+ src/films_sdk_sbre/film_config.py
5
+ src/films_sdk_sbre.egg-info/PKG-INFO
6
+ src/films_sdk_sbre.egg-info/SOURCES.txt
7
+ src/films_sdk_sbre.egg-info/dependency_links.txt
8
+ src/films_sdk_sbre.egg-info/requires.txt
9
+ src/films_sdk_sbre.egg-info/top_level.txt
10
+ src/films_sdk_sbre/schemas/__init__.py
11
+ src/films_sdk_sbre/schemas/schemas.py
@@ -0,0 +1,6 @@
1
+ httpx>=0.28.1
2
+ pydantic>=2.11.3
3
+ backoff>=2.2.1
4
+ numpy>=2.2.4
5
+ pandas>=2.2.3
6
+ python-dotenv
@@ -0,0 +1 @@
1
+ films_sdk_sbre