nhl-api-py 2.2.0__tar.gz → 2.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nhl-api-py
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: NHL API. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods for easy data loading in Pandas or any ML applications.
5
5
  Home-page: https://github.com/coreyjs/nhl-api-py
6
6
  License: GPL-3.0-or-later
@@ -1,3 +1,3 @@
1
1
  # Should this be driven by the main pyproject.toml file? yes, is it super convoluted? yes, can it wait? sure
2
2
 
3
- __version__ = "2.2.0"
3
+ __version__ = "2.2.1"
@@ -0,0 +1,45 @@
1
+ from typing import List
2
+
3
+ from nhlpy.http_client import HttpClient
4
+
5
+
6
+ class Misc:
7
+ def __init__(self, http_client: HttpClient) -> None:
8
+ self.client = http_client
9
+
10
+ def glossary(self) -> List[dict]:
11
+ """
12
+ Get the glossary for the NHL API.
13
+ :return: dict
14
+ """
15
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/glossary?sort=fullName").json()[
16
+ "data"
17
+ ]
18
+
19
+ def config(self) -> dict:
20
+ """
21
+ Seems to be various options for the filters?.
22
+ :return: dict
23
+ """
24
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/config").json()
25
+
26
+ def countries(self) -> List[dict]:
27
+ """
28
+ Get the countries for the NHL API.
29
+ :return: dict
30
+ """
31
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/country").json()["data"]
32
+
33
+ def season_specific_rules_and_info(self) -> List[dict]:
34
+ """
35
+ Get the season specific rules and info for the NHL API.
36
+ :return: dict
37
+ """
38
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/season").json()["data"]
39
+
40
+ def draft_year_and_rounds(self) -> List[dict]:
41
+ """
42
+ Get the draft year and rounds for the NHL API. This only has "id", "draftYear" and "rounds count".
43
+ :return: dict
44
+ """
45
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/draft").json()["data"]
@@ -0,0 +1,92 @@
1
+ import urllib.parse
2
+ import json
3
+ from typing import List
4
+
5
+
6
+ from nhlpy.http_client import HttpClient
7
+
8
+
9
+ class Stats:
10
+ def __init__(self, http_client: HttpClient):
11
+ self.client = http_client
12
+
13
+ def club_stats_season(self, team_abbr: str) -> dict:
14
+ """
15
+ This seems to return gameTypes for every season the team was in existence. Maybe its useful?
16
+ :param team_abbr: The 3 letter abbreviation of the team. BUF, TOR, etc
17
+ :return: dict
18
+ """
19
+ return self.client.get(resource=f"club-stats-season/{team_abbr}").json()
20
+
21
+ def player_career_stats(self, player_id: int) -> dict:
22
+ """
23
+ This returns the career stats for a player as well as player information.
24
+
25
+ example: https://api-web.nhle.com/v1/player/8481528/landing
26
+
27
+ :param player_id: The player_id for the player you want the stats for.
28
+ :return: dict
29
+ """
30
+ return self.client.get(resource=f"player/{player_id}/landing").json()
31
+
32
+ def team_summary(
33
+ self,
34
+ start_season: str,
35
+ end_season: str,
36
+ game_type_id: int = 2,
37
+ is_game: bool = False,
38
+ is_aggregate: bool = False,
39
+ sort_expr: List[dict] = None,
40
+ start: int = 0,
41
+ limit: int = 50,
42
+ fact_cayenne_exp: str = "gamesPlayed>1",
43
+ default_cayenne_exp: str = None,
44
+ ) -> List[dict]:
45
+ """
46
+ Example: c.stats.team_summary(start_season="20202021", end_season="20212022", game_type_id=2)
47
+ c.stats.team_summary(start_season="20202021", end_season="20212022")
48
+ :param start_season: Season id, in format 20202021, 20212022, etc, that will be the start of the range. This
49
+ allows for searching over multiple season. If you just want one season, set start_season and end_season.
50
+ :param end_season: Season id for the end range.
51
+ :param game_type_id: 2 is for regular season, 3 is for playoffs. I think 1 is for preseason.
52
+ :param is_game: (dev notes: not sure what this is, its part of the api call)
53
+ :param is_aggregate:
54
+ :param sort_expr: A list of key/value pairs of properties and their sort direction. For Example this defaults
55
+ to [
56
+ {"property":"points","direction":"DESC"},
57
+ {"property":"wins","direction":"DESC"},
58
+ {"property":"teamId","direction":"ASC"}
59
+ ]
60
+ :param start:
61
+ :param limit:
62
+ :param fact_cayenne_exp: An expression used by apache cayenne. This defaults to 'gamesPlayed>=1'.
63
+ You can experiment at will, this was taken from the nhl.com website.
64
+ :param default_cayenne_exp: Similar to above, I believe this provides a filter for the data returned.
65
+ This will look something like: "gameTypeId=2 and seasonId<=20232024 and seasonId>=20232024".
66
+
67
+ If this value is supplied, it will override a generated one, giving the user ability to experiment.
68
+ :return:
69
+ """
70
+ q_params = {
71
+ "isAggregate": is_aggregate,
72
+ "isGame": is_game,
73
+ "start": start,
74
+ "limit": limit,
75
+ "factCayenneExp": fact_cayenne_exp,
76
+ }
77
+
78
+ if not sort_expr:
79
+ sort_expr = [
80
+ {"property": "points", "direction": "DESC"},
81
+ {"property": "wins", "direction": "DESC"},
82
+ {"property": "teamId", "direction": "ASC"},
83
+ ]
84
+ q_params["sort"] = urllib.parse.quote(json.dumps(sort_expr))
85
+
86
+ if not default_cayenne_exp:
87
+ default_cayenne_exp = f"gameTypeId={game_type_id} and seasonId<={end_season} and seasonId>={start_season}"
88
+ q_params["cayenneExp"] = default_cayenne_exp
89
+
90
+ return self.client.get_by_url("https://api.nhle.com/stats/rest/en/team/summary", query_params=q_params).json()[
91
+ "data"
92
+ ]
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import importlib.resources
3
-
3
+ from warnings import warn
4
4
  from typing import List
