Skip to content

Commit da33db3

Browse files
authored
feat: use-context-evaluation-with-newest-engine-version (#182)
1 parent d43c903 commit da33db3

File tree

14 files changed

+615
-243
lines changed

14 files changed

+615
-243
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ name = "edge-proxy"
44
license = { file = "LICENSE" }
55
dependencies = [
66
"fastapi",
7-
"flagsmith-flag-engine>=6,<7",
7+
"flagsmith-flag-engine>=10,<11",
8+
"flagsmith>=5",
89
"httpx",
910
"marshmallow",
1011
"orjson",

requirements-dev.lock

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9+
# generate-hashes: false
10+
# universal: false
911

1012
-e file:.
1113
annotated-types==0.6.0
@@ -16,8 +18,11 @@ anyio==4.3.0
1618
certifi==2024.2.2
1719
# via httpcore
1820
# via httpx
21+
# via requests
1922
cfgv==3.4.0
2023
# via pre-commit
24+
charset-normalizer==3.4.4
25+
# via requests
2126
classify-imports==4.2.0
2227
# via reorder-python-imports
2328
click==8.1.7
@@ -28,8 +33,11 @@ fastapi==0.110.1
2833
# via edge-proxy
2934
filelock==3.13.3
3035
# via virtualenv
31-
flagsmith-flag-engine==6.1.0
36+
flagsmith==5.0.3
3237
# via edge-proxy
38+
flagsmith-flag-engine==10.0.3
39+
# via edge-proxy
40+
# via flagsmith
3341
freezegun==1.4.0
3442
# via pytest-freezegun
3543
h11==0.14.0
@@ -44,8 +52,13 @@ identify==2.5.35
4452
idna==3.6
4553
# via anyio
4654
# via httpx
55+
# via requests
4756
iniconfig==2.0.0
4857
# via pytest
58+
iregexp-check==0.1.4
59+
# via jsonpath-rfc9535
60+
jsonpath-rfc9535==0.2.0
61+
# via flagsmith-flag-engine
4962
marshmallow==3.21.1
5063
# via edge-proxy
5164
nodeenv==1.8.0
@@ -63,11 +76,7 @@ pre-commit==3.7.0
6376
pydantic==2.7.1
6477
# via edge-proxy
6578
# via fastapi
66-
# via flagsmith-flag-engine
67-
# via pydantic-collections
6879
# via pydantic-settings
69-
pydantic-collections==0.5.4
70-
# via flagsmith-flag-engine
7180
pydantic-core==2.18.2
7281
# via pydantic
7382
pydantic-settings==2.2.1
@@ -88,8 +97,15 @@ python-dotenv==1.0.1
8897
# via pydantic-settings
8998
pyyaml==6.0.1
9099
# via pre-commit
100+
regex==2025.11.3
101+
# via jsonpath-rfc9535
91102
reorder-python-imports==3.12.0
92-
semver==3.0.2
103+
requests==2.32.5
104+
# via flagsmith
105+
# via requests-futures
106+
requests-futures==1.0.2
107+
# via flagsmith
108+
semver==3.0.4
93109
# via flagsmith-flag-engine
94110
setuptools==69.2.0
95111
# via nodeenv
@@ -98,15 +114,20 @@ six==1.16.0
98114
sniffio==1.3.1
99115
# via anyio
100116
# via httpx
117+
sseclient-py==1.8.0
118+
# via flagsmith
101119
starlette==0.37.2
102120
# via fastapi
103121
structlog==24.1.0
104122
# via edge-proxy
105-
typing-extensions==4.11.0
123+
typing-extensions==4.15.0
106124
# via fastapi
125+
# via flagsmith
126+
# via flagsmith-flag-engine
107127
# via pydantic
108-
# via pydantic-collections
109128
# via pydantic-core
129+
urllib3==2.6.2
130+
# via requests
110131
uvicorn==0.29.0
111132
# via edge-proxy
112133
virtualenv==20.25.1

requirements.lock

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9+
# generate-hashes: false
10+
# universal: false
911

1012
-e file:.
1113
annotated-types==0.6.0
@@ -16,12 +18,18 @@ anyio==4.3.0
1618
certifi==2024.2.2
1719
# via httpcore
1820
# via httpx
21+
# via requests
22+
charset-normalizer==3.4.4
23+
# via requests
1924
click==8.1.7
2025
# via uvicorn
2126
fastapi==0.110.1
2227
# via edge-proxy
23-
flagsmith-flag-engine==6.1.0
28+
flagsmith==5.0.3
2429
# via edge-proxy
30+
flagsmith-flag-engine==10.0.3
31+
# via edge-proxy
32+
# via flagsmith
2533
h11==0.14.0
2634
# via httpcore
2735
# via uvicorn
@@ -32,6 +40,11 @@ httpx==0.27.0
3240
idna==3.6
3341
# via anyio
3442
# via httpx
43+
# via requests
44+
iregexp-check==0.1.4
45+
# via jsonpath-rfc9535
46+
jsonpath-rfc9535==0.2.0
47+
# via flagsmith-flag-engine
3548
marshmallow==3.21.1
3649
# via edge-proxy
3750
orjson==3.10.0
@@ -41,11 +54,7 @@ packaging==24.0
4154
pydantic==2.7.1
4255
# via edge-proxy
4356
# via fastapi
44-
# via flagsmith-flag-engine
45-
# via pydantic-collections
4657
# via pydantic-settings
47-
pydantic-collections==0.5.4
48-
# via flagsmith-flag-engine
4958
pydantic-core==2.18.2
5059
# via pydantic
5160
pydantic-settings==2.2.1
@@ -55,19 +64,31 @@ python-decouple==3.8
5564
python-dotenv==1.0.1
5665
# via edge-proxy
5766
# via pydantic-settings
58-
semver==3.0.2
67+
regex==2025.11.3
68+
# via jsonpath-rfc9535
69+
requests==2.32.5
70+
# via flagsmith
71+
# via requests-futures
72+
requests-futures==1.0.2
73+
# via flagsmith
74+
semver==3.0.4
5975
# via flagsmith-flag-engine
6076
sniffio==1.3.1
6177
# via anyio
6278
# via httpx
79+
sseclient-py==1.8.0
80+
# via flagsmith
6381
starlette==0.37.2
6482
# via fastapi
6583
structlog==24.1.0
6684
# via edge-proxy
67-
typing-extensions==4.11.0
85+
typing-extensions==4.15.0
6886
# via fastapi
87+
# via flagsmith
88+
# via flagsmith-flag-engine
6989
# via pydantic
70-
# via pydantic-collections
7190
# via pydantic-core
91+
urllib3==2.6.2
92+
# via requests
7293
uvicorn==0.29.0
7394
# via edge-proxy

src/edge_proxy/cache.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from abc import ABC
2-
from collections import defaultdict
1+
from abc import ABC, abstractmethod
32
from typing import Any
43

4+
from edge_proxy.feature_utils import build_feature_types_lookup
5+
56

67
class BaseEnvironmentsCache(ABC):
78
def __init__(self, *args, **kwargs):
@@ -24,22 +25,18 @@ def put_environment(
2425
return True
2526
return False
2627

28+
@abstractmethod
2729
def _put_environment(
2830
self,
2931
environment_api_key: str,
3032
environment_document: dict[str, Any],
31-
) -> None:
32-
raise NotImplementedError()
33+
) -> None: ...
3334

34-
def get_environment(self, environment_api_key: str) -> dict[str, Any] | None:
35-
raise NotImplementedError()
35+
@abstractmethod
36+
def get_environment(self, environment_api_key: str) -> dict[str, Any] | None: ...
3637

37-
def get_identity(
38-
self,
39-
environment_api_key: str,
40-
identifier: str,
41-
) -> dict[str, Any]:
42-
raise NotImplementedError()
38+
@abstractmethod
39+
def get_feature_types(self, environment_api_key: str) -> dict[int, str] | None: ...
4340

4441

4542
_LocalCacheDict = dict[str, dict[str, Any]]
@@ -49,33 +46,24 @@ class LocalMemEnvironmentsCache(BaseEnvironmentsCache):
4946
def __init__(self, *args, **kwargs):
5047
super().__init__(*args, **kwargs)
5148
self._environment_cache: _LocalCacheDict = {}
52-
self._identity_override_cache = defaultdict[str, _LocalCacheDict](dict)
49+
self._feature_types_cache: dict[str, dict[int, str]] = {}
5350

5451
def _put_environment(
5552
self,
5653
environment_api_key: str,
5754
environment_document: dict[str, Any],
5855
) -> None:
5956
self._environment_cache[environment_api_key] = environment_document
60-
new_overrides = environment_document.get("identity_overrides") or []
61-
self._identity_override_cache[environment_api_key] = {
62-
identifier: identity_document
63-
for identity_document in new_overrides
64-
if (identifier := identity_document.get("identifier"))
65-
}
57+
58+
self._feature_types_cache[environment_api_key] = build_feature_types_lookup(
59+
environment_document
60+
)
6661

6762
def get_environment(
6863
self,
6964
environment_api_key: str,
7065
) -> dict[str, Any] | None:
7166
return self._environment_cache.get(environment_api_key)
7267

73-
def get_identity(
74-
self,
75-
environment_api_key: str,
76-
identifier: str,
77-
) -> dict[str, Any]:
78-
return self._identity_override_cache[environment_api_key].get(identifier) or {
79-
"environment_api_key": environment_api_key,
80-
"identifier": identifier,
81-
}
68+
def get_feature_types(self, environment_api_key: str) -> dict[int, str] | None:
69+
return self._feature_types_cache.get(environment_api_key)

0 commit comments

Comments
 (0)