Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"distinct_id_random_22", person_properties={"$geoip_city_name": "Sydney"}, only_evaluate_locally=True
)
)
print(posthog.get_remote_config_payload("encrypted_payload_flag_key"))


posthog.shutdown()
20 changes: 20 additions & 0 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,26 @@ def get_feature_flag_payload(
)


def get_remote_config_payload(
key, # type: str
):
"""Get the payload for a remote config feature flag.

Args:
key: The key of the feature flag

Returns:
The payload associated with the feature flag. If payload is encrypted, the return value will decrypted

Note:
Requires personal_api_key to be set for authentication
"""
return _proxy(
"get_remote_config_payload",
key=key,
)


def get_all_flags_and_payloads(
distinct_id,
groups={},
Expand Down
22 changes: 21 additions & 1 deletion posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple, handle_in_app
from posthog.feature_flags import InconclusiveMatchError, match_feature_flag_properties
from posthog.poller import Poller
from posthog.request import DEFAULT_HOST, APIError, batch_post, decide, determine_server_host, get
from posthog.request import DEFAULT_HOST, APIError, batch_post, decide, determine_server_host, get, remote_config
from posthog.utils import SizeLimitedDict, clean, guess_timezone, remove_trailing_slash
from posthog.version import VERSION

Expand Down Expand Up @@ -849,6 +849,26 @@ def get_feature_flag_payload(

return payload

def get_remote_config_payload(self, key: str):
if self.disabled:
return None

if self.personal_api_key is None:
self.log.warning(
"[FEATURE FLAGS] You have to specify a personal_api_key to fetch decrypted feature flag payloads."
)
return None

try:
return remote_config(
self.personal_api_key,
self.host,
key,
timeout=self.feature_flags_request_timeout_seconds,
)
except Exception as e:
self.log.exception(f"[FEATURE FLAGS] Unable to get decrypted feature flag payload: {e}")

def _compute_payload_locally(self, key, match_value):
payload = None

Expand Down
5 changes: 5 additions & 0 deletions posthog/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def decide(api_key: str, host: Optional[str] = None, gzip: bool = False, timeout
return _process_response(res, success_message="Feature flags decided successfully")


def remote_config(personal_api_key: str, host: Optional[str] = None, key: str = "", timeout: int = 15) -> Any:
"""Get remote config flag value from remote_config API endpoint"""
return get(personal_api_key, f"/api/projects/@current/feature_flags/{key}/remote_config/", host, timeout)


def batch_post(
api_key: str, host: Optional[str] = None, gzip: bool = False, timeout: int = 15, **kwargs
) -> requests.Response:
Expand Down
2 changes: 1 addition & 1 deletion posthog/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "3.13.0"
VERSION = "3.14.0"

if __name__ == "__main__":
print(VERSION, end="") # noqa: T201