Skip to content

Commit 2be0619

Browse files
committed
feat(isolated): add factory module for isolated API instances
Signed-off-by: marcozabel <marco.zabel@dynatrace.com>
1 parent 8c8efa8 commit 2be0619

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

openfeature/isolated.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Factory for creating isolated OpenFeature API instances.
2+
3+
Per specification requirement 1.8.3, this module is intentionally separate
4+
from the global singleton ``openfeature.api`` to reduce the risk of
5+
accidentally creating isolated instances when the singleton is appropriate.
6+
7+
Usage::
8+
9+
from openfeature.isolated import create_api
10+
11+
api = create_api()
12+
api.set_provider(MyProvider())
13+
client = api.get_client()
14+
15+
Each instance returned by :func:`create_api` maintains its own providers,
16+
evaluation context, hooks, event handlers, and transaction context propagator
17+
— fully independent from the global singleton and from other instances.
18+
19+
A single provider instance should not be registered with more than one API
20+
instance simultaneously (spec requirement 1.8.4).
21+
"""
22+
23+
from openfeature._api import OpenFeatureAPI
24+
25+
__all__ = ["OpenFeatureAPI", "create_api"]
26+
27+
28+
def create_api() -> OpenFeatureAPI:
29+
"""Create a new, independent OpenFeature API instance.
30+
31+
The returned instance is functionally equivalent to the global singleton
32+
(``openfeature.api``), but with completely isolated state.
33+
34+
Returns:
35+
A new :class:`OpenFeatureAPI` instance.
36+
"""
37+
return OpenFeatureAPI()

0 commit comments

Comments
 (0)