dynatrace-openfeature-provider-python 0.0.4__tar.gz → 0.1.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.
Files changed (16) hide show
  1. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/PKG-INFO +10 -3
  2. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/README.md +9 -2
  3. dynatrace_openfeature_provider_python-0.1.0/pyproject.toml +159 -0
  4. dynatrace_openfeature_provider_python-0.0.4/pyproject.toml → dynatrace_openfeature_provider_python-0.1.0/pyproject.toml.orig +1 -1
  5. dynatrace_openfeature_provider_python-0.1.0/src/dynatrace/openfeature/options.py +106 -0
  6. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/provider.py +2 -2
  7. dynatrace_openfeature_provider_python-0.0.4/src/dynatrace/openfeature/options.py +0 -68
  8. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/LICENSE +0 -0
  9. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/__init__.py +0 -0
  10. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_cdn.py +0 -0
  11. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_metrics_aggregator.py +0 -0
  12. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_metrics_flusher.py +0 -0
  13. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_metrics_hook.py +0 -0
  14. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_polling.py +0 -0
  15. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/_retry.py +0 -0
  16. {dynatrace_openfeature_provider_python-0.0.4 → dynatrace_openfeature_provider_python-0.1.0}/src/dynatrace/openfeature/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynatrace-openfeature-provider-python
3
- Version: 0.0.4
3
+ Version: 0.1.0
4
4
  Summary: The official Dynatrace OpenFeature provider for Python
5
5
  Keywords: openfeature,dynatrace,feature-flags,feature-management
6
6
  Author: Dynatrace
@@ -49,10 +49,17 @@ enabled = client.get_boolean_value('my-feature', False, ctx)
49
49
  api.shutdown()
50
50
  ```
51
51
 
52
- ### CDN base URL override (labs / dev environments)
52
+ ### Config origin override (labs / dev environments)
53
+
54
+ By default the config endpoint is derived from the SDK key. To point the provider at a
55
+ different environment or at an SDK proxy, pass `config_origin`. The value is an origin
56
+ only — scheme, host, and optional port, with no path. The provider appends the platform
57
+ and key segments itself.
53
58
 
54
59
  ```python
55
- options = DynatraceProviderOptions.from_sdk_key(sdk_key)
60
+ api.set_provider(
61
+ DynatraceProvider(sdk_key, config_origin='https://cdn.eu.fm.dynatracelabs.com')
62
+ )
56
63
  ```
57
64
 
58
65
  ## Architecture
@@ -31,10 +31,17 @@ enabled = client.get_boolean_value('my-feature', False, ctx)
31
31
  api.shutdown()
32
32
  ```
33
33
 
34
- ### CDN base URL override (labs / dev environments)
34
+ ### Config origin override (labs / dev environments)
35
+
36
+ By default the config endpoint is derived from the SDK key. To point the provider at a
37
+ different environment or at an SDK proxy, pass `config_origin`. The value is an origin
38
+ only — scheme, host, and optional port, with no path. The provider appends the platform
39
+ and key segments itself.
35
40
 
36
41
  ```python
37
- options = DynatraceProviderOptions.from_sdk_key(sdk_key)
42
+ api.set_provider(
43
+ DynatraceProvider(sdk_key, config_origin='https://cdn.eu.fm.dynatracelabs.com')
44
+ )
38
45
  ```
39
46
 
40
47
  ## Architecture
