notifox 0.1.0__py3-none-any.whl

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.

notifox/__init__.py ADDED
@@ -0,0 +1,18 @@
1
+ from .client import NotifoxClient
2
+ from .exceptions import (
3
+ NotifoxError,
4
+ NotifoxAPIError,
5
+ NotifoxAuthenticationError,
6
+ NotifoxRateLimitError,
7
+ NotifoxConnectionError
8
+ )
9
+
10
+ __all__ = [
11
+ "NotifoxClient",
12
+ "NotifoxError",
13
+ "NotifoxAPIError",
14
+ "NotifoxAuthenticationError",
15
+ "NotifoxRateLimitError",
16
+ "NotifoxConnectionError",
17
+ ]
18
+ __version__ = "0.1.0"
notifox/client.py ADDED
@@ -0,0 +1,146 @@
1
+ # notifox/client.py
2
+ import os
3
+ from typing import Dict, Any, Optional
4
+ import requests
5
+ from requests.adapters import HTTPAdapter
6
+ from urllib3.util.retry import Retry
7
+
8
+ from .exceptions import (
9
+ NotifoxError,
10
+ NotifoxAPIError,
11
+ NotifoxAuthenticationError,
12
+ NotifoxRateLimitError,
13
+ NotifoxConnectionError
14
+ )
15
+
16
+
17
+ class NotifoxClient:
18
+ """
19
+ Python SDK for Notifox alerting API.
20
+
21
+ Examples:
22
+ client = NotifoxClient(api_key="your_api_key")
23
+ client.send_alert(audience="user1", alert="Server down!")
24
+
25
+ client = NotifoxClient() # Reads from NOTIFOX_API_KEY env var
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ api_key: Optional[str] = None,
31
+ base_url: str = "https://api.notifox.com",
32
+ timeout: float = 30.0,
33
+ max_retries: int = 3
34
+ ):
35
+ """
36
+ Initialize the Notifox client.
37
+
38
+ Args:
39
+ api_key: Your Notifox API key. If not provided, will attempt to read from
40
+ the NOTIFOX_API_KEY environment variable.
41
+ base_url: Base URL for the Notifox API. Defaults to https://api.notifox.com
42
+ timeout: Request timeout in seconds. Defaults to 30.0
43
+ max_retries: Maximum number of retries for failed requests. Defaults to 3
44
+ """
45
+ self.api_key = api_key or os.getenv("NOTIFOX_API_KEY")
46
+ if not self.api_key:
47
+ raise NotifoxError(
48
+ "API key is required. Provide it as an argument or set the "
49
+ "NOTIFOX_API_KEY environment variable."
50
+ )
51
+
52
+ self.base_url = base_url.rstrip("/")
53
+ self.timeout = timeout
54
+
55
+ # Create a session with retry logic
56
+ self.session = requests.Session()
57
+ retry_strategy = Retry(
58
+ total=max_retries,
59
+ backoff_factor=0.5,
60
+ status_forcelist=[429, 500, 502, 503, 504]
61
+ )
62
+ adapter = HTTPAdapter(max_retries=retry_strategy)
63
+ self.session.mount("https://", adapter)
64
+
65
+ def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
66
+ """
67
+ Handle API response and raise appropriate exceptions for errors.
68
+
69
+ Args:
70
+ response: The HTTP response from the API
71
+
72
+ Returns:
73
+ The JSON response data
74
+
75
+ Raises:
76
+ NotifoxAuthenticationError: For 401 or 403 status codes
77
+ NotifoxRateLimitError: For 429 status code
78
+ NotifoxAPIError: For other error status codes
79
+ """
80
+ if response.status_code == 401 or response.status_code == 403:
81
+ raise NotifoxAuthenticationError(
82
+ f"Authentication failed: {response.status_code}",
83
+ status_code=response.status_code,
84
+ response_text=response.text
85
+ )
86
+
87
+ if response.status_code == 429:
88
+ raise NotifoxRateLimitError(
89
+ "Rate limit exceeded. Please try again later.",
90
+ status_code=response.status_code,
91
+ response_text=response.text
92
+ )
93
+
94
+ if response.status_code >= 400:
95
+ raise NotifoxAPIError(
96
+ f"API error: {response.status_code} - {response.text}",
97
+ status_code=response.status_code,
98
+ response_text=response.text
99
+ )
100
+
101
+ return response.json()
102
+
103
+ def send_alert(
104
+ self,
105
+ audience: str,
106
+ alert: str
107
+ ) -> Dict[str, Any]:
108
+ """
109
+ Sends an alert to the specified audience.
110
+
111
+ Args:
112
+ audience: Audience identifier (e.g., mike, devops, support)
113
+ alert: The alert message to send
114
+
115
+ Returns:
116
+ API response as a dictionary
117
+
118
+ Raises:
119
+ NotifoxAuthenticationError: If authentication fails
120
+ NotifoxRateLimitError: If rate limit is exceeded
121
+ NotifoxAPIError: For other API errors
122
+ NotifoxConnectionError: If there's a connection issue
123
+ """
124
+ url = f"{self.base_url}/alert"
125
+ headers = {"Authorization": f"Bearer {self.api_key}"}
126
+ payload = {
127
+ "audience": audience,
128
+ "alert": alert,
129
+ }
130
+
131
+ try:
132
+ resp = self.session.post(
133
+ url,
134
+ headers=headers,
135
+ json=payload,
136
+ timeout=self.timeout
137
+ )
138
+ return self._handle_response(resp)
139
+ except requests.exceptions.Timeout:
140
+ raise NotifoxConnectionError(
141
+ f"Request timed out after {self.timeout} seconds"
142
+ )
143
+ except requests.exceptions.ConnectionError as e:
144
+ raise NotifoxConnectionError(f"Connection error: {str(e)}")
145
+ except requests.exceptions.RequestException as e:
146
+ raise NotifoxError(f"Request failed: {str(e)}")
notifox/exceptions.py ADDED
@@ -0,0 +1,28 @@
1
+ # notifox/exceptions.py
2
+ class NotifoxError(Exception):
3
+ """Base exception for all Notifox SDK errors."""
4
+ pass
5
+
6
+
7
+ class NotifoxAPIError(NotifoxError):
8
+ """Raised when the API returns an error response."""
9
+
10
+ def __init__(self, message: str, status_code: int, response_text: str = ""):
11
+ self.status_code = status_code
12
+ self.response_text = response_text
13
+ super().__init__(message)
14
+
15
+
16
+ class NotifoxAuthenticationError(NotifoxAPIError):
17
+ """Raised when authentication fails (401/403)."""
18
+ pass
19
+
20
+
21
+ class NotifoxRateLimitError(NotifoxAPIError):
22
+ """Raised when rate limit is exceeded (429)."""
23
+ pass
24
+
25
+
26
+ class NotifoxConnectionError(NotifoxError):
27
+ """Raised when there's a connection error to the API."""
28
+ pass
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: notifox
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for Notifox alerting API
5
+ Author: Mathis Van Eetvelde
6
+ License: MIT
7
+ Project-URL: Homepage, https://notifox.com
8
+ Project-URL: Console, https://console.notifox.com
9
+ Project-URL: Docs, https://notifox.com/docs
10
+ Project-URL: API, https://api.notifox.com/
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.28.0
15
+ Dynamic: license-file
16
+
17
+ # notifox-py
18
+
19
+ Python SDK for [Notifox](https://notifox.com).
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install notifox
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```python
30
+ from notifox import NotifoxClient
31
+
32
+ client = NotifoxClient(api_key="your_api_key_here")
33
+ client.send_alert(audience="mike", alert="Database server is down!")
34
+ ```
35
+
36
+ Or use the environment variable:
37
+
38
+ ```bash
39
+ export NOTIFOX_API_KEY="your_api_key_here"
40
+ ```
41
+
42
+ ```python
43
+ client = NotifoxClient() # Reads from NOTIFOX_API_KEY
44
+ client.send_alert(audience="mike", alert="High CPU usage!")
45
+ ```
46
+
47
+ ### Configuration
48
+
49
+ ```python
50
+ client = NotifoxClient(
51
+ api_key="your_api_key",
52
+ base_url="https://api.notifox.com",
53
+ timeout=30.0,
54
+ max_retries=3
55
+ )
56
+ ```
57
+
58
+ ## Error Handling
59
+
60
+ ```python
61
+ from notifox import (
62
+ NotifoxClient,
63
+ NotifoxAuthenticationError,
64
+ NotifoxRateLimitError,
65
+ NotifoxAPIError,
66
+ NotifoxConnectionError
67
+ )
68
+
69
+ try:
70
+ client.send_alert(audience=["admin"], alert="Alert")
71
+ except NotifoxAuthenticationError:
72
+ pass
73
+ except NotifoxRateLimitError:
74
+ pass
75
+ except NotifoxAPIError as e:
76
+ print(f"{e.status_code}: {e.response_text}")
77
+ ```
78
+
79
+ Available exceptions:
80
+ - `NotifoxError` - Base exception
81
+ - `NotifoxAuthenticationError` - Authentication failed (401/403)
82
+ - `NotifoxRateLimitError` - Rate limit exceeded (429)
83
+ - `NotifoxAPIError` - General API errors
84
+ - `NotifoxConnectionError` - Network errors
@@ -0,0 +1,8 @@
1
+ notifox/__init__.py,sha256=JTWJrlY-jCkYf6PSUMAF1Eng8blox8yX_xeYqxgJlJo,380
2
+ notifox/client.py,sha256=mwNYavJqPs__UNxWRZwVy6mRXF_tlCT-PUOTWjIlZ3A,4881
3
+ notifox/exceptions.py,sha256=Mbks4ACBd8tt2XEDgiFofsWXpY9xaqzw43H3ZLgyJXk,755
4
+ notifox-0.1.0.dist-info/licenses/LICENSE,sha256=eZtQec-wzyeDB7eeTSsosa9_a6RR0ebVBPPxn7xSakQ,1094
5
+ notifox-0.1.0.dist-info/METADATA,sha256=muT8mutjJijvkCHHcdJmoEphP7y3Vk2FduxNPIRDZRs,1811
6
+ notifox-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ notifox-0.1.0.dist-info/top_level.txt,sha256=VvmvnNCybE97RLvBOCrYNYCKGdhhVkPBVdYW_kM_spc,8
8
+ notifox-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Van Eetvelde Ventures LLC DBA Notifox
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.
@@ -0,0 +1 @@
1
+ notifox