openfeature-provider-flagd 0.2.6__py3-none-any.whl → 0.2.7__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.
Files changed (31) hide show
  1. openfeature/contrib/provider/flagd/provider.py +10 -3
  2. openfeature/contrib/provider/flagd/resolvers/grpc.py +82 -27
  3. openfeature/contrib/provider/flagd/resolvers/in_process.py +7 -3
  4. openfeature/contrib/provider/flagd/resolvers/process/connector/grpc_watcher.py +70 -38
  5. openfeature/contrib/provider/flagd/resolvers/process/targeting.py +5 -1
  6. openfeature/contrib/provider/flagd/resolvers/protocol.py +7 -3
  7. openfeature/contrib/provider/flagd/resolvers/types.py +7 -0
  8. openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2.py +36 -36
  9. openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2.pyi +41 -22
  10. openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2_grpc.py +2 -2
  11. openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2_grpc.pyi +194 -39
  12. openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2.py +22 -16
  13. openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2.pyi +33 -10
  14. openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2_grpc.py +2 -2
  15. openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2_grpc.pyi +94 -19
  16. openfeature/schemas/protobuf/schema/v1/schema_pb2.py +4 -4
  17. openfeature/schemas/protobuf/schema/v1/schema_pb2.pyi +25 -19
  18. openfeature/schemas/protobuf/schema/v1/schema_pb2_grpc.py +2 -2
  19. openfeature/schemas/protobuf/schema/v1/schema_pb2_grpc.pyi +194 -39
  20. openfeature/schemas/protobuf/sync/v1/sync_service_pb2.py +4 -4
  21. openfeature/schemas/protobuf/sync/v1/sync_service_pb2.pyi +9 -9
  22. openfeature/schemas/protobuf/sync/v1/sync_service_pb2_grpc.py +2 -2
  23. openfeature/schemas/protobuf/sync/v1/sync_service_pb2_grpc.pyi +69 -14
  24. openfeature_provider_flagd-0.2.7.dist-info/METADATA +208 -0
  25. openfeature_provider_flagd-0.2.7.dist-info/RECORD +37 -0
  26. {openfeature_provider_flagd-0.2.6.dist-info → openfeature_provider_flagd-0.2.7.dist-info}/WHEEL +1 -1
  27. openfeature_provider_flagd-0.2.7.dist-info/entry_points.txt +6 -0
  28. {openfeature_provider_flagd-0.2.6.dist-info → openfeature_provider_flagd-0.2.7.dist-info}/licenses/LICENSE +1 -1
  29. openfeature/.gitignore +0 -2
  30. openfeature_provider_flagd-0.2.6.dist-info/METADATA +0 -370
  31. openfeature_provider_flagd-0.2.6.dist-info/RECORD +0 -36
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: openfeature-provider-flagd
3
+ Version: 0.2.7
4
+ Summary: OpenFeature provider for the flagd flag evaluation engine
5
+ Project-URL: Homepage, https://github.com/open-feature/python-sdk-contrib
6
+ Author-email: OpenFeature <openfeature-core@groups.io>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.9
12
+ Requires-Dist: cachebox<6.0.0,>=5.1.0
13
+ Requires-Dist: grpcio>=1.76.0
14
+ Requires-Dist: mmh3<6.0.0,>=5.0.0
15
+ Requires-Dist: openfeature-sdk>=0.8.2
16
+ Requires-Dist: panzi-json-logic>=1.0.1
17
+ Requires-Dist: protobuf<7.0.0,>=6.30.0
18
+ Requires-Dist: pyyaml>=6.0.1
19
+ Requires-Dist: semver<4,>=3
20
+ Description-Content-Type: text/markdown
21
+
22
+ # flagd Provider for OpenFeature
23
+
24
+ This provider is designed to use flagd's [evaluation protocol](https://github.com/open-feature/schemas/blob/main/protobuf/schema/v1/schema.proto), or locally evaluate flags defined in a flagd [flag definition](https://github.com/open-feature/schemas/blob/main/json/flagd-definitions.json) via the OpenFeature Python SDK.
25
+
26
+ ## Installation
27
+
28
+ ```
29
+ pip install openfeature-provider-flagd
30
+ ```
31
+
32
+ ## Configuration and Usage
33
+
34
+ The flagd provider can operate in two modes: [RPC](#remote-resolver-rpc) (evaluation takes place in flagd, via gRPC calls) or [in-process](#in-process-resolver) (evaluation takes place in-process, with the provider getting a ruleset from a compliant sync-source).
35
+
36
+ ### Remote resolver (RPC)
37
+
38
+ This is the default mode of operation of the provider.
39
+ In this mode, `FlagdProvider` communicates with [flagd](https://github.com/open-feature/flagd) via the gRPC protocol.
40
+ Flag evaluations take place remotely at the connected flagd instance.
41
+
42
+ Instantiate a new FlagdProvider instance and configure the OpenFeature SDK to use it:
43
+
44
+ ```python
45
+ from openfeature import api
46
+ from openfeature.contrib.provider.flagd import FlagdProvider
47
+
48
+ api.set_provider(FlagdProvider())
49
+ ```
50
+
51
+ ### In-process resolver
52
+
53
+ This mode performs flag evaluations locally (in-process). Flag configurations for evaluation are obtained via gRPC protocol using [sync protobuf schema](https://buf.build/open-feature/flagd/file/main:sync/v1/sync_service.proto) service definition.
54
+
55
+ Consider the following example to create a `FlagdProvider` with in-process evaluations,
56
+
57
+ ```python
58
+ from openfeature import api
59
+ from openfeature.contrib.provider.flagd import FlagdProvider
60
+ from openfeature.contrib.provider.flagd.config import ResolverType
61
+
62
+ api.set_provider(FlagdProvider(
63
+ resolver_type=ResolverType.IN_PROCESS,
64
+ ))
65
+ ```
66
+
67
+ In the above example, in-process handlers attempt to connect to a sync service on address `localhost:8013` to obtain [flag definitions](https://github.com/open-feature/schemas/blob/main/json/flags.json).
68
+
69
+ <!--
70
+ #### Sync-metadata
71
+
72
+ To support the injection of contextual data configured in flagd for in-process evaluation, the provider exposes a `getSyncMetadata` accessor which provides the most recent value returned by the [GetMetadata RPC](https://buf.build/open-feature/flagd/docs/main:flagd.sync.v1#flagd.sync.v1.FlagSyncService.GetMetadata).
73
+ The value is updated with every (re)connection to the sync implementation.
74
+ This can be used to enrich evaluations with such data.
75
+ If the `in-process` mode is not used, and before the provider is ready, the `getSyncMetadata` returns an empty map.
76
+ -->
77
+ ### File mode
78
+
79
+ In-process resolvers can also work in an offline mode.
80
+ To enable this mode, you should provide a valid flag configuration file with the option `offlineFlagSourcePath`.
81
+
82
+ ```python
83
+ from openfeature import api
84
+ from openfeature.contrib.provider.flagd import FlagdProvider
85
+ from openfeature.contrib.provider.flagd.config import ResolverType
86
+
87
+ api.set_provider(FlagdProvider(
88
+ resolver_type=ResolverType.FILE,
89
+ offline_flag_source_path="my-flag.json",
90
+ ))
91
+ ```
92
+
93
+ Provider will attempt to detect file changes using polling.
94
+ Polling happens at 5 second intervals and this is currently unconfigurable.
95
+ This mode is useful for local development, tests and offline applications.
96
+
97
+ ### Configuration options
98
+
99
+ The default options can be defined in the FlagdProvider constructor.
100
+
101
+ | Option name | Environment variable name | Type & Values | Default | Compatible resolver |
102
+ |--------------------------|--------------------------------|----------------------------|-------------------------------|---------------------|
103
+ | resolver_type | FLAGD_RESOLVER | enum - `rpc`, `in-process` | rpc | |
104
+ | host | FLAGD_HOST | str | localhost | rpc & in-process |
105
+ | port | FLAGD_PORT | int | 8013 (rpc), 8015 (in-process) | rpc & in-process |
106
+ | tls | FLAGD_TLS | bool | false | rpc & in-process |
107
+ | cert_path | FLAGD_SERVER_CERT_PATH | String | null | rpc & in-process |
108
+ | deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process |
109
+ | stream_deadline_ms | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
110
+ | keep_alive_time | FLAGD_KEEP_ALIVE_TIME_MS | int | 0 | rpc & in-process |
111
+ | selector | FLAGD_SOURCE_SELECTOR | str | null | in-process |
112
+ | cache_type | FLAGD_CACHE | enum - `lru`, `disabled` | lru | rpc |
113
+ | max_cache_size | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
114
+ | retry_backoff_ms | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
115
+ | offline_flag_source_path | FLAGD_OFFLINE_FLAG_SOURCE_PATH | str | null | in-process |
116
+
117
+ > [!NOTE]
118
+ > The `selector` configuration is only used in **in-process** mode for filtering flag configurations. See [Selector Handling](#selector-handling-in-process-mode-only) for migration guidance.
119
+
120
+ <!-- not implemented
121
+ | target_uri | FLAGD_TARGET_URI | alternative to host/port, supporting custom name resolution | string | null | rpc & in-process |
122
+ | socket_path | FLAGD_SOCKET_PATH | alternative to host port, unix socket | String | null | rpc & in-process |
123
+ | context_enricher | - | sync-metadata to evaluation context mapping function | function | identity function | in-process |
124
+ | offline_pollIntervalMs | FLAGD_OFFLINE_POLL_MS | poll interval for reading offlineFlagSourcePath | int | 5000 | in-process |
125
+ -->
126
+
127
+ > [!NOTE]
128
+ > Some configurations are only applicable for RPC resolver.
129
+
130
+ ### Selector Handling (In-Process Mode Only)
131
+
132
+ > [!IMPORTANT]
133
+ > This section only applies to **in-process** resolver mode. RPC mode is not affected by selector handling changes.
134
+
135
+ #### Current Implementation
136
+
137
+ As of this SDK version, the `selector` parameter is passed via **both** gRPC metadata headers (`flagd-selector`) and the request body when using in-process mode. This dual approach ensures maximum compatibility with all flagd versions.
138
+
139
+ **Configuration Example:**
140
+ ```python
141
+ from openfeature import api
142
+ from openfeature.contrib.provider.flagd import FlagdProvider
143
+ from openfeature.contrib.provider.flagd.config import ResolverType
144
+
145
+ api.set_provider(FlagdProvider(
146
+ resolver_type=ResolverType.IN_PROCESS,
147
+ selector="my-flag-source", # Passed via both header and request body
148
+ ))
149
+ ```
150
+
151
+ The selector is automatically passed via:
152
+ - **gRPC metadata header** (`flagd-selector`) - For flagd v0.11.0+ selector normalization
153
+ - **Request body** - For backward compatibility with older flagd versions
154
+
155
+ #### Backward Compatibility
156
+
157
+ This dual transmission approach ensures the Python SDK works seamlessly with all flagd service versions:
158
+ - **Older flagd versions** read the selector from the request body
159
+ - **Newer flagd versions (v0.11.0+)** prefer the selector from the gRPC metadata header
160
+ - Both approaches are supported simultaneously for maximum compatibility
161
+
162
+ **Related Resources:**
163
+ - Upstream issue: [open-feature/flagd#1814](https://github.com/open-feature/flagd/issues/1814)
164
+ - Selector normalization affects in-process evaluations that filter flag configurations by source
165
+
166
+ <!--
167
+ ### Unix socket support
168
+ Unix socket communication with flagd is facilitated by usaging of the linux-native `epoll` library on `linux-x86_64`
169
+ only (ARM support is pending the release of `netty-transport-native-epoll` v5).
170
+ Unix sockets are not supported on other platforms or architectures.
171
+ -->
172
+
173
+ ### Reconnection
174
+
175
+ Reconnection is supported by the underlying gRPC connections.
176
+ If the connection to flagd is lost, it will reconnect automatically.
177
+ A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect indefinitely.
178
+
179
+ ### Deadlines
180
+
181
+ Deadlines are used to define how long the provider waits to complete initialization or flag evaluations.
182
+ They behave differently based on the resolver type.
183
+
184
+ #### Deadlines with Remote resolver (RPC)
185
+
186
+ If the remote evaluation call is not completed within this deadline, the gRPC call is terminated with the error `DEADLINE_EXCEEDED`
187
+ and the evaluation will default.
188
+
189
+ ### TLS
190
+
191
+ TLS is available in situations where flagd is running on another host.
192
+
193
+
194
+ You may optionally supply an X.509 certificate in PEM format. Otherwise, the default certificate store will be used.
195
+
196
+ ```python
197
+ from openfeature import api
198
+ from openfeature.contrib.provider.flagd import FlagdProvider
199
+
200
+ api.set_provider(FlagdProvider(
201
+ tls=True, # use TLS
202
+ cert_path="etc/cert/ca.crt" # PEM cert
203
+ ))
204
+ ```
205
+
206
+ ## License
207
+
208
+ Apache 2.0 - See [LICENSE](./LICENSE) for more information.
@@ -0,0 +1,37 @@
1
+ openfeature/contrib/provider/flagd/__init__.py,sha256=WlrcPaCH31dEG1IvrvpeuhAaQ8Ni8LEzDpNM_x-qKOA,65
2
+ openfeature/contrib/provider/flagd/config.py,sha256=S2DO-X5Fs8Wn1hq-7tOYBuYep4URhINbhbzH1vDcLxk,8373
3
+ openfeature/contrib/provider/flagd/flag_type.py,sha256=rZYfmqQEmtqVVTb8e-d8Wt8ZCnHtf7xPSmYxyU8w0R0,158
4
+ openfeature/contrib/provider/flagd/provider.py,sha256=3NY8K0t-N7RVvCq6dmUmMHwAGS3tc18eBdLm2I6aYEs,8400
5
+ openfeature/contrib/provider/flagd/sync_metadata_hook.py,sha256=fd3uRtwDhVlCW9vZhS35p9qENkl6wDHwlFH-L48aPDM,456
6
+ openfeature/contrib/provider/flagd/resolvers/__init__.py,sha256=CzsnsfxJCaD_S1gBf15kkJBVD-gVLKIwDi4W1nE-dXw,181
7
+ openfeature/contrib/provider/flagd/resolvers/grpc.py,sha256=AxsJ1QWWYrp8vMxlymuhcIVDC9ys9crZ_JcXPG_AdQk,17082
8
+ openfeature/contrib/provider/flagd/resolvers/in_process.py,sha256=_bVqwVMlxfqNho1ifAj2LiW6sQdECT44A4a5aZDSAhE,6491
9
+ openfeature/contrib/provider/flagd/resolvers/protocol.py,sha256=i_pIZpVSChj6qHXrwyy_d1aqL-UQhu2GqEjlp-z3r7U,1565
10
+ openfeature/contrib/provider/flagd/resolvers/types.py,sha256=n0-ybSOdukPlfwjork7RfP7haPbFeRJNeENbgV4LFAU,208
11
+ openfeature/contrib/provider/flagd/resolvers/process/custom_ops.py,sha256=bZX1At0dRxhghhWz4g-8N-YPobcVfYSv9PTsYh-lZDc,4549
12
+ openfeature/contrib/provider/flagd/resolvers/process/flags.py,sha256=PPD99ebcRlZ08rbzqP6TY-433rW5xyMvmLTavSib2FU,4689
13
+ openfeature/contrib/provider/flagd/resolvers/process/targeting.py,sha256=2i8mmkTxZa1KIeO3syPTXL_dYrXv8VHkoRLq_92p8Jo,1148
14
+ openfeature/contrib/provider/flagd/resolvers/process/connector/__init__.py,sha256=hyYYxRYEnSho5F28M2hbhhtkG4DQTwJjD36ddI0Xs7M,289
15
+ openfeature/contrib/provider/flagd/resolvers/process/connector/file_watcher.py,sha256=abj6DhAyu2nP-P5EAHB9GyceJMym21rO8tKr8nQhmKM,4241
16
+ openfeature/contrib/provider/flagd/resolvers/process/connector/grpc_watcher.py,sha256=_OFVzRdhwk9b3civRg0nlkIIaNdxr4mAMLWcWqwKxos,12058
17
+ openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2.py,sha256=QEcMb-M9spzNTtRiHS7Ml1Nx4BQ2V_SLCzdg_4J2DZs,7662
18
+ openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2.pyi,sha256=zJFHwyVVvO9A_HCcvJz9IslTCJFJUzlVHCP7gl594qo,19513
19
+ openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2_grpc.py,sha256=3Knhk-6SULSC5UlGZLzrMJUG69hUZUy3lpyLLwYWufY,17188
20
+ openfeature/schemas/protobuf/flagd/evaluation/v1/evaluation_pb2_grpc.pyi,sha256=zWKTHFU_0fPp-gh_pZSEq0_G9eILMF73xOyFvw1vrfI,15643
21
+ openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2.py,sha256=8CD6l2HdMuRrMx5-7v2PvV3qpBp-xFC_8-zRIFgOlUM,4120
22
+ openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2.pyi,sha256=gj0C_DwVsys4OJcZHIkTn_dmpsO_eaMoDEi1YIMRHmQ,7239
23
+ openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2_grpc.py,sha256=2mRDoaBJ2YMr4oEaUVWF2MC0_dkK6NP0mWxcHMsYyKg,8334
24
+ openfeature/schemas/protobuf/flagd/sync/v1/sync_pb2_grpc.pyi,sha256=d5xo73GdcBqLJSVLe_HqBym_cojJHN_xYOS__cQtF6Y,7100
25
+ openfeature/schemas/protobuf/schema/v1/schema_pb2.py,sha256=QA0tgGdq_mDaLCrY5cFgy0bEfVat_NbbLEKmkKg8Wuw,7255
26
+ openfeature/schemas/protobuf/schema/v1/schema_pb2.pyi,sha256=43T6MZs5_Wgv_cNLpIGgIp8WQQNoiJ_UWlpdOFXZyf4,18922
27
+ openfeature/schemas/protobuf/schema/v1/schema_pb2_grpc.py,sha256=2t7v6KiJIBysUCXEmIKA2L70kBew5TFQmR_IIuATDmI,16226
28
+ openfeature/schemas/protobuf/schema/v1/schema_pb2_grpc.pyi,sha256=rCDQli44_BEUOp-mGJ9grv0Vrm5nByZS45BHHvBN0nk,14195
29
+ openfeature/schemas/protobuf/sync/v1/sync_service_pb2.py,sha256=1XNp_EYYg9s416kbOCOikrja4VnsXlgTYfp_KCi8wn4,3327
30
+ openfeature/schemas/protobuf/sync/v1/sync_service_pb2.pyi,sha256=hoE0X-Gh9ax5-dqsxSDNYr7QSlKLYNN-F6oAP6O4evc,8119
31
+ openfeature/schemas/protobuf/sync/v1/sync_service_pb2_grpc.py,sha256=UaBctTe_2emIAv5asA4XgBODmg6S03BOsTnyGvIp8F8,6184
32
+ openfeature/schemas/protobuf/sync/v1/sync_service_pb2_grpc.pyi,sha256=VoHfY5vMMKVLvAU_vO1V-9EM1a0xU1esZJ4PaVgWVhc,5358
33
+ openfeature_provider_flagd-0.2.7.dist-info/METADATA,sha256=x0WDKeqnwwLvkUCPWIr9hinN59waFJtIz7Mdk24DEvw,10449
34
+ openfeature_provider_flagd-0.2.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
35
+ openfeature_provider_flagd-0.2.7.dist-info/entry_points.txt,sha256=qgpX_LsL9eQyUfrI8UWF-qpvkzcFOeZlPQzwAoVpbaQ,182
36
+ openfeature_provider_flagd-0.2.7.dist-info/licenses/LICENSE,sha256=-WTExFj8w3QawWOdwovvHkLAFrN8q5_oRAD8O1l9xas,11348
37
+ openfeature_provider_flagd-0.2.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,6 @@
1
+ [console_scripts]
2
+ cov = scripts.scripts:cov
3
+ cov-report = scripts.scripts:cov_report
4
+ mypy-check = scripts.scripts:mypy
5
+ test = scripts.scripts:test
6
+ test-cov = scripts.scripts:test_cov
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright OpenFeature Maintainers
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
openfeature/.gitignore DELETED
@@ -1,2 +0,0 @@
1
-
2
- schemas
@@ -1,370 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: openfeature-provider-flagd
3
- Version: 0.2.6
4
- Summary: OpenFeature provider for the flagd flag evaluation engine
5
- Project-URL: Homepage, https://github.com/open-feature/python-sdk-contrib
6
- Author-email: OpenFeature <openfeature-core@groups.io>
7
- License: Apache License
8
- Version 2.0, January 2004
9
- http://www.apache.org/licenses/
10
-
11
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
12
-
13
- 1. Definitions.
14
-
15
- "License" shall mean the terms and conditions for use, reproduction,
16
- and distribution as defined by Sections 1 through 9 of this document.
17
-
18
- "Licensor" shall mean the copyright owner or entity authorized by
19
- the copyright owner that is granting the License.
20
-
21
- "Legal Entity" shall mean the union of the acting entity and all
22
- other entities that control, are controlled by, or are under common
23
- control with that entity. For the purposes of this definition,
24
- "control" means (i) the power, direct or indirect, to cause the
25
- direction or management of such entity, whether by contract or
26
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
27
- outstanding shares, or (iii) beneficial ownership of such entity.
28
-
29
- "You" (or "Your") shall mean an individual or Legal Entity
30
- exercising permissions granted by this License.
31
-
32
- "Source" form shall mean the preferred form for making modifications,
33
- including but not limited to software source code, documentation
34
- source, and configuration files.
35
-
36
- "Object" form shall mean any form resulting from mechanical
37
- transformation or translation of a Source form, including but
38
- not limited to compiled object code, generated documentation,
39
- and conversions to other media types.
40
-
41
- "Work" shall mean the work of authorship, whether in Source or
42
- Object form, made available under the License, as indicated by a
43
- copyright notice that is included in or attached to the work
44
- (an example is provided in the Appendix below).
45
-
46
- "Derivative Works" shall mean any work, whether in Source or Object
47
- form, that is based on (or derived from) the Work and for which the
48
- editorial revisions, annotations, elaborations, or other modifications
49
- represent, as a whole, an original work of authorship. For the purposes
50
- of this License, Derivative Works shall not include works that remain
51
- separable from, or merely link (or bind by name) to the interfaces of,
52
- the Work and Derivative Works thereof.
53
-
54
- "Contribution" shall mean any work of authorship, including
55
- the original version of the Work and any modifications or additions
56
- to that Work or Derivative Works thereof, that is intentionally
57
- submitted to Licensor for inclusion in the Work by the copyright owner
58
- or by an individual or Legal Entity authorized to submit on behalf of
59
- the copyright owner. For the purposes of this definition, "submitted"
60
- means any form of electronic, verbal, or written communication sent
61
- to the Licensor or its representatives, including but not limited to
62
- communication on electronic mailing lists, source code control systems,
63
- and issue tracking systems that are managed by, or on behalf of, the
64
- Licensor for the purpose of discussing and improving the Work, but
65
- excluding communication that is conspicuously marked or otherwise
66
- designated in writing by the copyright owner as "Not a Contribution."
67
-
68
- "Contributor" shall mean Licensor and any individual or Legal Entity
69
- on behalf of whom a Contribution has been received by Licensor and
70
- subsequently incorporated within the Work.
71
-
72
- 2. Grant of Copyright License. Subject to the terms and conditions of
73
- this License, each Contributor hereby grants to You a perpetual,
74
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
- copyright license to reproduce, prepare Derivative Works of,
76
- publicly display, publicly perform, sublicense, and distribute the
77
- Work and such Derivative Works in Source or Object form.
78
-
79
- 3. Grant of Patent License. Subject to the terms and conditions of
80
- this License, each Contributor hereby grants to You a perpetual,
81
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82
- (except as stated in this section) patent license to make, have made,
83
- use, offer to sell, sell, import, and otherwise transfer the Work,
84
- where such license applies only to those patent claims licensable
85
- by such Contributor that are necessarily infringed by their
86
- Contribution(s) alone or by combination of their Contribution(s)
87
- with the Work to which such Contribution(s) was submitted. If You
88
- institute patent litigation against any entity (including a
89
- cross-claim or counterclaim in a lawsuit) alleging that the Work
90
- or a Contribution incorporated within the Work constitutes direct
91
- or contributory patent infringement, then any patent licenses
92
- granted to You under this License for that Work shall terminate
93
- as of the date such litigation is filed.
94
-
95
- 4. Redistribution. You may reproduce and distribute copies of the
96
- Work or Derivative Works thereof in any medium, with or without
97
- modifications, and in Source or Object form, provided that You
98
- meet the following conditions:
99
-
100
- (a) You must give any other recipients of the Work or
101
- Derivative Works a copy of this License; and
102
-
103
- (b) You must cause any modified files to carry prominent notices
104
- stating that You changed the files; and
105
-
106
- (c) You must retain, in the Source form of any Derivative Works
107
- that You distribute, all copyright, patent, trademark, and
108
- attribution notices from the Source form of the Work,
109
- excluding those notices that do not pertain to any part of
110
- the Derivative Works; and
111
-
112
- (d) If the Work includes a "NOTICE" text file as part of its
113
- distribution, then any Derivative Works that You distribute must
114
- include a readable copy of the attribution notices contained
115
- within such NOTICE file, excluding those notices that do not
116
- pertain to any part of the Derivative Works, in at least one
117
- of the following places: within a NOTICE text file distributed
118
- as part of the Derivative Works; within the Source form or
119
- documentation, if provided along with the Derivative Works; or,
120
- within a display generated by the Derivative Works, if and
121
- wherever such third-party notices normally appear. The contents
122
- of the NOTICE file are for informational purposes only and
123
- do not modify the License. You may add Your own attribution
124
- notices within Derivative Works that You distribute, alongside
125
- or as an addendum to the NOTICE text from the Work, provided
126
- that such additional attribution notices cannot be construed
127
- as modifying the License.
128
-
129
- You may add Your own copyright statement to Your modifications and
130
- may provide additional or different license terms and conditions
131
- for use, reproduction, or distribution of Your modifications, or
132
- for any such Derivative Works as a whole, provided Your use,
133
- reproduction, and distribution of the Work otherwise complies with
134
- the conditions stated in this License.
135
-
136
- 5. Submission of Contributions. Unless You explicitly state otherwise,
137
- any Contribution intentionally submitted for inclusion in the Work
138
- by You to the Licensor shall be under the terms and conditions of
139
- this License, without any additional terms or conditions.
140
- Notwithstanding the above, nothing herein shall supersede or modify
141
- the terms of any separate license agreement you may have executed
142
- with Licensor regarding such Contributions.
143
-
144
- 6. Trademarks. This License does not grant permission to use the trade
145
- names, trademarks, service marks, or product names of the Licensor,
146
- except as required for reasonable and customary use in describing the
147
- origin of the Work and reproducing the content of the NOTICE file.
148
-
149
- 7. Disclaimer of Warranty. Unless required by applicable law or
150
- agreed to in writing, Licensor provides the Work (and each
151
- Contributor provides its Contributions) on an "AS IS" BASIS,
152
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
153
- implied, including, without limitation, any warranties or conditions
154
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
155
- PARTICULAR PURPOSE. You are solely responsible for determining the
156
- appropriateness of using or redistributing the Work and assume any
157
- risks associated with Your exercise of permissions under this License.
158
-
159
- 8. Limitation of Liability. In no event and under no legal theory,
160
- whether in tort (including negligence), contract, or otherwise,
161
- unless required by applicable law (such as deliberate and grossly
162
- negligent acts) or agreed to in writing, shall any Contributor be
163
- liable to You for damages, including any direct, indirect, special,
164
- incidental, or consequential damages of any character arising as a
165
- result of this License or out of the use or inability to use the
166
- Work (including but not limited to damages for loss of goodwill,
167
- work stoppage, computer failure or malfunction, or any and all
168
- other commercial damages or losses), even if such Contributor
169
- has been advised of the possibility of such damages.
170
-
171
- 9. Accepting Warranty or Additional Liability. While redistributing
172
- the Work or Derivative Works thereof, You may choose to offer,
173
- and charge a fee for, acceptance of support, warranty, indemnity,
174
- or other liability obligations and/or rights consistent with this
175
- License. However, in accepting such obligations, You may act only
176
- on Your own behalf and on Your sole responsibility, not on behalf
177
- of any other Contributor, and only if You agree to indemnify,
178
- defend, and hold each Contributor harmless for any liability
179
- incurred by, or claims asserted against, such Contributor by reason
180
- of your accepting any such warranty or additional liability.
181
-
182
- END OF TERMS AND CONDITIONS
183
-
184
- APPENDIX: How to apply the Apache License to your work.
185
-
186
- To apply the Apache License to your work, attach the following
187
- boilerplate notice, with the fields enclosed by brackets "[]"
188
- replaced with your own identifying information. (Don't include
189
- the brackets!) The text should be enclosed in the appropriate
190
- comment syntax for the file format. We also recommend that a
191
- file or class name and description of purpose be included on the
192
- same "printed page" as the copyright notice for easier
193
- identification within third-party archives.
194
-
195
- Copyright [yyyy] [name of copyright owner]
196
-
197
- Licensed under the Apache License, Version 2.0 (the "License");
198
- you may not use this file except in compliance with the License.
199
- You may obtain a copy of the License at
200
-
201
- http://www.apache.org/licenses/LICENSE-2.0
202
-
203
- Unless required by applicable law or agreed to in writing, software
204
- distributed under the License is distributed on an "AS IS" BASIS,
205
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
206
- See the License for the specific language governing permissions and
207
- limitations under the License.
208
- License-File: LICENSE
209
- Classifier: License :: OSI Approved :: Apache Software License
210
- Classifier: Programming Language :: Python
211
- Classifier: Programming Language :: Python :: 3
212
- Requires-Python: >=3.9
213
- Requires-Dist: cachebox
214
- Requires-Dist: grpcio>=1.68.1
215
- Requires-Dist: mmh3>=4.1.0
216
- Requires-Dist: openfeature-sdk>=0.6.0
217
- Requires-Dist: panzi-json-logic>=1.0.1
218
- Requires-Dist: protobuf>=5.26.1
219
- Requires-Dist: pyyaml>=6.0.1
220
- Requires-Dist: semver<4,>=3
221
- Description-Content-Type: text/markdown
222
-
223
- # flagd Provider for OpenFeature
224
-
225
- This provider is designed to use flagd's [evaluation protocol](https://github.com/open-feature/schemas/blob/main/protobuf/schema/v1/schema.proto), or locally evaluate flags defined in a flagd [flag definition](https://github.com/open-feature/schemas/blob/main/json/flagd-definitions.json) via the OpenFeature Python SDK.
226
-
227
- ## Installation
228
-
229
- ```
230
- pip install openfeature-provider-flagd
231
- ```
232
-
233
- ## Configuration and Usage
234
-
235
- The flagd provider can operate in two modes: [RPC](#remote-resolver-rpc) (evaluation takes place in flagd, via gRPC calls) or [in-process](#in-process-resolver) (evaluation takes place in-process, with the provider getting a ruleset from a compliant sync-source).
236
-
237
- ### Remote resolver (RPC)
238
-
239
- This is the default mode of operation of the provider.
240
- In this mode, `FlagdProvider` communicates with [flagd](https://github.com/open-feature/flagd) via the gRPC protocol.
241
- Flag evaluations take place remotely at the connected flagd instance.
242
-
243
- Instantiate a new FlagdProvider instance and configure the OpenFeature SDK to use it:
244
-
245
- ```python
246
- from openfeature import api
247
- from openfeature.contrib.provider.flagd import FlagdProvider
248
-
249
- api.set_provider(FlagdProvider())
250
- ```
251
-
252
- ### In-process resolver
253
-
254
- This mode performs flag evaluations locally (in-process). Flag configurations for evaluation are obtained via gRPC protocol using [sync protobuf schema](https://buf.build/open-feature/flagd/file/main:sync/v1/sync_service.proto) service definition.
255
-
256
- Consider the following example to create a `FlagdProvider` with in-process evaluations,
257
-
258
- ```python
259
- from openfeature import api
260
- from openfeature.contrib.provider.flagd import FlagdProvider
261
- from openfeature.contrib.provider.flagd.config import ResolverType
262
-
263
- api.set_provider(FlagdProvider(
264
- resolver_type=ResolverType.IN_PROCESS,
265
- ))
266
- ```
267
-
268
- In the above example, in-process handlers attempt to connect to a sync service on address `localhost:8013` to obtain [flag definitions](https://github.com/open-feature/schemas/blob/main/json/flags.json).
269
-
270
- <!--
271
- #### Sync-metadata
272
-
273
- To support the injection of contextual data configured in flagd for in-process evaluation, the provider exposes a `getSyncMetadata` accessor which provides the most recent value returned by the [GetMetadata RPC](https://buf.build/open-feature/flagd/docs/main:flagd.sync.v1#flagd.sync.v1.FlagSyncService.GetMetadata).
274
- The value is updated with every (re)connection to the sync implementation.
275
- This can be used to enrich evaluations with such data.
276
- If the `in-process` mode is not used, and before the provider is ready, the `getSyncMetadata` returns an empty map.
277
- -->
278
- ### File mode
279
-
280
- In-process resolvers can also work in an offline mode.
281
- To enable this mode, you should provide a valid flag configuration file with the option `offlineFlagSourcePath`.
282
-
283
- ```python
284
- from openfeature import api
285
- from openfeature.contrib.provider.flagd import FlagdProvider
286
- from openfeature.contrib.provider.flagd.config import ResolverType
287
-
288
- api.set_provider(FlagdProvider(
289
- resolver_type=ResolverType.FILE,
290
- offline_flag_source_path="my-flag.json",
291
- ))
292
- ```
293
-
294
- Provider will attempt to detect file changes using polling.
295
- Polling happens at 5 second intervals and this is currently unconfigurable.
296
- This mode is useful for local development, tests and offline applications.
297
-
298
- ### Configuration options
299
-
300
- The default options can be defined in the FlagdProvider constructor.
301
-
302
- | Option name | Environment variable name | Type & Values | Default | Compatible resolver |
303
- |--------------------------|--------------------------------|----------------------------|-------------------------------|---------------------|
304
- | resolver_type | FLAGD_RESOLVER | enum - `rpc`, `in-process` | rpc | |
305
- | host | FLAGD_HOST | str | localhost | rpc & in-process |
306
- | port | FLAGD_PORT | int | 8013 (rpc), 8015 (in-process) | rpc & in-process |
307
- | tls | FLAGD_TLS | bool | false | rpc & in-process |
308
- | cert_path | FLAGD_SERVER_CERT_PATH | String | null | rpc & in-process |
309
- | deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process |
310
- | stream_deadline_ms | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
311
- | keep_alive_time | FLAGD_KEEP_ALIVE_TIME_MS | int | 0 | rpc & in-process |
312
- | selector | FLAGD_SOURCE_SELECTOR | str | null | in-process |
313
- | cache_type | FLAGD_CACHE | enum - `lru`, `disabled` | lru | rpc |
314
- | max_cache_size | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
315
- | retry_backoff_ms | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
316
- | offline_flag_source_path | FLAGD_OFFLINE_FLAG_SOURCE_PATH | str | null | in-process |
317
-
318
- <!-- not implemented
319
- | target_uri | FLAGD_TARGET_URI | alternative to host/port, supporting custom name resolution | string | null | rpc & in-process |
320
- | socket_path | FLAGD_SOCKET_PATH | alternative to host port, unix socket | String | null | rpc & in-process |
321
- | context_enricher | - | sync-metadata to evaluation context mapping function | function | identity function | in-process |
322
- | offline_pollIntervalMs | FLAGD_OFFLINE_POLL_MS | poll interval for reading offlineFlagSourcePath | int | 5000 | in-process |
323
- -->
324
-
325
- > [!NOTE]
326
- > Some configurations are only applicable for RPC resolver.
327
-
328
- <!--
329
- ### Unix socket support
330
- Unix socket communication with flagd is facilitated by usaging of the linux-native `epoll` library on `linux-x86_64`
331
- only (ARM support is pending the release of `netty-transport-native-epoll` v5).
332
- Unix sockets are not supported on other platforms or architectures.
333
- -->
334
-
335
- ### Reconnection
336
-
337
- Reconnection is supported by the underlying gRPC connections.
338
- If the connection to flagd is lost, it will reconnect automatically.
339
- A failure to connect will result in an [error event](https://openfeature.dev/docs/reference/concepts/events#provider_error) from the provider, though it will attempt to reconnect indefinitely.
340
-
341
- ### Deadlines
342
-
343
- Deadlines are used to define how long the provider waits to complete initialization or flag evaluations.
344
- They behave differently based on the resolver type.
345
-
346
- #### Deadlines with Remote resolver (RPC)
347
-
348
- If the remote evaluation call is not completed within this deadline, the gRPC call is terminated with the error `DEADLINE_EXCEEDED`
349
- and the evaluation will default.
350
-
351
- ### TLS
352
-
353
- TLS is available in situations where flagd is running on another host.
354
-
355
-
356
- You may optionally supply an X.509 certificate in PEM format. Otherwise, the default certificate store will be used.
357
-
358
- ```python
359
- from openfeature import api
360
- from openfeature.contrib.provider.flagd import FlagdProvider
361
-
362
- api.set_provider(FlagdProvider(
363
- tls=True, # use TLS
364
- cert_path="etc/cert/ca.crt" # PEM cert
365
- ))
366
- ```
367
-
368
- ## License
369
-
370
- Apache 2.0 - See [LICENSE](./LICENSE) for more information.