5
5
 
6
6
  from nhlpy.http_client import HttpClient
@@ -12,12 +12,18 @@ class Teams:
12
12
  self.base_url = "https://api.nhle.com"
13
13
  self.api_ver = "/stats/rest/"
14
14
 
15
+ # todo deprecate this
15
16
  def team_stats_summary(self, lang="en") -> List[dict]:
16
17
  """
17
- I really dont know what this endpoint does. It returns a list of dicts with team stats.
18
+ I really don't know what this endpoint does. It returns a list of dicts with team stats.
18
19
  :param lang: Language param. 'en' for English, 'fr' for French
19
20
  :return:
20
21
  """
22
+ warn(
23
+ "This endpoint will be deprecated in the future. Use stats.team_summary() instead.",
24
+ DeprecationWarning,
25
+ stacklevel=2,
26
+ )
21
27
  return self.client.get_by_url(full_resource=f"{self.base_url}{self.api_ver}{lang}/team/summary").json()["data"]
22
28
 
23
29
  def teams_info(self) -> dict:
@@ -41,3 +47,10 @@ class Teams:
41
47
  :return:
42
48
  """
43
49
  return self.client.get(resource=f"roster/{team_abbr}/{season}").json()
50
+
51
+ def all_franchises(self) -> List[dict]:
52
+ """
53
+ Returns a list of all past and current NHL franchises. This includes ones long forgotten.
54
+ :return:
55
+ """
56
+ return self.client.get_by_url(full_resource="https://api.nhle.com/stats/rest/en/franchise").json()["data"]
@@ -23,13 +23,14 @@ class HttpClient:
23
23
 
24
24
  return r
25
25
 
26
- def get_by_url(self, full_resource: str) -> httpx.request:
26
+ def get_by_url(self, full_resource: str, query_params: dict = None) -> httpx.request:
27
27
  """
28
28
  Private method to make a get request to any HTTP resource. This wraps the lib httpx functionality.
29
+ :param query_params:
29
30
  :param full_resource: The full resource to get.
30
31
  :return:
31
32
  """
32
- r: httpx.request = httpx.get(url=full_resource, follow_redirects=True)
33
+ r: httpx.request = httpx.get(url=full_resource, params=query_params, follow_redirects=True)
33
34
 
34
35
  if self._config.verbose:
35
36
  logging.info(f"API URL: {r.url}")
@@ -1,4 +1,4 @@
1
- from nhlpy.api import teams, standings, schedule, game_center
1
+ from nhlpy.api import teams, standings, schedule, game_center, stats, misc
2
2
  from nhlpy.http_client import HttpClient
3
3
  from nhlpy.config import ClientConfig
4
4
 
@@ -24,3 +24,5 @@ class NHLClient:
24
24
  self.standings = standings.Standings(http_client=self._http_client)
25
25
  self.schedule = schedule.Schedule(http_client=self._http_client)
26
26
  self.game_center = game_center.GameCenter(http_client=self._http_client)
27
+ self.stats = stats.Stats(http_client=self._http_client)
28
+ self.misc = misc.Misc(http_client=self._http_client)
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "nhl-api-py"
7
- version = "2.2.0"
7
+ version = "2.2.1"
8
8
  description = "NHL API. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods for easy data loading in Pandas or any ML applications."
9
9
  authors = ["Corey Schaf <cschaf@gmail.com>"]
10
10
  readme = "README.md"
File without changes
File without changes
File without changes