notifox 0.1.0__tar.gz → 0.1.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.

Potentially problematic release.


This version of notifox might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notifox
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Official Python SDK for Notifox alerting API
5
5
  Author: Mathis Van Eetvelde
6
6
  License: MIT
@@ -66,14 +66,18 @@ from notifox import (
66
66
  NotifoxConnectionError
67
67
  )
68
68
 
69
+ client = NotifoxClient(api_key="your_api_key")
70
+
69
71
  try:
70
- client.send_alert(audience=["admin"], alert="Alert")
72
+ client.send_alert(audience="admin", alert="System is running low on memory")
71
73
  except NotifoxAuthenticationError:
72
- pass
74
+ print("Authentication failed. Check your API key.")
73
75
  except NotifoxRateLimitError:
74
- pass
76
+ print("Rate limit exceeded. Please wait before sending more alerts.")
75
77
  except NotifoxAPIError as e:
76
- print(f"{e.status_code}: {e.response_text}")
78
+ print(f"API error ({e.status_code}): {e.response_text}")
79
+ except NotifoxConnectionError as e:
80
+ print(f"Connection failed: {e}")
77
81
  ```
78
82
 
79
83
  Available exceptions:
@@ -50,14 +50,18 @@ from notifox import (
50
50
  NotifoxConnectionError
51
51
  )
52
52
 
53
+ client = NotifoxClient(api_key="your_api_key")
54
+
53
55
  try:
54
- client.send_alert(audience=["admin"], alert="Alert")
56
+ client.send_alert(audience="admin", alert="System is running low on memory")
55
57
  except NotifoxAuthenticationError:
56
- pass
58
+ print("Authentication failed. Check your API key.")
57
59
  except NotifoxRateLimitError:
58
- pass
60
+ print("Rate limit exceeded. Please wait before sending more alerts.")
59
61
  except NotifoxAPIError as e:
60
- print(f"{e.status_code}: {e.response_text}")
62
+ print(f"API error ({e.status_code}): {e.response_text}")
63
+ except NotifoxConnectionError as e:
64
+ print(f"Connection failed: {e}")
61
65
  ```
62
66
 
63
67
  Available exceptions:
@@ -1,10 +1,10 @@
1
1
  from .client import NotifoxClient
2
2
  from .exceptions import (
3
- NotifoxError,
4
3
  NotifoxAPIError,
5
4
  NotifoxAuthenticationError,
5
+ NotifoxConnectionError,
6
+ NotifoxError,
6
7
  NotifoxRateLimitError,
7
- NotifoxConnectionError
8
8
  )
9
9
 
10
10
  __all__ = [
@@ -15,4 +15,4 @@ __all__ = [
15
15
  "NotifoxRateLimitError",
16
16
  "NotifoxConnectionError",
17
17
  ]
18
- __version__ = "0.1.0"
18
+ __version__ = "0.1.1"
@@ -1,27 +1,28 @@
1
1
  # notifox/client.py
2
2
  import os
3
- from typing import Dict, Any, Optional
3
+ from typing import Any, Dict, Optional
4
+
4
5
  import requests
5
6
  from requests.adapters import HTTPAdapter
6
7
  from urllib3.util.retry import Retry
7
8
 
8
9
  from .exceptions import (
9
- NotifoxError,
10
10
  NotifoxAPIError,
11
11
  NotifoxAuthenticationError,
12
+ NotifoxConnectionError,
13
+ NotifoxError,
12
14
  NotifoxRateLimitError,
13
- NotifoxConnectionError
14
15
  )
15
16
 
16
17
 
17
18
  class NotifoxClient:
18
19
  """
19
20
  Python SDK for Notifox alerting API.
20
-
21
+
21
22
  Examples:
22
23
  client = NotifoxClient(api_key="your_api_key")
23
24
  client.send_alert(audience="user1", alert="Server down!")
24
-
25
+
25
26
  client = NotifoxClient() # Reads from NOTIFOX_API_KEY env var
26
27
  """
27
28
 
@@ -34,7 +35,7 @@ class NotifoxClient:
34
35
  ):
35
36
  """
36
37
  Initialize the Notifox client.
37
-
38
+
38
39
  Args:
39
40
  api_key: Your Notifox API key. If not provided, will attempt to read from
40
41
  the NOTIFOX_API_KEY environment variable.
@@ -48,10 +49,10 @@ class NotifoxClient:
48
49
  "API key is required. Provide it as an argument or set the "
49
50
  "NOTIFOX_API_KEY environment variable."
50
51
  )
51
-
52
+
52
53
  self.base_url = base_url.rstrip("/")
53
54
  self.timeout = timeout
54
-
55
+
55
56
  # Create a session with retry logic
56
57
  self.session = requests.Session()
57
58
  retry_strategy = Retry(
@@ -65,13 +66,13 @@ class NotifoxClient:
65
66
  def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
66
67
  """
