flipswitch-sdk 0.1.2__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Flipswitch
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,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: flipswitch-sdk
3
+ Version: 0.1.2
4
+ Summary: Flipswitch SDK with real-time SSE support for OpenFeature
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/flipswitch-io/python-sdk
7
+ Project-URL: Documentation, https://flipswitch.io/docs/sdks/python
8
+ Project-URL: Repository, https://github.com/flipswitch-io/python-sdk
9
+ Keywords: feature-flags,openfeature,flipswitch,sse,real-time
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: openfeature-sdk>=0.7.0
24
+ Requires-Dist: openfeature-provider-ofrep>=0.2.0
25
+ Requires-Dist: httpx>=0.27.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
28
+ Requires-Dist: pytest-httpserver>=1.0.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # Flipswitch Python SDK
33
+
34
+ [![CI](https://github.com/flipswitch-io/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/flipswitch-io/python-sdk/actions/workflows/ci.yml)
35
+ [![PyPI](https://img.shields.io/pypi/v/flipswitch-sdk.svg)](https://pypi.org/project/flipswitch-sdk/)
36
+
37
+ Flipswitch SDK for Python with real-time SSE support for OpenFeature.
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install flipswitch-sdk
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ```python
48
+ from flipswitch import FlipswitchProvider
49
+ from openfeature import api
50
+ from openfeature.evaluation_context import EvaluationContext
51
+
52
+ # Only API key is required
53
+ provider = FlipswitchProvider(api_key="YOUR_API_KEY")
54
+
55
+ # Register with OpenFeature
56
+ api.set_provider(provider)
57
+
58
+ # Get a client and evaluate flags
59
+ client = api.get_client()
60
+ dark_mode = client.get_boolean_value("dark-mode", False)
61
+ welcome_message = client.get_string_value("welcome-message", "Hello!")
62
+ ```
63
+
64
+ ## Configuration Options
65
+
66
+ | Option | Type | Default | Description |
67
+ |--------|------|---------|-------------|
68
+ | `api_key` | `str` | *required* | Environment API key from dashboard |
69
+ | `base_url` | `str` | `https://api.flipswitch.io` | Your Flipswitch server URL |
70
+ | `enable_realtime` | `bool` | `True` | Enable SSE for real-time flag updates |
71
+
72
+ ```python
73
+ provider = FlipswitchProvider(
74
+ api_key="YOUR_API_KEY",
75
+ base_url="https://api.flipswitch.io",
76
+ enable_realtime=True,
77
+ )
78
+ ```
79
+
80
+ ## Evaluation Context
81
+
82
+ Pass user attributes for targeting:
83
+
84
+ ```python
85
+ context = EvaluationContext(
86
+ targeting_key="user-123",
87
+ attributes={
88
+ "email": "user@example.com",
89
+ "plan": "premium",
90
+ "country": "SE",
91
+ },
92
+ )
93
+
94
+ show_feature = client.get_boolean_value("new-feature", False, context)
95
+ ```
96
+
97
+ ## Real-Time Updates
98
+
99
+ When `enable_realtime=True` (default), the SDK maintains an SSE connection to receive instant flag changes:
100
+
101
+ ### Event Listeners
102
+
103
+ ```python
104
+ from flipswitch import FlagChangeEvent
105
+
106
+ def on_flag_change(event: FlagChangeEvent):
107
+ print(f"Flag changed: {event.flag_key}")
108
+
109
+ provider.add_flag_change_listener(on_flag_change)
110
+ ```
111
+
112
+ ### Connection Status
113
+
114
+ ```python
115
+ # Check current SSE status
116
+ status = provider.get_sse_status()
117
+ # ConnectionStatus.CONNECTING, CONNECTED, DISCONNECTED, ERROR
118
+
119
+ # Force reconnect
120
+ provider.reconnect_sse()
121
+ ```
122
+
123
+ ## Bulk Flag Evaluation
124
+
125
+ Evaluate all flags at once:
126
+
127
+ ```python
128
+ # Evaluate all flags
129
+ flags = provider.evaluate_all_flags(context)
130
+ for flag in flags:
131
+ print(f"{flag.key} ({flag.value_type}): {flag.get_value_as_string()}")
132
+
133
+ # Evaluate a single flag with full details
134
+ flag = provider.evaluate_flag("dark-mode", context)
135
+ if flag:
136
+ print(f"Value: {flag.value}, Reason: {flag.reason}, Variant: {flag.variant}")
137
+ ```
138
+
139
+ ## Shutdown
140
+
141
+ Always shutdown the provider when done:
142
+
143
+ ```python
144
+ provider.shutdown()
145
+ ```
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ # Install with dev dependencies
151
+ pip install -e ".[dev]"
152
+
153
+ # Run tests
154
+ pytest
155
+
156
+ # Run demo
157
+ python examples/demo.py <api-key>
158
+ ```
159
+
160
+ ## Contributing
161
+
162
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
163
+
164
+ ## License
165
+
166
+ MIT - see [LICENSE](LICENSE) for details.
@@ -0,0 +1,135 @@
1
+ # Flipswitch Python SDK
2
+
3
+ [![CI](https://github.com/flipswitch-io/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/flipswitch-io/python-sdk/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/flipswitch-sdk.svg)](https://pypi.org/project/flipswitch-sdk/)
5
+
6
+ Flipswitch SDK for Python with real-time SSE support for OpenFeature.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install flipswitch-sdk
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```python
17
+ from flipswitch import FlipswitchProvider
18
+ from openfeature import api
19
+ from openfeature.evaluation_context import EvaluationContext
20
+
21
+ # Only API key is required
22
+ provider = FlipswitchProvider(api_key="YOUR_API_KEY")
23
+
24
+ # Register with OpenFeature
25
+ api.set_provider(provider)
26
+
27
+ # Get a client and evaluate flags
28
+ client = api.get_client()
29
+ dark_mode = client.get_boolean_value("dark-mode", False)
30
+ welcome_message = client.get_string_value("welcome-message", "Hello!")
31
+ ```
32
+
33
+ ## Configuration Options
34
+
35
+ | Option | Type | Default | Description |
36
+ |--------|------|---------|-------------|
37
+ | `api_key` | `str` | *required* | Environment API key from dashboard |
38
+ | `base_url` | `str` | `https://api.flipswitch.io` | Your Flipswitch server URL |
39
+ | `enable_realtime` | `bool` | `True` | Enable SSE for real-time flag updates |
40
+
41
+ ```python
42
+ provider = FlipswitchProvider(
43
+ api_key="YOUR_API_KEY",
44
+ base_url="https://api.flipswitch.io",
45
+ enable_realtime=True,
46
+ )
47
+ ```
48
+
49
+ ## Evaluation Context
50
+
51
+ Pass user attributes for targeting:
52
+
53
+ ```python
54
+ context = EvaluationContext(
55
+ targeting_key="user-123",
56
+ attributes={
57
+ "email": "user@example.com",
58
+ "plan": "premium",
59
+ "country": "SE",
60
+ },
61
+ )
62
+
63
+ show_feature = client.get_boolean_value("new-feature", False, context)
64
+ ```
65
+
66
+ ## Real-Time Updates
67
+
68
+ When `enable_realtime=True` (default), the SDK maintains an SSE connection to receive instant flag changes:
69
+
70
+ ### Event Listeners
71
+
72
+ ```python
73
+ from flipswitch import FlagChangeEvent
74
+
75
+ def on_flag_change(event: FlagChangeEvent):
76
+ print(f"Flag changed: {event.flag_key}")
77
+
78
+ provider.add_flag_change_listener(on_flag_change)
79
+ ```
80
+
81
+ ### Connection Status
82
+
83
+ ```python
84
+ # Check current SSE status
85
+ status = provider.get_sse_status()
86
+ # ConnectionStatus.CONNECTING, CONNECTED, DISCONNECTED, ERROR
87
+
88
+ # Force reconnect
89
+ provider.reconnect_sse()
90
+ ```
91
+
92
+ ## Bulk Flag Evaluation
93
+
94
+ Evaluate all flags at once:
95
+
96
+ ```python
97
+ # Evaluate all flags
98
+ flags = provider.evaluate_all_flags(context)
99
+ for flag in flags:
100
+ print(f"{flag.key} ({flag.value_type}): {flag.get_value_as_string()}")
101
+
102
+ # Evaluate a single flag with full details
103
+ flag = provider.evaluate_flag("dark-mode", context)
104
+ if flag:
105
+ print(f"Value: {flag.value}, Reason: {flag.reason}, Variant: {flag.variant}")
106
+ ```
107
+
108
+ ## Shutdown
109
+
110
+ Always shutdown the provider when done:
111
+
112
+ ```python
113
+ provider.shutdown()
114
+ ```
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ # Install with dev dependencies
120
+ pip install -e ".[dev]"
121
+
122
+ # Run tests
123
+ pytest
124
+
125
+ # Run demo
126
+ python examples/demo.py <api-key>
127
+ ```
128
+
129
+ ## Contributing
130
+
131
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
132
+
133
+ ## License
134
+
135
+ MIT - see [LICENSE](LICENSE) for details.
@@ -0,0 +1,44 @@
1
+ """
2
+ Flipswitch SDK with real-time SSE support for OpenFeature.
3
+
4
+ This SDK wraps OFREP-compatible flag evaluation with automatic
5
+ cache invalidation via Server-Sent Events (SSE). When flags change
6
+ in your Flipswitch dashboard, connected clients receive updates
7
+ in real-time.
8
+
9
+ Example:
10
+ >>> from flipswitch import FlipswitchProvider
11
+ >>> from openfeature import api
12
+ >>>
13
+ >>> # Only API key is required
14
+ >>> provider = FlipswitchProvider(api_key="your-api-key")
15
+ >>>
16
+ >>> api.set_provider(provider)
17
+ >>> client = api.get_client()
18
+ >>>
19
+ >>> # Flags automatically update when changed in dashboard
20
+ >>> dark_mode = client.get_boolean_value("dark-mode", False)
21
+ """
22
+
23
+ from flipswitch.provider import FlipswitchProvider
24
+ from flipswitch.sse_client import SseClient, ConnectionStatus
25
+ from flipswitch.types import (
26
+ FlipswitchOptions,
27
+ FlagChangeEvent,
28
+ FlagUpdatedEvent,
29
+ ConfigUpdatedEvent,
30
+ FlagEvaluation,
31
+ )
32
+
33
+ __all__ = [
34
+ "FlipswitchProvider",
35
+ "SseClient",
36
+ "ConnectionStatus",
37
+ "FlipswitchOptions",
38
+ "FlagChangeEvent",
39
+ "FlagUpdatedEvent",
40
+ "ConfigUpdatedEvent",
41
+ "FlagEvaluation",
42
+ ]
43
+
44
+ __version__ = "0.1.0"