@@ -0,0 +1,159 @@
1
+ [build-system]
2
+ requires = ["uv_build~=0.10.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "dynatrace-openfeature-provider-python"
7
+ version = "0.1.0"
8
+ description = "The official Dynatrace OpenFeature provider for Python"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ classifiers = [
13
+ "Programming Language :: Python",
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: Apache Software License",
16
+ ]
17
+ keywords = [
18
+ "openfeature",
19
+ "dynatrace",
20
+ "feature-flags",
21
+ "feature-management",
22
+ ]
23
+ dependencies = [
24
+ "openfeature-sdk>=0.8.2",
25
+ "openfeature-flagd-core>=1.0.0,<2.0.0",
26
+ "requests>=2.27.0",
27
+ ]
28
+ requires-python = ">=3.10"
29
+
30
+ [[project.authors]]
31
+ name = "Dynatrace"
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/Dynatrace/openfeature-provider-python"
35
+
36
+ [dependency-groups]
37
+ dev = [
38
+ "coverage[toml]>=7.10.0,<8.0.0",
39
+ "mypy>=1.18.0,<2.0.0",
40
+ "poethepoet>=0.37.0",
41
+ "pytest>=9.0.0,<10.0.0",
42
+ "responses>=0.25.0,<1.0.0",
43
+ "pre-commit>=4.0.0",
44
+ "ruff>=0.15.13",
45
+ "types-requests>=2.32.0,<3.0.0",
46
+ ]
47
+
48
+ [tool.uv.build-backend]
49
+ module-name = "dynatrace"
50
+ module-root = "src"
51
+ namespace = true
52
+
53
+ [tool.coverage.run]
54
+ omit = ["tests/**"]
55
+
56
+ [tool.mypy]
57
+ mypy_path = "src"
58
+ files = "src"
59
+ python_version = "3.10"
60
+ namespace_packages = true
61
+ explicit_package_bases = true
62
+ local_partial_types = true
63
+ allow_redefinition_new = true
64
+ fixed_format_cache = true
65
+ pretty = true
66
+ strict = true
67
+ disallow_any_generics = false
68
+
69
+ [tool.ruff]
70
+ target-version = "py310"
71
+ exclude = [
72
+ ".git",
73
+ ".venv",
74
+ "__pycache__",
75
+ "venv",
76
+ ]
77
+
78
+ [tool.ruff.lint]
79
+ select = [
80
+ "A",
81
+ "B",
82
+ "C4",
83
+ "C90",
84
+ "E",
85
+ "F",
86
+ "FLY",
87
+ "FURB",
88
+ "I",
89
+ "ICN003",
90
+ "LOG",
91
+ "N",
92
+ "PERF",
93
+ "PGH",
94
+ "PLC",
95
+ "PLR0913",
96
+ "PLR0915",
97
+ "RUF",
98
+ "S",
99
+ "SIM",
100
+ "T10",
101
+ "T20",
102
+ "TID251",
103
+ "UP",
104
+ "W",
105
+ "YTT",
106
+ ]
107
+ ignore = ["E501"]
108
+
109
+ [tool.ruff.lint.per-file-ignores]
110
+ "**/tests/**/*" = ["S101"]
111
+
112
+ [tool.ruff.lint.flake8-import-conventions]
113
+ banned-from = ["typing"]
114
+
115
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.Awaitable"]
116
+ msg = "Use collections.abc.Awaitable instead"
117
+
118
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.Callable"]
119
+ msg = "Use collections.abc.Callable instead"
120
+
121
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.Collection"]
122
+ msg = "Use collections.abc.Collection instead"
123
+
124
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.Mapping"]
125
+ msg = "Use collections.abc.Mapping instead"
126
+
127
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.MutableMapping"]
128
+ msg = "Use collections.abc.MutableMapping instead"
129
+
130
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.MutableSequence"]
131
+ msg = "Use collections.abc.MutableSequence instead"
132
+
133
+ [tool.ruff.lint.flake8-tidy-imports.banned-api."typing.Sequence"]
134
+ msg = "Use collections.abc.Sequence instead"
135
+
136
+ [tool.ruff.lint.isort]
137
+ known-first-party = ["dynatrace"]
138
+
139
+ [tool.ruff.lint.pylint]
140
+ max-args = 8
141
+ max-statements = 30
142
+
143
+ [tool.ruff.lint.pyupgrade]
144
+ keep-runtime-typing = true
145
+
146
+ [tool.pytest.ini_options]
147
+ strict = true
148
+
149
+ [tool.poe.tasks]
150
+ test = "pytest tests"
151
+ test-cov = "coverage run -m pytest tests"
152
+ cov-report = "coverage xml"
153
+ cov = [
154
+ "test-cov",
155
+ "cov-report",
156
+ ]
157
+ mypy = "mypy"
158
+ lint = "ruff check src tests"
159
+ fmt = "ruff format src tests"
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "dynatrace-openfeature-provider-python"
7
- version = "0.0.4"
7
+ version = "0.1.0"
8
8
  description = "The official Dynatrace OpenFeature provider for Python"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Dynatrace" }]
@@ -0,0 +1,106 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from urllib.parse import urlparse
5
+
6
+ # SDK key format per providers.md §3.0:
7
+ # {token}.server_{geo}_{publicRandom}.{secret}_{sha1}
8
+ _KEY_PATTERN = re.compile(
9
+ r"^(dt[0-9]{2})\.(server)_([a-z]{2,})_([a-zA-Z0-9]{10,})\.([a-fA-F0-9]{32,})_([a-f0-9]{10,})$"
10
+ )
11
+
12
+ _ALLOWED_SCHEMES = ("http", "https")
13
+
14
+
15
+ def _normalise_config_origin(value: str) -> str:
16
+ """Validate that ``value`` is a bare origin and return it in canonical form.
17
+
18
+ An origin is a scheme, host, and optional port — nothing else. Anything the
19
+ platform and key segments could not be safely appended to is rejected here,
20
+ so a malformed override fails at construction rather than as a 404 on the
21
+ first config fetch.
22
+ """
23
+ try:
24
+ parsed = urlparse(value)
25
+ except ValueError as exc:
26
+ raise ValueError(f"config_origin is not a valid URL; got {value!r}") from exc
27
+ if parsed.scheme not in _ALLOWED_SCHEMES:
28
+ raise ValueError(f"config_origin must use http or https; got {value!r}")
29
+ try:
30
+ port = parsed.port
31
+ except ValueError as exc:
32
+ raise ValueError(f"config_origin has an invalid port; got {value!r}") from exc
33
+ if not parsed.hostname:
34
+ raise ValueError(f"config_origin must include a host; got {value!r}")
35
+ if parsed.path.rstrip("/"):
36
+ raise ValueError(f"config_origin must not include a path; got {value!r}")
37
+ if parsed.query:
38
+ raise ValueError(
39
+ f"config_origin must not include a query string; got {value!r}"
40
+ )
41
+ if parsed.fragment:
42
+ raise ValueError(f"config_origin must not include a fragment; got {value!r}")
43
+ if parsed.username or parsed.password:
44
+ raise ValueError(f"config_origin must not include user info; got {value!r}")
45
+ host = parsed.hostname if port is None else f"{parsed.hostname}:{port}"
46
+ return f"{parsed.scheme}://{host}"
47
+
48
+
49
+ class DynatraceProviderOptions:
50
+ __slots__ = ("_cdn_url", "_key", "_metrics_url")
51
+
52
+ def __init__(self, key: str, cdn_url: str, metrics_url: str) -> None:
53
+ self._key = key
54
+ self._cdn_url = cdn_url
55
+ self._metrics_url = metrics_url
56
+
57
+ @classmethod
58
+ def from_sdk_key(
59
+ cls,
60
+ sdk_key: str,
61
+ config_origin: str | None = None,
62
+ metrics_url: str | None = None,
63
+ ) -> DynatraceProviderOptions:
64
+ if not sdk_key or not sdk_key.strip():
65
+ raise ValueError("sdk_key must not be null or blank")
66
+ trimmed = sdk_key.strip()
67
+ key_match = _KEY_PATTERN.match(trimmed)
68
+ if not key_match:
69
+ last_dot = trimmed.rfind(".")
70
+ public_part = trimmed[:last_dot] if last_dot > 0 else "<redacted>"
71
+ raise ValueError(
72
+ f"invalid key format (public: {public_part!r}); "
73
+ "expected dt{NN}.server_{geo}_{rand}.{secret}_{sha}"
74
+ )
75
+ _token, platform, geo, _rand, _secret, _sha = key_match.groups()
76
+ if config_origin is not None:
77
+ config_origin = config_origin.strip()
78
+ if not config_origin:
79
+ raise ValueError("config_origin must not be blank")
80
+ origin = _normalise_config_origin(config_origin)
81
+ base = origin + "/" + platform + "/"
82
+ else:
83
+ base = f"https://cdn.{geo}.fm.dynatrace.com/{platform}/"
84
+ cdn_url = base + trimmed + ".json"
85
+ if metrics_url is not None:
86
+ metrics_url = metrics_url.strip()
87
+ if not metrics_url:
88
+ raise ValueError("metrics_url must not be blank")
89
+ resolved_metrics_url = metrics_url
90
+ else:
91
+ resolved_metrics_url = f"https://metrics.{geo}.fm.dynatrace.com/v1/metrics"
92
+ return cls(key=trimmed, cdn_url=cdn_url, metrics_url=resolved_metrics_url)
93
+
94
+ @property
95
+ def public_key(self) -> str:
96
+ # Everything before the last '.' — safe to log; never exposes the secret segment.
97
+ idx = self._key.rfind(".")
98
+ return self._key[:idx] if idx > 0 else "<redacted>"
99
+
100
+ @property
101
+ def cdn_url(self) -> str:
102
+ return self._cdn_url
103
+
104
+ @property
105
+ def metrics_url(self) -> str:
106
+ return self._metrics_url
@@ -49,7 +49,7 @@ class DynatraceProvider(AbstractProvider):
49
49
  self,
50
50
  sdk_key: str,
51
51
  *,
52
- cdn_base_url: str | None = None,
52
+ config_origin: str | None = None,
53
53
  metrics_url: str | None = None,
54
54
  flagd_core: FlagdCore | None = None,
55
55
  fetcher: CdnFetcher | None = None,
@@ -59,7 +59,7 @@ class DynatraceProvider(AbstractProvider):
59
59
  metrics_flush_interval_s: float = _METRICS_FLUSH_INTERVAL_S,
60
60
  ) -> None:
