flagswitch-sdk 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagswitch-sdk
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python SDK for FlagSwitch feature flag management
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -1,5 +1,9 @@
1
+ __version__ = "0.3.0"
2
+ __author__ = "FlagSwitch"
3
+
1
4
  from flagswitch_sdk.client import FlagSwitch, FlagSwitchSync
2
5
  from flagswitch_sdk.exceptions import (
6
+ EnvironmentNotFoundError,
3
7
  FlagSwitchConnectionError,
4
8
  FlagSwitchError,
5
9
  InvalidApiKeyError,
@@ -10,5 +14,6 @@ __all__ = [
10
14
  "FlagSwitchSync",
11
15
  "FlagSwitchError",
12
16
  "InvalidApiKeyError",
17
+ "EnvironmentNotFoundError",
13
18
  "FlagSwitchConnectionError",
14
19
  ]
@@ -3,7 +3,11 @@ from typing import Any
3
3
 
4
4
  import httpx
5
5
 
6
- from flagswitch_sdk.exceptions import FlagSwitchConnectionError, InvalidApiKeyError
6
+ from flagswitch_sdk.exceptions import (
7
+ EnvironmentNotFoundError,
8
+ FlagSwitchConnectionError,
9
+ InvalidApiKeyError,
10
+ )
7
11
 
8
12
 
9
13
  _BASE_URL = "http://localhost:8010/api/fs"
@@ -11,8 +15,9 @@ _CACHE_TTL = 30
11
15
 
12
16
 
13
17
  class FlagSwitch:
14
- def __init__(self, api_key: str):
18
+ def __init__(self, api_key: str, environment: str):
15
19
  self._api_key = api_key
20
+ self._environment = environment
16
21
  self._cache_ttl = _CACHE_TTL
17
22
  self._cache: dict[str, Any] = {}
18
23
  self._cache_ts: float = 0
@@ -26,6 +31,7 @@ class FlagSwitch:
26
31
  response = await http.get(
27
32
  f"{_BASE_URL}/evaluate",
28
33
  headers={"X-Api-Key": self._api_key},
34
+ params={"environment": self._environment},
29
35
  timeout=5.0,
30
36
  )
31
37
  except httpx.RequestError as e:
@@ -34,6 +40,11 @@ class FlagSwitch:
34
40
  if response.status_code == 401:
35
41
  raise InvalidApiKeyError("Invalid or inactive API key.")
36
42
 
43
+ if response.status_code == 404:
44
+ raise EnvironmentNotFoundError(
45
+ f"Environment '{self._environment}' not found for this project."
46
+ )
47
+
37
48
  if response.status_code != 200:
38
49
  raise FlagSwitchConnectionError(
39
50
  f"Unexpected response from FlagSwitch: {response.status_code}"
@@ -64,8 +75,9 @@ class FlagSwitch:
64
75
 
65
76
 
66
77
  class FlagSwitchSync:
67
- def __init__(self, api_key: str):
78
+ def __init__(self, api_key: str, environment: str):
68
79
  self._api_key = api_key
80
+ self._environment = environment
69
81
  self._cache_ttl = _CACHE_TTL
70
82
  self._cache: dict[str, Any] = {}
71
83
  self._cache_ts: float = 0
@@ -79,6 +91,7 @@ class FlagSwitchSync:
79
91
  response = http.get(
80
92
  f"{_BASE_URL}/evaluate",
81
93
  headers={"X-Api-Key": self._api_key},
94
+ params={"environment": self._environment},
82
95
  timeout=5.0,
83
96
  )
84
97
  except httpx.RequestError as e:
@@ -87,6 +100,11 @@ class FlagSwitchSync:
87
100
  if response.status_code == 401:
88
101
  raise InvalidApiKeyError("Invalid or inactive API key.")
89
102
 
103
+ if response.status_code == 404:
104
+ raise EnvironmentNotFoundError(
105
+ f"Environment '{self._environment}' not found for this project."
106
+ )
107
+
90
108
  if response.status_code != 200:
91
109
  raise FlagSwitchConnectionError(
92
110
  f"Unexpected response from FlagSwitch: {response.status_code}"
@@ -6,5 +6,9 @@ class InvalidApiKeyError(FlagSwitchError):
6
6
  pass
7
7
 
8
8
 
9
+ class EnvironmentNotFoundError(FlagSwitchError):
10
+ pass
11
+
12
+
9
13
  class FlagSwitchConnectionError(FlagSwitchError):
10
14
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagswitch-sdk
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python SDK for FlagSwitch feature flag management
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "flagswitch-sdk"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Python SDK for FlagSwitch feature flag management"
9
9
  requires-python = ">=3.11"
10
10
  dependencies = ["httpx>=0.27"]
File without changes
File without changes