-
Notifications
You must be signed in to change notification settings - Fork 69
feat(flags): add official PostHog OpenFeature provider #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
786fa8b
00ee43a
e5809e1
8f24613
5236b4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| *.pyc | ||
| __pycache__/ | ||
| .pytest_cache/ | ||
| .ruff_cache/ | ||
| .mypy_cache/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to `openfeature-provider-posthog` are documented here. This | ||
| file is maintained by [Sampo](https://github.com/bruits/sampo) from changesets in | ||
| `.sampo/changesets/` that target `pypi/openfeature-provider-posthog`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Copyright (c) 2023 PostHog (part of Hiberly Inc) | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # PostHog provider for OpenFeature (Python) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd move all install/snippets to https://posthog.com/docs/feature-flags and just point to the docs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 8f24613 — slimmed the README to a minimal quickstart and pointed to https://posthog.com/docs/feature-flags as the single source of truth. Kept only the OpenFeature-specific registration snippet + context mapping (not yet on the docs site); those can move there once the provider is documented.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done earlier in 8f24613 — README slimmed to a minimal quickstart pointing at https://posthog.com/docs/feature-flags as the source of truth. |
||
|
|
||
| Official [PostHog](https://posthog.com) provider for the | ||
| [OpenFeature](https://openfeature.dev) Python SDK. It resolves OpenFeature flag | ||
| evaluations through a configured `posthog.Posthog` client. | ||
|
|
||
| - **Distribution:** `openfeature-provider-posthog` | ||
| - **Import path:** `openfeature.contrib.provider.posthog` | ||
| - **License:** MIT | ||
|
|
||
| ## Documentation | ||
|
|
||
| PostHog's feature-flag docs are the single source of truth for flag setup, | ||
| concepts, and usage: **https://posthog.com/docs/feature-flags** | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| pip install openfeature-provider-posthog | ||
| ``` | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ```python | ||
| import posthog | ||
| from openfeature import api | ||
| from openfeature.evaluation_context import EvaluationContext | ||
| from openfeature.contrib.provider.posthog import PostHogProvider | ||
|
|
||
| client = posthog.Posthog("phc_project_api_key", host="https://us.i.posthog.com") | ||
| api.set_provider(PostHogProvider(client, default_distinct_id="anonymous")) | ||
|
|
||
| of_client = api.get_client() | ||
| ctx = EvaluationContext(targeting_key="user-123", attributes={"plan": "pro"}) | ||
| enabled = of_client.get_boolean_value("my-flag", False, ctx) | ||
| ``` | ||
|
|
||
| The OpenFeature `targeting_key` maps to PostHog's `distinct_id`; other context | ||
| attributes become person properties, with reserved keys `groups` and | ||
| `group_properties` mapping to PostHog groups. You own the `Posthog` client | ||
| lifecycle — call `client.shutdown()` when done. | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| cd openfeature-provider | ||
| uv sync --extra dev | ||
| uv run pytest | ||
| uv run ruff check . | ||
| uv run mypy . | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from openfeature.contrib.provider.posthog.provider import PostHogProvider | ||
|
|
||
| __all__ = ["PostHogProvider"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The package declares support for Python 3.10 through 3.14 (requires-pythonplus classifiers inpyproject.toml), but this job only tests on 3.12. mypy targets 3.10, so type errors are caught, but nothing exercises the floor or ceiling at runtime. A 3.10-only incompatibility or a 3.14 behavior change would ship unverified.The
testsandimport-checkjobs already matrix across all five versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree the matrix should mirror the
tests/import-checkjobs (3.10–3.14). I do not edit.github/workflows/**in this automated review-fix turn (guardrail), so I have left this for a maintainer to apply directly.