Repository navigation
Conversation
| ```python | ||
| from posthog import set_context_session | ||
| set_context_session("session_123") | ||
| set_context_session("0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b") |
There was a problem hiding this comment.
Revert this. it's a place holder whta are you doing gemini
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 5bed350: 1 Consider.
New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
| ``evaluate_flags()``, ``get_remote_config_payload()``, ``emails``, ``flush()``, | ||
| ``shutdown()``, and ``join()`` are awaitable. |
There was a problem hiding this comment.
P3 · Name the awaitable email methods instead of the property
Following this guidance with await client.emails raises TypeError: AsyncClient.emails is a synchronous property returning an AsyncEmails instance, and that class has no __await__ implementation. The awaitable operations are client.emails.send(...) and client.emails.get(...); list those methods instead in the constructor documentation.
There was a problem hiding this comment.
Already fixed in 11ec448a. The table in posthog/async_client.py now lists emails.send and emails.get instead of emails.
| such as ``memory://local/?ttl=300&size=10000`` or a Redis URL. | ||
| enable_local_evaluation: Whether to poll feature flag definitions for | ||
| local evaluation when a personal API key is configured. | ||
| local evaluation when ``secret_key`` is configured. |
There was a problem hiding this comment.
| local evaluation when ``secret_key`` is configured. | |
| local evaluation when ``secret_key`` is configured with your personal API key. |
for this also do a generic back link to relevant posthog settings page to get such a key
| Tags attach as event ``properties`` (overriding ``super_properties``, | ||
| overridden by explicit ``properties``). Calling ``set()`` or ``set_once()`` | ||
| in the context also folds active tags into ``$set`` or ``$set_once``. | ||
|
|
There was a problem hiding this comment.
This is ultra confusing to read my guy, i actually don't even. know what you're saying. try again :kek:
| Python 8 has no ``identify()`` method, so call this inside ``new_context()`` | ||
| to attribute ``capture()``, ``capture_exception()``, ``evaluate_flags()``, and | ||
| ``start_span()`` calls to the user. Events outside an identified context | ||
| without an explicit ``distinct_id`` send as personless. | ||
|
|
There was a problem hiding this comment.
It's more like in Python SDKs later than X.X.X, identify is done through the context() pattern (link back in docs written in getting started about context)
Call this method in a context, and all captures are automatically tagged with the identity.
something liek this
| Events with a ``distinct_id`` (explicit or from ``identify_context()``) | ||
| create or update a person profile. Pass ``$set`` or ``$set_once`` inside | ||
| ``properties`` (or call ``set()`` / ``set_once()``), since Python 8 has no | ||
| ``identify()`` method. Events without a ``distinct_id`` send as personless, | ||
| or pass ``options={"process_person_profile": False}`` for a known | ||
| ``distinct_id``. | ||
|
|
There was a problem hiding this comment.
Buddy I'm not sure a robot can understand you either lol.
Say it like this
Some special properties should be set with their respective methods
- Identity information should be set with ...
| Duplicate calls on the same exception instance send only one event. Contexts | ||
| autocapture only uncaught exceptions escaping ``new_context()``, so call | ||
| ``capture_exception()`` manually when catching and swallowing an error. | ||
| Passing ``None`` reads ``sys.exc_info()``. Returns the event UUID, or ``None`` | ||
| if skipped or dropped. |
There was a problem hiding this comment.
| Duplicate calls on the same exception instance send only one event. Contexts | |
| autocapture only uncaught exceptions escaping ``new_context()``, so call | |
| ``capture_exception()`` manually when catching and swallowing an error. | |
| Passing ``None`` reads ``sys.exc_info()``. Returns the event UUID, or ``None`` | |
| if skipped or dropped. | |
| Duplicate calls on the same exception instance send only one event. | |
| Contexts only autocaptures uncaught exceptions escaping ``new_context()``, so call | |
| ``capture_exception()`` manually when catching and handling an error gracefully. | |
| Passing ``None`` reads ``sys.exc_info()``. | |
| Returns the event UUID, or ``None`` if skipped or dropped. |
| and reason ``"Evaluated locally"``. Pass ``flags=flags.only_accessed()`` to | ||
| ``capture()`` to attach only flags read via ``is_enabled()`` or ``get_flag()`` | ||
| before that call, or ``flags=flags.only([...])`` for specific keys. | ||
| ``get_flag_payload()`` doesn't mark a flag accessed or emit | ||
| ``$feature_flag_called``. | ||
|
|
||
| Args: | ||
| distinct_id: The user's distinct ID. If ``None``, falls back to the | ||
| context distinct_id. If still unresolvable, returns an empty snapshot. | ||
| groups: Mapping of group type to group key. | ||
| person_properties: Person properties to use for evaluation. | ||
| group_properties: Group properties keyed by group type. | ||
| person_properties: Person properties for conditions not yet ingested or | ||
| overridden locally. | ||
| group_properties: Group properties keyed by group type (not group key), | ||
| e.g. ``{"company": {"plan": "enterprise"}}``. |
There was a problem hiding this comment.
You need some next lines I can't parse tokens
| than one cause applies, the first reason in the order below is reported: | ||
|
|
||
| - ``EXPERIENCE_CONTINUITY``: The flag has experience continuity enabled, which | ||
| local evaluation never resolves. Change the flag to fix it. | ||
| - ``UNSUPPORTED_DEFINITION``: The flag uses something the local evaluator does not | ||
| support, such as a static cohort, an unknown operator or filter type, a | ||
| malformed value, a dependency with no loaded definition or a circular | ||
| dependency. Change the flag or upgrade the SDK to fix it. | ||
| - ``UNRESOLVED_DEPENDENCY``: A flag this flag depends on has a loaded definition | ||
| but was unresolved. | ||
| - ``MISSING_CONTEXT``: The call did not pass a property, group property or device | ||
| id the flag needs, or passed it in an unusable form. Pass it to fix it. |
There was a problem hiding this comment.
Would a table work here? just 2 cols
johncwaters
left a comment
There was a problem hiding this comment.
Verdict: APPROVE WITH NITS
See inline comments.
Automated review by Glimmervoid. Not written by a human
|
|
||
| #### The differences from ``Client`` | ||
|
|
||
| Constructor options match ``Client(...)``, except in four places: |
There was a problem hiding this comment.
[convergent: code/contract + redteam/coverage] MEDIUM
"Except in four places" undercounts. AsyncClient.__init__ has no **kwargs, and these Client options aren't on it at all: enable_exception_autocapture plus its four exception_autocapture_* rate-limit options, metrics, traces, poll_interval, enable_local_evaluation, flag_definition_cache_provider, and flag_fallback_cache_url. So moving a working Posthog(..., enable_exception_autocapture=True) config over to AsyncPosthog(...) raises TypeError at startup, which this sentence says can't happen.
Suggest dropping the count and adding a bullet that names those options as Client-only, then regenerating both reference files (the same sentence is in references/posthog-python-8.md).
Automated review by Glimmervoid. Not written by a human
There was a problem hiding this comment.
Fixed in e4435e54. Dropped the count, named all 12 Client-only constructor options (local flag evaluation, exception autocapture and its rate-limit options, sync_mode, metrics, traces), and regenerated both reference files.
| disable_geoip: Whether to disable server-side GeoIP enrichment. | ||
| Defaults to True. Events get ``$geoip_disable`` only when the | ||
| event, context tags and ``super_properties`` leave it unset. | ||
| Set ``$ip`` in event properties to geolocate from a client IP. |
There was a problem hiding this comment.
[code/contract] MEDIUM
This reads as if $ip alone geolocates, but disable_geoip defaults to True, so capture_event.py adds $geoip_disable: True to every event and $ip gets ignored.
Suggest: "Set disable_geoip=False (or $geoip_disable: False on the event) and pass $ip in event properties to geolocate from a client IP."
Automated review by Glimmervoid. Not written by a human
There was a problem hiding this comment.
Fixed in e4435e54. Updated the docstring to state disable_geoip=False (or $geoip_disable: False on the event) is required alongside $ip, and regenerated both reference files.
| Set properties on a person profile. | ||
|
|
||
| Uses ``identify_context()`` when ``distinct_id`` is omitted, and folds | ||
| active context tags into ``$set``. Without a distinct ID or at least one |
There was a problem hiding this comment.
[code/contract] MEDIUM
Not true inside an identified context. add_context_tags (client.py:342) always adds a $context_tags key when a context is active, so under identify_context("u") a set() with no properties has properties == {"$context_tags": set()}, which is truthy, and the if personless or not properties guard at :2690 lets a $set event through. The async docstring at async_client.py:880 has the same problem.
Suggested wording:
Without a distinct ID (explicit or from
identify_context()) the call sends nothing and returnsNone.
Making the guard ignore $context_tags would be a behavior change, so that belongs in its own PR.
Automated review by Glimmervoid. Not written by a human
There was a problem hiding this comment.
Fixed in e4435e54. Updated both Client.set() and AsyncClient.set() docstrings to match the actual add_context_tags() behavior, and regenerated both reference files.
💡 Motivation and Context
Problem
The Python 8 reference is missing guidance from the retired
posthog.comdocs, and the generated Markdown has 4-column tables with emptyTypecells, raw<details>blocks, and hard-wrapped prose.Changes
docs/getting-started.md, client and module docstrings, and Django/DRF docs, and warned when context helpers no-op outsidewith new_context():.bin/docs_scripts/generate_markdown.pyto export DRF exception handlers, fold parameter tables to 2 columns, unwrap docstring prose, and put-in unannotatedReturns:rows.<details>blocks in docstrings with Markdown tables and fenced code blocks.1. Missing reference docs (
AsyncClient)Before
No docstring on
AsyncClient.__init__(only the raw function signature rendered).After
Create an async PostHog client. Import it as
AsyncPosthogfromposthog.Keep one client for your app's lifetime on one event loop. Open it with
async with AsyncPosthog(...), or callawait shutdown()on teardown.Know what to await
Queue methods write to memory and return right away. Network reads and lifecycle calls are coroutines.
awaitcapture,capture_ai,set,set_once,group_identify,alias,capture_exceptionawaitcapture_immediate,capture_ai_immediateawaitevaluate_flags,get_remote_config_payload,emails.send,emails.get,flush,shutdown,joinThe differences from
ClientConstructor options match
Client(...), except in four places:secret_keyauthenticatesget_remote_config_payload()andemails.AsyncPosthogdoesn't poll flag definitions locally.before_sendandon_erroraccept regular functions orasync defcoroutines.AsyncPosthoghas no context methods. Open a context withposthog.new_context(),posthog.scoped(), orPosthogASGIMiddleware, then callposthog.identify_context()andposthog.tag()inside it.start_span()andsync_modelive on syncPosthogonly.2. Dense prose into scannable bullets (
AsyncClient.emails)Before
Send transactional email from PostHog email templates or from content
in your code, and read the status of each email sent with
get.Needs
secret_key, a project secret API key with thetransactional_email:writescope, and
posthog[async]. Sends go toapp_host, or to the PostHogCloud app host of
host.email_request_timeout_secondsandemail_request_max_retriesconfigure each send. A disabled or shut-downclient sends nothing. See
posthog.emailsfor setup.After
Send transactional email from PostHog templates or inline code, and read delivery status with
get.posthog[async]and asecret_keyproject secret API key with thetransactional_email:writescope.app_host, or to the PostHog Cloud app host ofhost.email_request_timeout_secondsandemail_request_max_retries.posthog.emailsfor full setup.3. 4-column parameter tables folded into 2 columns (
Client(...)excerpt)Before
project_api_keystrhosthttps://us.posthog.comare mapped to the corresponding ingestion host.Nonetimeoutfloat15disable_geoip$geoip_disableonly when the event, context tags andsuper_propertiesleave it unset.TrueAfter
project_api_keystr. PostHog project API key/token. Required.hosthttps://us.posthog.comare mapped to the corresponding ingestion host. Default:None.timeoutfloat. HTTP request timeout in seconds for event uploads. Default:15.disable_geoip$geoip_disableonly when the event, context tags andsuper_propertiesleave it unset. Set$ipin event properties to geolocate from a client IP. Default:True.4. Raw
<details>blocks and hard-wrapped prose (UnresolvedFlagReason)Before
Reported by
FeatureFlagEvaluations.unresolved_flags. Inheriting fromstrkeeps the members directly comparable to their string values. When morethan one cause applies, the first reason in the order below is reported.
Values
EXPERIENCE_CONTINUITY: The flag has experience continuity enabled, which
local evaluation never resolves. Change the flag to fix it.
UNSUPPORTED_DEFINITION: The flag uses something the local evaluator does not
support, such as a static cohort, an unknown operator or filter type, a
malformed value, a dependency with no loaded definition or a circular
dependency. Change the flag or upgrade the SDK to fix it.
UNRESOLVED_DEPENDENCY: A flag this flag depends on has a loaded definition
but was unresolved.
MISSING_CONTEXT: The call did not pass a property, group property or device
id the flag needs, or passed it in an unusable form. Pass it to fix it.
After
Reported by
FeatureFlagEvaluations.unresolved_flags. Inheriting fromstrkeeps the members directly comparable to their string values. When more than one cause applies, the first reason in the order below is reported:EXPERIENCE_CONTINUITYUNSUPPORTED_DEFINITIONUNRESOLVED_DEPENDENCYMISSING_CONTEXT💚 How did you test it?
python bin/docs_scripts/generate_markdown.py --sdk-specs ../sdk-specs(Python3.11.11,griffe==2.0.2): regeneratedreferences/posthog-python-8.mdandreferences/posthog-python-reference.md.pytest posthog/test/test_reference_markdown.py .github/scripts/test_check_public_api.py: 23 passed (4 new).ruff format --check .(423 files),ruff check .,python .github/scripts/check_public_api.py, andgit diff --check: all passed.📝 Checklist
If releasing new changes
sampo addto generate a changeset file (docstrings, reference generator, and tests only)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
3.11.11,griffe==2.0.2,pytest,ruff, andgh.posthog.comPython docs against v8 docstrings, keptClient.new_contextlinks from#1272andUnresolvedFlagReasonwording from#1288, movedemails.sendandemails.getunderawaitinAsyncClient, and updatedgenerate_markdown.pyinstead of hand-editing generated docs.