61
61
  options = DynatraceProviderOptions.from_sdk_key(
62
- sdk_key, cdn_base_url=cdn_base_url, metrics_url=metrics_url
62
+ sdk_key, config_origin=config_origin, metrics_url=metrics_url
63
63
  )
64
64
  if fetcher is None and poll_interval_s <= _REQUEST_TIMEOUT_S:
65
65
  raise ValueError(
@@ -1,68 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import re
4
-
5
- # SDK key format per providers.md §3.0:
6
- # {token}.server_{geo}_{publicRandom}.{secret}_{sha1}
7
- _KEY_PATTERN = re.compile(
8
- r"^(dt[0-9]{2})\.(server)_([a-z]{2,})_([a-zA-Z0-9]{10,})\.([a-fA-F0-9]{32,})_([a-f0-9]{10,})$"
9
- )
10
-
11
-
12
- class DynatraceProviderOptions:
13
- __slots__ = ("_cdn_url", "_key", "_metrics_url")
14
-
15
- def __init__(self, key: str, cdn_url: str, metrics_url: str) -> None:
16
- self._key = key
17
- self._cdn_url = cdn_url
18
- self._metrics_url = metrics_url
19
-
20
- @classmethod
21
- def from_sdk_key(
22
- cls,
23
- sdk_key: str,
24
- cdn_base_url: str | None = None,
25
- metrics_url: str | None = None,
26
- ) -> DynatraceProviderOptions:
27
- if not sdk_key or not sdk_key.strip():
28
- raise ValueError("sdk_key must not be null or blank")
29
- trimmed = sdk_key.strip()
30
- key_match = _KEY_PATTERN.match(trimmed)
31
- if not key_match:
32
- last_dot = trimmed.rfind(".")
33
- public_part = trimmed[:last_dot] if last_dot > 0 else "<redacted>"
34
- raise ValueError(
35
- f"invalid key format (public: {public_part!r}); "
36
- "expected dt{NN}.server_{geo}_{rand}.{secret}_{sha}"
37
- )
38
- _token, _platform, geo, _rand, _secret, _sha = key_match.groups()
39
- if cdn_base_url is not None:
40
- cdn_base_url = cdn_base_url.strip()
41
- if not cdn_base_url:
42
- raise ValueError("cdn_base_url must not be blank")
43
- base = cdn_base_url if cdn_base_url.endswith("/") else cdn_base_url + "/"
44
- else:
45
- base = f"https://cdn.{geo}.fm.dynatrace.com/server/"
46
- cdn_url = base + trimmed + ".json"
47
- if metrics_url is not None:
48
- metrics_url = metrics_url.strip()
49
- if not metrics_url:
50
- raise ValueError("metrics_url must not be blank")
51
- resolved_metrics_url = metrics_url
52
- else:
53
- resolved_metrics_url = f"https://metrics.{geo}.fm.dynatrace.com/v1/metrics"
54
- return cls(key=trimmed, cdn_url=cdn_url, metrics_url=resolved_metrics_url)
55
-
56
- @property
57
- def public_key(self) -> str:
58
- # Everything before the last '.' — safe to log; never exposes the secret segment.
59
- idx = self._key.rfind(".")
60
- return self._key[:idx] if idx > 0 else "<redacted>"
61
-
62
- @property
63
- def cdn_url(self) -> str:
64
- return self._cdn_url
65
-
66
- @property
67
- def metrics_url(self) -> str:
68
- return self._metrics_url