67
68
  Handle API response and raise appropriate exceptions for errors.
68
-
69
+
69
70
  Args:
70
71
  response: The HTTP response from the API
71
-
72
+
72
73
  Returns:
73
74
  The JSON response data
74
-
75
+
75
76
  Raises:
76
77
  NotifoxAuthenticationError: For 401 or 403 status codes
77
78
  NotifoxRateLimitError: For 429 status code
@@ -83,21 +84,21 @@ class NotifoxClient:
83
84
  status_code=response.status_code,
84
85
  response_text=response.text
85
86
  )
86
-
87
+
87
88
  if response.status_code == 429:
88
89
  raise NotifoxRateLimitError(
89
90
  "Rate limit exceeded. Please try again later.",
90
91
  status_code=response.status_code,
91
92
  response_text=response.text
92
93
  )
93
-
94
+
94
95
  if response.status_code >= 400:
95
96
  raise NotifoxAPIError(
96
97
  f"API error: {response.status_code} - {response.text}",
97
98
  status_code=response.status_code,
98
99
  response_text=response.text
99
100
  )
100
-
101
+
101
102
  return response.json()
102
103
 
103
104
  def send_alert(
@@ -107,14 +108,14 @@ class NotifoxClient:
107
108
  ) -> Dict[str, Any]:
108
109
  """
109
110
  Sends an alert to the specified audience.
110
-
111
+
111
112
  Args:
112
113
  audience: Audience identifier (e.g., mike, devops, support)
113
114
  alert: The alert message to send
114
-
115
+
115
116
  Returns:
116
117
  API response as a dictionary
117
-
118
+
118
119
  Raises:
119
120
  NotifoxAuthenticationError: If authentication fails
120
121
  NotifoxRateLimitError: If rate limit is exceeded
@@ -139,8 +140,8 @@ class NotifoxClient:
139
140
  except requests.exceptions.Timeout:
140
141
  raise NotifoxConnectionError(
141
142
  f"Request timed out after {self.timeout} seconds"
142
- )
143
+ ) from None
143
144
  except requests.exceptions.ConnectionError as e:
144
- raise NotifoxConnectionError(f"Connection error: {str(e)}")
145
+ raise NotifoxConnectionError(f"Connection error: {str(e)}") from e
145
146
  except requests.exceptions.RequestException as e:
146
- raise NotifoxError(f"Request failed: {str(e)}")
147
+ raise NotifoxError(f"Request failed: {str(e)}") from e
@@ -6,7 +6,7 @@ class NotifoxError(Exception):
6
6
 
7
7
  class NotifoxAPIError(NotifoxError):
8
8
  """Raised when the API returns an error response."""
9
-
9
+
10
10
  def __init__(self, message: str, status_code: int, response_text: str = ""):
11
11
  self.status_code = status_code
12
12
  self.response_text = response_text
@@ -25,4 +25,4 @@ class NotifoxRateLimitError(NotifoxAPIError):
25
25
 
26
26
  class NotifoxConnectionError(NotifoxError):
27
27
  """Raised when there's a connection error to the API."""
28
- pass
28
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notifox
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Official Python SDK for Notifox alerting API
5
5
  Author: Mathis Van Eetvelde
6
6
  License: MIT
@@ -66,14 +66,18 @@ from notifox import (
66
66
  NotifoxConnectionError
67
67
  )
68
68
 
69
+ client = NotifoxClient(api_key="your_api_key")
70
+
69
71
  try:
70
- client.send_alert(audience=["admin"], alert="Alert")
72
+ client.send_alert(audience="admin", alert="System is running low on memory")
71
73
  except NotifoxAuthenticationError:
72
- pass
74
+ print("Authentication failed. Check your API key.")
73
75
  except NotifoxRateLimitError:
74
- pass
76
+ print("Rate limit exceeded. Please wait before sending more alerts.")
75
77
  except NotifoxAPIError as e:
76
- print(f"{e.status_code}: {e.response_text}")
78
+ print(f"API error ({e.status_code}): {e.response_text}")
79
+ except NotifoxConnectionError as e:
80
+ print(f"Connection failed: {e}")
77
81
  ```
78
82
 
79
83
  Available exceptions:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "notifox"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Official Python SDK for Notifox alerting API"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Mathis Van Eetvelde" }]
File without changes
File without changes