diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 81fad45b2..565dbe6c0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -27,6 +27,7 @@ updates: - dependency-name: "langchain*" - dependency-name: "langgraph" open-pull-requests-limit: 1 + versioning-strategy: increase-if-necessary reviewers: - "PostHog/team-llm-analytics" @@ -57,6 +58,7 @@ updates: - dependency-name: "langchain*" - dependency-name: "langgraph" open-pull-requests-limit: 1 + versioning-strategy: increase-if-necessary reviewers: - "PostHog/team-llm-analytics" # Uncomment below to enable auto-merge for minor updates when CI passes diff --git a/.github/scripts/check_strict_types.sh b/.github/scripts/check_strict_types.sh index 7b46c0af0..4e41c9e8f 100755 --- a/.github/scripts/check_strict_types.sh +++ b/.github/scripts/check_strict_types.sh @@ -15,6 +15,7 @@ import atexit import posthog from posthog import FeatureFlagEvaluations, FlagValue, Posthog +from posthog.emails import AsyncEmails, Emails, SendEmailResult from posthog.ai.evaluations import ( AsyncOfflineEvaluations, BooleanScorerConfig, @@ -40,6 +41,16 @@ span.end() _ = (flag_value, all_flags, enabled, payload, evaluations, active) +emails = Emails("phs_example") +template_send: SendEmailResult = emails.send(to="user@example.com", template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b", template_data={"name": "Ada"}) +rendered_send: SendEmailResult = emails.send(to="user@example.com", template_key="password-reset", subject="Reset", html="
Reset
", from_="AcmeHi
") + _ = sent + async def offline_evaluation_types( sync_client: OfflineEvaluations, async_client: AsyncOfflineEvaluations @@ -64,15 +75,26 @@ async def offline_evaluation_types( _ = config PY -cat > "$tmp/invalid_offline_types.py" <<'PY' +cat > "$tmp/invalid_types.py" <<'PY' # pyright: strict from posthog.ai.evaluations import BooleanScorerConfig, CategoricalScorerConfig, NumericPassingRule, NumericScorerConfig, OfflineEvaluations +from posthog.emails import AsyncEmails, Emails client = OfflineEvaluations(project_id=123, secret_key="phx_example") NumericPassingRule(operator="gt", threshold=0.8) # expected-type-error NumericScorerConfig(unknown_setting=True) # expected-type-error CategoricalScorerConfig(selection_mode="single") # expected-type-error client.scorers.create(name="Bad config", kind="numeric", config=BooleanScorerConfig(true_is_failure=True)) # expected-type-error +Emails("phs_example").send(to="user@example.com", template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b", template_key="welcome", subject="Hi", html="Hi
") # expected-type-error +Emails("phs_example").send(to="user@example.com", template_key="welcome", html="Hi
") # expected-type-error +Emails("phs_example").send(to="user@example.com", template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b", cc="team@example.com") # expected-type-error +Emails("phs_example").send(to="user@example.com", template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b", capture_engagement=False) # expected-type-error +Emails("phs_example").send(to="user@example.com", template_key="welcome", subject="Hi", html="Hi
", template_data={"name": "Ada"}) # expected-type-error +Emails("phs_example").send(to="user@example.com", template_key="welcome", subject="Hi", html="Hi
", cc="team@example.com") # expected-type-error + + +async def invalid_async_email() -> None: + await AsyncEmails("phs_example").send(to="user@example.com", template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b", subject="Hi") # expected-type-error PY "$tmp/.venv/bin/python" - <<'PY' > "$tmp/public_api_access.py" @@ -116,8 +138,8 @@ JSON cd "$tmp" "$tmp/.venv/bin/python" -m pyright strict_posthog_types.py public_api_access.py -if "$tmp/.venv/bin/python" -m pyright --outputjson invalid_offline_types.py > invalid_types.json; then - echo "Invalid offline evaluation configurations unexpectedly passed type checking." +if "$tmp/.venv/bin/python" -m pyright --outputjson invalid_types.py > invalid_types.json; then + echo "Invalid offline evaluation configurations and email sends unexpectedly passed type checking." exit 1 fi "$tmp/.venv/bin/python" - <<'PY' @@ -125,11 +147,11 @@ import json from pathlib import Path expected = { - index for index, line in enumerate(Path("invalid_offline_types.py").read_text().splitlines()) + index for index, line in enumerate(Path("invalid_types.py").read_text().splitlines()) if "expected-type-error" in line } diagnostics = json.loads(Path("invalid_types.json").read_text())["generalDiagnostics"] actual = {item["range"]["start"]["line"] for item in diagnostics if item["severity"] == "error"} assert actual == expected, diagnostics -print("Offline evaluation configuration types reject invalid inputs.") +print("Offline evaluation configuration and email send types reject invalid inputs.") PY diff --git a/.github/workflows/benchmark-report.yml b/.github/workflows/benchmark-report.yml new file mode 100644 index 000000000..7fabe81e1 --- /dev/null +++ b/.github/workflows/benchmark-report.yml @@ -0,0 +1,21 @@ +name: Python SDK benchmark report + +on: + workflow_run: + workflows: ['Python SDK benchmarks'] + types: [completed] + +permissions: {} + +jobs: + report: + permissions: + contents: read + actions: read + pull-requests: write + uses: PostHog/.github/.github/workflows/sdk-benchmark-report.yml@3322f26f21f088ad5e5960d65a916971e309ac0b # SDK benchmark workflow (PostHog/.github PR #84) + with: + workflow-path: .github/workflows/benchmarks.yml + artifact-name: python-benchmark-results + report-key: posthog-python + sdk: posthog-python diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 000000000..a41910600 --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,143 @@ +name: Python SDK benchmarks + +on: [pull_request] + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + benchmark: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + shard: [flags-single, flags-scaling, flags-memory, capture] + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + persist-credentials: false + + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12.12' + + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + version: '0.13.4' + enable-cache: true + + - name: Prepare pinned baseline + env: + TARGET_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + set -euo pipefail + export BASE_WORKTREE="$RUNNER_TEMP/python-benchmark-base" + export RESULTS="$RUNNER_TEMP/python-benchmark-results" + printf 'BASE_WORKTREE=%s\nRESULTS=%s\n' "$BASE_WORKTREE" "$RESULTS" >> "$GITHUB_ENV" + BASE_SHA=$(git merge-base "$TARGET_SHA" "$HEAD_SHA") + git worktree add --detach "$BASE_WORKTREE" "$BASE_SHA" + mkdir -p "$RESULTS" + python -c 'import json, os, pathlib, sys; pathlib.Path(os.environ["RESULTS"], "revisions.json").write_text(json.dumps({"target":os.environ["TARGET_SHA"], "head":os.environ["HEAD_SHA"], "base":sys.argv[1]}, indent=2))' "$BASE_SHA" + + - name: Install isolated head and baseline wheels + run: | + python benchmarks/prepare.py . + python benchmarks/prepare.py "$BASE_WORKTREE" + + - name: Test measurement controls and fixtures + run: .venv-benchmark/bin/python -B benchmarks/test_benchmarks.py + + - name: Measure paired base and head + id: measure + timeout-minutes: 8 + run: | + .venv-benchmark/bin/python -B benchmarks/run.py \ + --base "$BASE_WORKTREE" \ + --head "$GITHUB_WORKSPACE" \ + --output "$RESULTS" \ + --repetitions 6 \ + --shard "${{ matrix.shard }}" + + - name: Upload raw shard results + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: benchmark-shard-${{ matrix.shard }} + path: | + ${{ runner.temp }}/python-benchmark-results/base.json + ${{ runner.temp }}/python-benchmark-results/head.json + ${{ runner.temp }}/python-benchmark-results/revisions.json + if-no-files-found: warn + retention-days: 14 + + collect: + needs: benchmark + if: ${{ !cancelled() }} + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: Download shard results + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: benchmark-shard-* + path: ${{ runner.temp }}/python-benchmark-shards + merge-multiple: false + + - name: Collect and render benchmark comparison + uses: PostHog/.github/.github/actions/benchmark-report@3322f26f21f088ad5e5960d65a916971e309ac0b # SDK benchmark reporting (PostHog/.github PR #84) + with: + mode: collect + source-status: ${{ needs.benchmark.result }} + shard-manifest: benchmarks/shards.json + shard-directory: ${{ runner.temp }}/python-benchmark-shards + output-directory: ${{ runner.temp }}/python-benchmark-report + + - name: Upload rendered comparison + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: python-benchmark-report + path: | + ${{ runner.temp }}/python-benchmark-report/report.md + ${{ runner.temp }}/python-benchmark-report/comparison.json + if-no-files-found: ignore + retention-days: 14 + + - name: Upload raw benchmark results + if: always() + id: results + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: python-benchmark-results + path: | + ${{ runner.temp }}/python-benchmark-report/bundle.json + ${{ runner.temp }}/python-benchmark-report/revisions.json + if-no-files-found: warn + retention-days: 14 + + - name: Link results + if: always() + env: + ARTIFACT_URL: ${{ steps.results.outputs.artifact-url }} + run: | + printf '## Python SDK benchmark data\n\n' >> "$GITHUB_STEP_SUMMARY" + if [[ -n "$ARTIFACT_URL" ]]; then + printf '[Download paired measurements and execution metadata](%s)\n\n' "$ARTIFACT_URL" >> "$GITHUB_STEP_SUMMARY" + fi + printf 'Measurements are informational. Check workload statuses before comparing values.\n' >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecbc6914c..ef0ff8a61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,7 @@ jobs: fetch-depth: 1 - name: Set up Python 3.11 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.11 @@ -104,12 +104,12 @@ jobs: fetch-depth: 1 - name: Set up Python 3.11 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.11 - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -132,12 +132,12 @@ jobs: fetch-depth: 1 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: ${{ matrix.python-version }} - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -179,12 +179,12 @@ jobs: fetch-depth: 1 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: ${{ matrix.python-version }} - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -244,13 +244,13 @@ jobs: - name: Set up Python 3.11 if: steps.changes.outputs.changed == 'true' - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.11 - name: Install uv if: steps.changes.outputs.changed == 'true' - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -303,7 +303,7 @@ jobs: fetch-depth: 1 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: ${{ matrix.python-version }} @@ -326,12 +326,12 @@ jobs: fetch-depth: 1 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: ${{ matrix.python-version }} - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -381,12 +381,12 @@ jobs: fetch-depth: 1 - name: Set up Python 3.12 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.12 - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ea90e4ce8..b15388d96 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Initialize CodeQL - uses: github/codeql-action/init@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 + uses: github/codeql-action/init@1fc58d04a4d4374f921bdac573c3811c240f9c26 # v4.39.2 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -40,6 +40,6 @@ jobs: trap-caching: false - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 + uses: github/codeql-action/analyze@1fc58d04a4d4374f921bdac573c3811c240f9c26 # v4.39.2 with: category: '/language:${{matrix.language}}' diff --git a/.github/workflows/generate-references.yml b/.github/workflows/generate-references.yml new file mode 100644 index 000000000..708e21322 --- /dev/null +++ b/.github/workflows/generate-references.yml @@ -0,0 +1,64 @@ +name: Generate references + +# Regenerates references/ by hand, for when the release's best-effort reference step fails +# or the pages need a refresh. Same shape as posthog-js's generate-references.yml. +on: + workflow_dispatch: + +permissions: {} + +jobs: + generate-references: + name: Generate SDK reference + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Get GitHub App token + id: releaser + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ secrets.GH_APP_POSTHOG_PYTHON_RELEASER_APP_ID }} + private-key: ${{ secrets.GH_APP_POSTHOG_PYTHON_RELEASER_PRIVATE_KEY }} + + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + token: ${{ steps.releaser.outputs.token }} + + - name: Check out sdk-specs + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: PostHog/sdk-specs + path: .sdk-specs + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: 3.11 + + - name: Install uv + uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + with: + version: "0.13.4" + enable-cache: true + + - name: Generate references + id: changes + run: | + uv run --extra dev bin/docs --sdk-specs .sdk-specs + git add references + git diff --cached --quiet || echo "changed=true" >> "$GITHUB_OUTPUT" + + - name: Commit generated references + if: steps.changes.outputs.changed == 'true' + uses: planetscale/ghcommit-action@a6b150b81dca5dd027baa898604418eec9e11465 # v0.2.22 + with: + commit_message: "docs: update the SDK reference [skip ci]" + repo: ${{ github.repository }} + branch: main + file_pattern: references/ + env: + GITHUB_TOKEN: ${{ steps.releaser.outputs.token }} diff --git a/.github/workflows/posthog-upgrade.yml b/.github/workflows/posthog-upgrade.yml index 0c1f8126f..55fc6718f 100644 --- a/.github/workflows/posthog-upgrade.yml +++ b/.github/workflows/posthog-upgrade.yml @@ -42,7 +42,7 @@ jobs: token: ${{ steps.upgrader.outputs.token }} - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" diff --git a/.github/workflows/release-failure-notification.yml b/.github/workflows/release-failure-notification.yml new file mode 100644 index 000000000..caec2e759 --- /dev/null +++ b/.github/workflows/release-failure-notification.yml @@ -0,0 +1,59 @@ +name: Release failure notification + +on: + workflow_run: + workflows: [Release] + types: [completed] + branches: [main] + +permissions: + actions: read + contents: read + +jobs: + notify-failed: + name: Notify Slack - Failed + runs-on: ubuntu-latest + if: >- + github.event.workflow_run.head_repository.full_name == github.repository && + (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'workflow_dispatch') + timeout-minutes: 10 + steps: + # This workflow must survive cancellation or runner startup failure in Release. + # Never execute code from the triggering run's head in this privileged workflow. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.repository.default_branch }} + persist-credentials: false + + - name: Download approval thread timestamps + continue-on-error: true + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 + with: + pattern: release-slack-thread-* + path: ${{ runner.temp }}/release-slack-threads + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Check release jobs + id: release-status + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SLACK_CHANNEL_ID: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} + THREAD_DIRECTORY: ${{ runner.temp }}/release-slack-threads + with: + retries: 3 + script: | + const notification = require('./scripts/release-failure-notification.cjs'); + const payload = await notification({ github, context, channel: process.env.SLACK_CHANNEL_ID, threadDirectory: process.env.THREAD_DIRECTORY }); + if (payload) core.setOutput('payload', JSON.stringify(payload)); + + - name: Notify Slack - Failed + if: steps.release-status.outputs.payload != '' + uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 + with: + method: chat.postMessage + token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} + errors: true + retries: 5 + payload: ${{ steps.release-status.outputs.payload }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0dd57cb0a..77b77bbb7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,6 +53,27 @@ jobs: slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} posthog_project_api_key: ${{ secrets.POSTHOG_PROJECT_API_KEY }} + preserve-slack-thread: + name: Preserve Slack thread + needs: notify-approval-needed + if: needs.notify-approval-needed.outputs.slack_ts != '' + runs-on: ubuntu-latest + timeout-minutes: 5 + continue-on-error: true + permissions: {} + steps: + - name: Save approval thread timestamp + env: + THREAD_TS: ${{ needs.notify-approval-needed.outputs.slack_ts }} + run: printf '%s' "$THREAD_TS" > thread-ts.txt + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release-slack-thread-${{ github.run_attempt }} + path: thread-ts.txt + retention-days: 30 + if-no-files-found: error + # Bump versions, commit to main, and regenerate references. This is the single # approval-gated job (environment "Release"). It does NOT publish — publishing # happens in the `publish` matrix job below, which has no environment so the @@ -96,12 +117,12 @@ jobs: token: ${{ steps.releaser.outputs.token }} - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: 3.11 - name: Install uv - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: version: "0.13.4" enable-cache: true @@ -177,10 +198,28 @@ jobs: git fetch origin main git reset --hard "$COMMIT_HASH" + # The reference headings come from the sdk-specs capabilities. + - name: Check out sdk-specs + # Best-effort: a failure never blocks the release. Run generate-references.yml to retry. + continue-on-error: true + if: steps.commit-release.outputs.commit-hash != '' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: PostHog/sdk-specs + path: .sdk-specs + persist-credentials: false + - name: Generate references + id: reference + # Best-effort: a failure never blocks the release. Run generate-references.yml to retry. + continue-on-error: true if: steps.commit-release.outputs.commit-hash != '' run: | - uv run bin/docs generate-references + uv run bin/docs --sdk-specs .sdk-specs + + - name: Warn if the SDK reference didn't regenerate + if: steps.reference.outcome == 'failure' + run: echo "::warning::The SDK reference didn't regenerate. Run generate-references.yml to retry." - name: Check for changes in references if: steps.commit-release.outputs.commit-hash != '' @@ -229,16 +268,6 @@ jobs: "alertContext": "The version bump/changelog step failed before packages were published." } - - name: Notify Slack - Failed - if: ${{ failure() && needs.notify-approval-needed.outputs.slack_ts != '' }} - uses: posthog/.github/.github/actions/slack-thread-reply@cb0979b67dcd585828b61ac45927eef4da8f6287 # main - with: - slack_bot_token: ${{ secrets.SLACK_CLIENT_LIBRARIES_BOT_TOKEN }} - slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }} - thread_ts: ${{ needs.notify-approval-needed.outputs.slack_ts }} - message: "❌ Failed to bump versions for `posthog-python@${{ steps.sampo-release.outputs.new_version }}`! are expressions.
+ md = re.sub(r"(.*?)", r"`\1`", md.replace("
", "
"))
+ # A parameter documented only in the docstring, like a **kwargs key, isn't required.
+ md = re.sub(r"^(`\w+` \| \| .*) \| \*required\*$", r"\1 | ", md, flags=re.M)
+ return re.sub(r"^### .*$", f"### `{name}`", md.strip(), count=1, flags=re.M)
+
+
+def methods(cls) -> list:
+ """Public methods and properties, and `__init__`."""
+ return [
+ m
+ for n, m in cls.members.items()
+ if not m.is_alias
+ and (m.is_function or "property" in m.labels)
+ and (not n.startswith("_") or n == "__init__")
+ ]
+
+
+def label(prefix: str, m) -> str:
+ return f"{prefix}(...)" if m.name == "__init__" else f"{prefix}.{m.name}"
+
+
+def capabilities(checkout: str) -> dict[str, str]:
+ """Each sdk-specs capability's slug and title in sentence case, in the README's order."""
+ readme = (Path(checkout) / "README.md").read_text()
+ rows = re.findall(
+ r"^\| ([^|]+?) \| \[`openspec/specs/([a-z0-9-]+)/spec\.md`\]", readme, re.M
+ )
+ acronyms = {"id": "ID", "ai": "AI", "http": "HTTP", "mcp": "MCP"}
+ titles = {
+ s: " ".join(acronyms.get(w.lower(), w.lower()) for w in n.split())
+ for n, s in rows
+ }
+ # Setup, capture and identify come first; the rest follow the README.
+ order = [*FIRST, *(s for s in titles if s not in FIRST)]
+ return {s: titles[s][0].upper() + titles[s][1:] for s in order if s in titles}
+
+
+def has(pkg, path: str) -> bool:
+ try:
+ pkg[path]
+ return True
+ except KeyError:
+ return False
+
+
+def reference(pkg, caps: dict[str, str], current: bool) -> list[str]:
+ """`current` is false for a next major, which can remove what the map names."""
+ order = {slug: i for i, slug in enumerate(caps)}
+ utils, types = ([pkg[p] for p in paths if has(pkg, p)] for paths in (UTILS, TYPES))
+ module = [
+ m
+ for n, m in pkg.members.items()
+ if not m.is_alias and m.is_function and not n.startswith("_")
+ ]
+ sync, asyncs = (
+ methods(pkg["client.Client"]),
+ methods(pkg["async_client.AsyncClient"]),
+ )
+ found = {label("Client", m) for m in sync} | {
+ label("AsyncClient", m) for m in asyncs
+ }
+ found |= {f"posthog.{m.name}" for m in module}
+ for obj in [*sync, *asyncs, *module, *utils, *types]:
+ clean(obj)
+ data = json.loads((ROOT / "docs/capabilities.json").read_text())
+ utils_names, later = set(data.pop("utils")), data.pop("next", {})
+ mapped = {**later, **data}
+ for name, slug in mapped.items():
+ if current and name not in found and name not in later:
+ raise SystemExit(f"docs/capabilities.json: no symbol for {name}")
+ if slug not in caps:
+ raise SystemExit(
+ f"docs/capabilities.json: {name}: {slug} isn't in sdk-specs"
+ )
+ for name in sorted(found - mapped.keys() - utils_names):
+ if name.startswith("Client"):
+ raise SystemExit(f"docs/capabilities.json: map {name} or add it to utils")
+ client = [(mapped.get(label("Client", m)), m) for m in sync]
+ asyncs = sorted(
+ ((mapped.get(label("AsyncClient", m)), m) for m in asyncs),
+ key=lambda e: order.get(e[0] or "", len(order)),
+ )
+ out = []
+ for slug, title in caps.items():
+ if tagged := [m for t, m in client if t == slug]:
+ out += [f"## {title}", *(entry(m, label("Client", m)) for m in tagged)]
+ out += ["## SDK utils", *(entry(m, label("Client", m)) for t, m in client if not t)]
+ out += [entry(o, f"posthog.{o.path.removeprefix('posthog.')}") for o in utils]
+ out += ["## AsyncClient", "Needs the `async` extra, `posthog[async]`."]
+ out += [entry(m, label("AsyncClient", m)) for _, m in asyncs]
+ out += ["## Module functions", *(entry(m, f"posthog.{m.name}") for m in module)]
+ return out + ["## Types", *(entry(o, o.name) for o in types)]
+
+
+def front_matter(title: str, sections: list[str]) -> str:
+ """The docs site's front matter. Its ToC lists the page's H2 sections only."""
+ toc = []
+ for heading in [s[3:] for s in sections if s.startswith("## ")]:
+ anchor = re.sub(r"[^\w\- ]", "", heading.lower()).replace(" ", "-")
+ toc.append(f' - value: "{heading}"\n url: {anchor}\n depth: 0')
+ head = [f'title: "{title}"', "sidebar: Docs", "showTitle: true"]
+ head += [
+ "contentMaxWidthClass: max-w-full",
+ "platformLogo: python",
+ "tableOfContents:",
+ *toc,
+ ]
+ return "\n".join(["---", *head, "---"])
+
+
+def nest(markdown: str) -> str:
+ """Moves each heading down one level and drops the H1. Code stays as written."""
+ out, in_fence = [], False
+ for line in markdown.strip().split("\n"):
+ in_fence ^= bool(re.match(r"\s*```", line))
+ if in_fence or not re.match(r"#{1,5} ", line):
+ out.append(line)
+ elif not line.startswith("# "):
+ out.append("#" + line)
+ return "\n".join(out)
+
+
+def write(name: str, sections: list[str]) -> None:
+ (ROOT / "references" / name).write_text("\n\n".join(sections) + "\n")
+ print(f"wrote references/{name}")
+
+
+def main() -> None:
+ args = argparse.ArgumentParser(description="Generate the SDK reference Markdown.")
+ args.add_argument("--sdk-specs", required=True, help="PostHog/sdk-specs checkout")
+ args.add_argument(
+ "--major", type=int, help="target major, defaults to the declared one"
+ )
+ opts = args.parse_args()
+ logging.getLogger("griffe").setLevel(logging.ERROR)
+ pkg = griffe.load(
+ "posthog",
+ search_paths=[str(ROOT)],
+ docstring_parser="google",
+ # A Returns section is one return value, even when its description wraps.
+ docstring_options={"returns_multiple_items": False},
+ resolve_aliases=False,
+ )
+ declared = int(
+ (ROOT / "posthog/version.py").read_text().split('"')[1].split(".")[0]
+ )
+ major = opts.major or declared
+ started = nest((ROOT / "docs/getting-started.md").read_text())
+ body = [
+ "## Getting started",
+ started,
+ *reference(pkg, capabilities(opts.sdk_specs), declared >= major),
+ ]
+ title = f"PostHog Python SDK {major}.x" + (
+ "" if declared >= major else " (experimental)"
+ )
+ write(f"posthog-python-{major}.md", [front_matter(title, body), *body])
+ if declared >= major:
+ write(
+ "posthog-python-reference.md",
+ [front_matter("PostHog Python SDK", body), *body],
+ )
+ if guides := sorted((ROOT / "docs").glob("migration-*.md"), reverse=True):
+ head = "---\ntitle: PostHog Python SDK migration guides\nsidebar: Docs\nshowTitle: true\n---"
+ write(
+ "posthog-python-migration.md",
+ [head, *(g.read_text().strip() for g in guides)],
+ )
+
+
+if __name__ == "__main__":
+ main()
diff --git a/docs/capabilities.json b/docs/capabilities.json
new file mode 100644
index 000000000..7bf0d6031
--- /dev/null
+++ b/docs/capabilities.json
@@ -0,0 +1,82 @@
+{
+ "AsyncClient(...)": "setup",
+ "AsyncClient.alias": "alias",
+ "AsyncClient.capture": "capture",
+ "AsyncClient.capture_exception": "capture-exception",
+ "AsyncClient.capture_immediate": "capture",
+ "AsyncClient.emails": "emails",
+ "AsyncClient.evaluate_flags": "evaluate-flags",
+ "AsyncClient.flush": "flush",
+ "AsyncClient.group_identify": "group-identify",
+ "AsyncClient.join": "shutdown",
+ "AsyncClient.set": "identify",
+ "AsyncClient.set_once": "identify",
+ "AsyncClient.shutdown": "shutdown",
+ "Client(...)": "setup",
+ "Client.alias": "alias",
+ "Client.capture": "capture",
+ "Client.capture_ai": "capture-ai",
+ "Client.capture_exception": "capture-exception",
+ "Client.emails": "emails",
+ "Client.evaluate_flags": "evaluate-flags",
+ "Client.feature_enabled": "is-feature-enabled",
+ "Client.feature_flag_definitions": "flag-definition-loader",
+ "Client.flush": "flush",
+ "Client.get_active_span": "traces",
+ "Client.get_all_flags": "get-feature-flags",
+ "Client.get_all_flags_and_payloads": "get-feature-flags-and-payloads",
+ "Client.get_feature_flag": "get-feature-flag",
+ "Client.get_feature_flag_payload": "get-feature-flag-payload",
+ "Client.get_feature_flag_result": "get-feature-flag-result",
+ "Client.get_feature_flags_and_payloads": "get-feature-flags-and-payloads",
+ "Client.get_feature_variants": "get-feature-flags",
+ "Client.group_identify": "group-identify",
+ "Client.join": "shutdown",
+ "Client.load_feature_flags": "flag-definition-loader",
+ "Client.set": "identify",
+ "Client.set_once": "identify",
+ "Client.shutdown": "shutdown",
+ "Client.start_span": "traces",
+ "posthog.alias": "alias",
+ "posthog.capture": "capture",
+ "posthog.capture_ai": "capture-ai",
+ "posthog.capture_exception": "capture-exception",
+ "posthog.evaluate_flags": "evaluate-flags",
+ "posthog.feature_enabled": "is-feature-enabled",
+ "posthog.feature_flag_definitions": "flag-definition-loader",
+ "posthog.flush": "flush",
+ "posthog.get_active_span": "traces",
+ "posthog.get_all_flags": "get-feature-flags",
+ "posthog.get_all_flags_and_payloads": "get-feature-flags-and-payloads",
+ "posthog.get_feature_flag": "get-feature-flag",
+ "posthog.get_feature_flag_payload": "get-feature-flag-payload",
+ "posthog.get_feature_flag_result": "get-feature-flag-result",
+ "posthog.group_identify": "group-identify",
+ "posthog.join": "shutdown",
+ "posthog.load_feature_flags": "flag-definition-loader",
+ "posthog.set": "identify",
+ "posthog.set_once": "identify",
+ "posthog.setup": "setup",
+ "posthog.shutdown": "shutdown",
+ "posthog.start_span": "traces",
+ "utils": [
+ "Client.consumers",
+ "Client.feature_flags",
+ "Client.get_context_options",
+ "Client.get_feature_flag_evaluation_runtime",
+ "Client.get_feature_flag_keys_by_evaluation_runtime",
+ "Client.get_feature_payloads",
+ "Client.get_flags_decision",
+ "Client.get_remote_config_payload",
+ "Client.get_tags",
+ "Client.identify_context",
+ "Client.metrics",
+ "Client.new_context",
+ "Client.queue",
+ "Client.scoped",
+ "Client.set_context_device_id",
+ "Client.set_context_option",
+ "Client.set_context_session",
+ "Client.tag"
+ ]
+}
diff --git a/docs/getting-started.md b/docs/getting-started.md
new file mode 100644
index 000000000..27d91f176
--- /dev/null
+++ b/docs/getting-started.md
@@ -0,0 +1,39 @@
+# Getting started
+
+The Python SDK captures events, evaluates feature flags and reports errors from Python 3.10 or later.
+
+To send your first event, install the package, create a client, capture an event, and shut the client down, as the steps below show.
+
+## Install
+
+```bash
+pip install posthog
+```
+
+## Initialize
+
+Create one client for your app with your project token and host. Your project token and host are in your [project settings](https://app.posthog.com/project/settings). Keep the token in an environment variable rather than in code.
+
+```python
+from posthog import Posthog
+
+posthog = Posthog("", host="")
+```
+
+## Capture an event
+
+```python
+posthog.capture("user_signed_up", distinct_id="user_123", properties={"plan": "free"})
+```
+
+`capture` queues the event and returns right away. A background thread sends it.
+
+## Shut down
+
+Call `shutdown()` before your process exits, so queued events are sent.
+
+```python
+posthog.shutdown()
+```
+
+In an asyncio app, use `AsyncPosthog` as an async context manager instead. See [AsyncClient](#asyncclient).
diff --git a/examples/example-ai-anthropic/chat.py b/examples/example-ai-anthropic/chat.py
index 9a17424e3..c8a024070 100644
--- a/examples/example-ai-anthropic/chat.py
+++ b/examples/example-ai-anthropic/chat.py
@@ -58,7 +58,7 @@ def get_weather(latitude: float, longitude: float, location_name: str) -> str:
message = client.messages.create(
- model="claude-sonnet-4-5-20250929",
+ model="claude-sonnet-5-5",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather like in San Francisco?"}],
diff --git a/examples/example-ai-anthropic/extended_thinking.py b/examples/example-ai-anthropic/extended_thinking.py
index 7254c6904..cfc445e1f 100644
--- a/examples/example-ai-anthropic/extended_thinking.py
+++ b/examples/example-ai-anthropic/extended_thinking.py
@@ -34,9 +34,9 @@
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
message = client.messages.create(
- model="claude-sonnet-4-5-20250929",
+ model="claude-sonnet-5-5",
max_tokens=16000,
- thinking={"type": "enabled", "budget_tokens": 10000},
+ thinking={"type": "adaptive", "display": "summarized"},
messages=[
{
"role": "user",
diff --git a/examples/example-ai-anthropic/streaming.py b/examples/example-ai-anthropic/streaming.py
index ea8c884b1..7bbe8d082 100644
--- a/examples/example-ai-anthropic/streaming.py
+++ b/examples/example-ai-anthropic/streaming.py
@@ -31,7 +31,7 @@
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
stream = client.messages.create(
- model="claude-sonnet-4-5-20250929",
+ model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about observability."}],
stream=True,
diff --git a/examples/example-ai-crewai/pyproject.toml b/examples/example-ai-crewai/pyproject.toml
index 9e655dc11..694257691 100644
--- a/examples/example-ai-crewai/pyproject.toml
+++ b/examples/example-ai-crewai/pyproject.toml
@@ -5,7 +5,7 @@ requires-python = ">=3.10"
dependencies = [
"posthog",
"crewai>=0.80.0",
- "litellm>=1.88.6",
+ "litellm>=1.100.4",
]
[tool.uv.sources]
diff --git a/examples/example-ai-crewai/uv.lock b/examples/example-ai-crewai/uv.lock
index c12480df8..514b96dff 100644
--- a/examples/example-ai-crewai/uv.lock
+++ b/examples/example-ai-crewai/uv.lock
@@ -10,7 +10,7 @@ resolution-markers = [
]
[options]
-exclude-newer = "2026-10-03T03:16:06.117367Z"
+exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values.
exclude-newer-span = "P7D"
[options.exclude-newer-package]
@@ -385,6 +385,34 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458, upload-time = "2024-11-08T17:25:46.184Z" },
]
+[[package]]
+name = "boto3"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+ { name = "jmespath" },
+ { name = "s3transfer" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fc/8a/64b46f075149f9160da44aa7e1052dd18431b9ad4435beb0cfb02cc48624/boto3-1.43.123.tar.gz", hash = "sha256:055fabb990c5d2f31fce4ca569255bd640cdd11a3ca68c9ecad35f4f8a5b83b5", size = 112638, upload-time = "2026-10-30T19:18:50.085Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/96/b2/a7986c327f80aa6f1544f4cb8f2fa7da4e1fccd472379a21cad0508b8a0e/boto3-1.43.123-py3-none-any.whl", hash = "sha256:d18d66e1e13faa0c25d0b1b8c5ce946e29fb5fc0b6456b655a93a678ff4cc313", size = 140044, upload-time = "2026-10-30T19:18:47.734Z" },
+]
+
+[[package]]
+name = "botocore"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "jmespath" },
+ { name = "python-dateutil" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e0/de/011fc2a47fb066c47064b122498d2fd21f55bc90ea514acbddc37ca0f8c1/botocore-1.43.123.tar.gz", hash = "sha256:80948cb9b1cdf1a1a25809089a42e3a1bc4af0258d198222db6e97dcc660dd0c", size = 16486269, upload-time = "2026-10-30T19:18:44.609Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/db/96/4f2dffd304425c07160ab2c12cb13322d852fd956fe9d4386228c93f02ea/botocore-1.43.123-py3-none-any.whl", hash = "sha256:e30580f9c1282c321529238ff8ff75066096a2adbd0a293c8ae592c21d1733a3", size = 16185987, upload-time = "2026-10-30T19:18:39.794Z" },
+]
+
[[package]]
name = "build"
version = "1.4.2"
@@ -620,7 +648,8 @@ dependencies = [
{ name = "overrides" },
{ name = "pybase64" },
{ name = "pydantic" },
- { name = "pydantic-settings" },
+ { name = "pydantic-settings", version = "2.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
+ { name = "pydantic-settings", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
{ name = "pypika" },
{ name = "pyyaml" },
{ name = "rich" },
@@ -830,7 +859,7 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "crewai", specifier = ">=0.80.0" },
- { name = "litellm", specifier = ">=1.88.6" },
+ { name = "litellm", specifier = ">=1.100.4" },
{ name = "posthog", directory = "../../" },
]
@@ -839,7 +868,7 @@ name = "exceptiongroup"
version = "1.3.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
- { name = "typing-extensions", marker = "python_full_version < '3.11'" },
+ { name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" }
wheels = [
@@ -1343,17 +1372,17 @@ resolution-markers = [
"python_full_version < '3.11'",
]
dependencies = [
- { name = "colorama", marker = "python_full_version < '3.11' and sys_platform == 'win32'" },
- { name = "decorator", marker = "python_full_version < '3.11'" },
- { name = "exceptiongroup", marker = "python_full_version < '3.11'" },
- { name = "jedi", marker = "python_full_version < '3.11'" },
- { name = "matplotlib-inline", marker = "python_full_version < '3.11'" },
- { name = "pexpect", marker = "python_full_version < '3.11' and sys_platform != 'emscripten' and sys_platform != 'win32'" },
- { name = "prompt-toolkit", marker = "python_full_version < '3.11'" },
- { name = "pygments", marker = "python_full_version < '3.11'" },
- { name = "stack-data", marker = "python_full_version < '3.11'" },
- { name = "traitlets", marker = "python_full_version < '3.11'" },
- { name = "typing-extensions", marker = "python_full_version < '3.11'" },
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+ { name = "decorator" },
+ { name = "exceptiongroup" },
+ { name = "jedi" },
+ { name = "matplotlib-inline" },
+ { name = "pexpect", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" },
+ { name = "prompt-toolkit" },
+ { name = "pygments" },
+ { name = "stack-data" },
+ { name = "traitlets" },
+ { name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/40/18/f8598d287006885e7136451fdea0755af4ebcbfe342836f24deefaed1164/ipython-8.39.0.tar.gz", hash = "sha256:4110ae96012c379b8b6db898a07e186c40a2a1ef5d57a7fa83166047d9da7624", size = 5513971, upload-time = "2026-03-27T10:02:13.94Z" }
wheels = [
@@ -1368,17 +1397,17 @@ resolution-markers = [
"python_full_version == '3.11.*'",
]
dependencies = [
- { name = "colorama", marker = "python_full_version == '3.11.*' and sys_platform == 'win32'" },
- { name = "decorator", marker = "python_full_version == '3.11.*'" },
- { name = "ipython-pygments-lexers", marker = "python_full_version == '3.11.*'" },
- { name = "jedi", marker = "python_full_version == '3.11.*'" },
- { name = "matplotlib-inline", marker = "python_full_version == '3.11.*'" },
- { name = "pexpect", marker = "python_full_version == '3.11.*' and sys_platform != 'emscripten' and sys_platform != 'win32'" },
- { name = "prompt-toolkit", marker = "python_full_version == '3.11.*'" },
- { name = "pygments", marker = "python_full_version == '3.11.*'" },
- { name = "stack-data", marker = "python_full_version == '3.11.*'" },
- { name = "traitlets", marker = "python_full_version == '3.11.*'" },
- { name = "typing-extensions", marker = "python_full_version == '3.11.*'" },
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+ { name = "decorator" },
+ { name = "ipython-pygments-lexers" },
+ { name = "jedi" },
+ { name = "matplotlib-inline" },
+ { name = "pexpect", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" },
+ { name = "prompt-toolkit" },
+ { name = "pygments" },
+ { name = "stack-data" },
+ { name = "traitlets" },
+ { name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/c5/25/daae0e764047b0a2480c7bbb25d48f4f509b5818636562eeac145d06dfee/ipython-9.10.1.tar.gz", hash = "sha256:e170e9b2a44312484415bdb750492699bf329233b03f2557a9692cce6466ada4", size = 4426663, upload-time = "2026-03-27T09:53:26.244Z" }
wheels = [
@@ -1395,16 +1424,16 @@ resolution-markers = [
"python_full_version == '3.12.*'",
]
dependencies = [
- { name = "colorama", marker = "python_full_version >= '3.12' and sys_platform == 'win32'" },
- { name = "decorator", marker = "python_full_version >= '3.12'" },
- { name = "ipython-pygments-lexers", marker = "python_full_version >= '3.12'" },
- { name = "jedi", marker = "python_full_version >= '3.12'" },
- { name = "matplotlib-inline", marker = "python_full_version >= '3.12'" },
- { name = "pexpect", marker = "python_full_version >= '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'" },
- { name = "prompt-toolkit", marker = "python_full_version >= '3.12'" },
- { name = "pygments", marker = "python_full_version >= '3.12'" },
- { name = "stack-data", marker = "python_full_version >= '3.12'" },
- { name = "traitlets", marker = "python_full_version >= '3.12'" },
+ { name = "colorama", marker = "sys_platform == 'win32'" },
+ { name = "decorator" },
+ { name = "ipython-pygments-lexers" },
+ { name = "jedi" },
+ { name = "matplotlib-inline" },
+ { name = "pexpect", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" },
+ { name = "prompt-toolkit" },
+ { name = "pygments" },
+ { name = "stack-data" },
+ { name = "traitlets" },
]
sdist = { url = "https://files.pythonhosted.org/packages/3a/73/7114f80a8f9cabdb13c27732dce24af945b2923dcab80723602f7c8bc2d8/ipython-9.12.0.tar.gz", hash = "sha256:01daa83f504b693ba523b5a407246cabde4eb4513285a3c6acaff11a66735ee4", size = 4428879, upload-time = "2026-03-27T09:42:45.312Z" }
wheels = [
@@ -1416,7 +1445,7 @@ name = "ipython-pygments-lexers"
version = "1.1.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
- { name = "pygments", marker = "python_full_version >= '3.11'" },
+ { name = "pygments" },
]
sdist = { url = "https://files.pythonhosted.org/packages/ef/4c/5dd1d8af08107f88c7f741ead7a40854b8ac24ddf9ae850afbcf698aa552/ipython_pygments_lexers-1.1.1.tar.gz", hash = "sha256:09c0138009e56b6854f9535736f4171d855c8c08a563a0dcd8022f78355c7e81", size = 8393, upload-time = "2025-01-17T11:24:34.505Z" }
wheels = [
@@ -1544,6 +1573,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d9/71/71408b02c6133153336d29fa3ba53000f1e1a3f78bb2fc2d1a1865d2e743/jiter-0.11.1-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18c77aaa9117510d5bdc6a946baf21b1f0cfa58ef04d31c8d016f206f2118960", size = 343697, upload-time = "2025-10-17T11:31:13.773Z" },
]
+[[package]]
+name = "jmespath"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/d3/59/322338183ecda247fb5d1763a6cbe46eff7222eaeebafd9fa65d4bf5cb11/jmespath-1.1.0.tar.gz", hash = "sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d", size = 27377, upload-time = "2026-01-22T16:35:26.279Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/14/2f/967ba146e6d58cf6a652da73885f52fc68001525b4197effc174321d70b4/jmespath-1.1.0-py3-none-any.whl", hash = "sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64", size = 20419, upload-time = "2026-01-22T16:35:24.919Z" },
+]
+
[[package]]
name = "json-repair"
version = "0.60.1"
@@ -1620,10 +1658,11 @@ wheels = [
[[package]]
name = "litellm"
-version = "1.88.6"
+version = "1.100.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "aiohttp" },
+ { name = "boto3" },
{ name = "click" },
{ name = "fastuuid" },
{ name = "httpx" },
@@ -1632,13 +1671,21 @@ dependencies = [
{ name = "jsonschema" },
{ name = "openai" },
{ name = "pydantic" },
+ { name = "pydantic-settings", version = "2.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
+ { name = "pydantic-settings", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
{ name = "python-dotenv" },
{ name = "tiktoken" },
{ name = "tokenizers" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/f4/a6/d2312da4d65390f0d899a669731500983c8a10bd89009657680949c5766d/litellm-1.88.6.tar.gz", hash = "sha256:07d947dfe92f137d5296c40285dbcf97cb405b4300d73c0feda48d76468d6eb4", size = 13889078, upload-time = "2026-08-09T00:06:33.818Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/71/63/28fb5696e52f40f4bafd096a3d0ed2c8679a24311ed89c200a280ee3b68a/litellm-1.100.4.tar.gz", hash = "sha256:c031cbc63848be16403725594f6060fe002dc2e65f0866878285d72923ac27ab", size = 17338625, upload-time = "2026-09-29T23:04:57.065Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f7/0b/2e42b95ccca2e2a8a524808e9c414f70a0352165dac589efa01192afb8ba/litellm-1.88.6-py3-none-any.whl", hash = "sha256:8c01f7e9aebded5b3509128be648518a2ec4f1feb8dfb87a539895091651898b", size = 15271205, upload-time = "2026-08-09T00:06:30.607Z" },
+ { url = "https://files.pythonhosted.org/packages/67/5e/407031806577da6b1f3c9217774dabcc1353345337282093915411596aa9/litellm-1.100.4-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:c86e2e3370674557547022eb9acd8ec842f802bddb2cfa97992332ad56309a53", size = 23902271, upload-time = "2026-09-29T23:04:39.582Z" },
+ { url = "https://files.pythonhosted.org/packages/db/71/a284cce63fa6c37dab677415d146c968d9d802e1eed2778efcdddba49010/litellm-1.100.4-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:737c99748f9a37e74d4927ad9fe311e3f531a5379ea423eb0d1412d3310f1643", size = 23553194, upload-time = "2026-09-29T23:04:43.133Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/55/c16164e6cbae93437f50aaf550c5dcacc7a1ca4f1af80ece2c116fbeb01e/litellm-1.100.4-cp310-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7228d4d12eb332e5e7b7dbfeb41a4182784ad2acf86f6b7eb806565e04912ada", size = 23696180, upload-time = "2026-09-29T23:04:45.734Z" },
+ { url = "https://files.pythonhosted.org/packages/ff/09/d99612074d3e114c449fc928d7374f09d8e87cc74dc36fdbb466fc1b9f5a/litellm-1.100.4-cp310-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:ded14b15466163c76c9a7da0cd091663b4bebbff9aa56724a5905386a9d12532", size = 24066201, upload-time = "2026-09-29T23:04:48.071Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/a0/cc57f435963705f6baeaa717a870a616dd83981217daa81c9de2c2456a0d/litellm-1.100.4-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:eb12645456c19dd56f1fa5d7e165a2a76effb1501ace5d0a4df18efc0ac5c39a", size = 23769546, upload-time = "2026-09-29T23:04:50.353Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/dd/b7b458120100e47fa17718fa7aa7f1953cc01b34ce0439cc9f681cc746a0/litellm-1.100.4-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:aa8e8507678451b18c4369b69506d8948154b2ab4af211454dd062380597c1ce", size = 24166511, upload-time = "2026-09-29T23:04:52.583Z" },
+ { url = "https://files.pythonhosted.org/packages/26/35/51d5be49f6add1bea14a0d47cb4f125fc343150095e2e655aa02cba2e885/litellm-1.100.4-cp310-abi3-win_amd64.whl", hash = "sha256:83342175eb948f146f405735b03c1cb1e5c332aeef6a98cfb31f59233d10426a", size = 23981383, upload-time = "2026-09-29T23:04:54.838Z" },
]
[[package]]
@@ -2242,11 +2289,11 @@ wheels = [
[[package]]
name = "oauthlib"
-version = "4.0.0"
+version = "4.0.1"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/7a/d8/a1bcc8ba112a627f8ffbdc212a78ce18d3ac07e91a5ca65d27918eee25a1/oauthlib-4.0.0.tar.gz", hash = "sha256:efb274799819440f95b4ab3b818869f1ce9ae26c5beacba0201d1a1b76b54f86", size = 187232, upload-time = "2026-09-28T06:01:18.77Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/33/17/2bb072de0b990303c985f26869fd47bb179024a051f47e7f9d208eb92f8e/oauthlib-4.0.1.tar.gz", hash = "sha256:3d73febdb6faa00f277c81fb04be7b7586fb96fc3b7f0b9c772dada69a25ede7", size = 191219, upload-time = "2026-10-31T09:52:58.008Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/d9/f4/78229a1066068ca14fc60fb26cf7381cabe4382261392b90e5f9552722d4/oauthlib-4.0.0-py3-none-any.whl", hash = "sha256:624c28c13a0a59cabf9747dfa52af63be3e512a7f2714df16e91b5b3a145e6cd", size = 159715, upload-time = "2026-09-28T06:01:17.008Z" },
+ { url = "https://files.pythonhosted.org/packages/df/ef/3b8adde1b32a6f540758bff734d3442c621734c83708e5f02b0ba2f43b84/oauthlib-4.0.1-py3-none-any.whl", hash = "sha256:498a298876e996301950a5b053d12c31628bb7b895db03666430c69ce182eb61", size = 161934, upload-time = "2026-10-31T09:52:56.206Z" },
]
[[package]]
@@ -2688,7 +2735,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.64.1"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "distro" },
@@ -2699,16 +2746,23 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "anthropic", marker = "extra == 'test'", specifier = ">=0.72" },
+ { name = "celery", marker = "extra == 'test'", specifier = ">=5.3,<6" },
{ name = "claude-agent-sdk", marker = "extra == 'test'" },
{ name = "coverage", marker = "extra == 'test'" },
{ name = "distro", specifier = ">=1.5.0" },
{ name = "django", marker = "extra == 'test'", specifier = ">=5.2.15,<6.0" },
{ name = "django-stubs", marker = "extra == 'dev'" },
+ { name = "djangorestframework", marker = "extra == 'test'", specifier = ">=3.15,<4" },
+ { name = "fastapi", marker = "extra == 'test'", specifier = ">=0.115,<1" },
{ name = "fastmcp", marker = "extra == 'test'", specifier = ">=2.0" },
+ { name = "flask", marker = "extra == 'test'", specifier = ">=2.2" },
{ name = "freezegun", marker = "extra == 'test'", specifier = "==1.5.1" },
{ name = "gevent", marker = "implementation_name == 'cpython' and extra == 'test'", specifier = ">=25.4.1" },
{ name = "google-genai", marker = "extra == 'test'" },
{ name = "griffe", marker = "extra == 'dev'" },
+ { name = "griffe", marker = "extra == 'test'" },
+ { name = "griffe2md", marker = "extra == 'dev'" },
+ { name = "griffe2md", marker = "extra == 'test'" },
{ name = "httpx", marker = "extra == 'async'", specifier = ">=0.27.0,<1.0" },
{ name = "jsonschema", marker = "extra == 'test'", specifier = ">=4.0" },
{ name = "langchain", marker = "extra == 'langchain'", specifier = ">=1.3.9" },
@@ -2724,8 +2778,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -2753,7 +2821,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
@@ -3233,16 +3301,40 @@ wheels = [
[[package]]
name = "pydantic-settings"
-version = "2.10.1"
+version = "2.15.0"
+source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version < '3.11'",
+]
+dependencies = [
+ { name = "pydantic" },
+ { name = "python-dotenv" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/68/ca/31c57507b13119d7d3cfa1576dad2911a4861e3be07b579395f4e9d393f9/pydantic_settings-2.15.0.tar.gz", hash = "sha256:694b793e84f766ba76a90ebdefc01d0a9a045dab0382bee70393da93712ad117", size = 261253, upload-time = "2026-08-07T09:24:57.419Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/30/a4/2bffa9f8e804325a09867f0e9d30795c80ea9f8d62560bd1b6ad6220eb2f/pydantic_settings-2.15.0-py3-none-any.whl", hash = "sha256:0ba092c291c94baceb5eff768aa0d56400a457585bc0175925a5a5510303da42", size = 69413, upload-time = "2026-08-07T09:24:55.839Z" },
+]
+
+[[package]]
+name = "pydantic-settings"
+version = "2.16.2"
source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version >= '3.14'",
+ "python_full_version == '3.13.*'",
+ "python_full_version == '3.12.*'",
+ "python_full_version == '3.11.*'",
+]
dependencies = [
{ name = "pydantic" },
{ name = "python-dotenv" },
+ { name = "typing-extensions" },
{ name = "typing-inspection" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/68/85/1ea668bbab3c50071ca613c6ab30047fb36ab0da1b92fa8f17bbc38fd36c/pydantic_settings-2.10.1.tar.gz", hash = "sha256:06f0062169818d0f5524420a360d632d5857b83cffd4d42fe29597807a1614ee", size = 172583, upload-time = "2025-06-24T13:26:46.841Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/d0/31/21d21e0e38a8f5f7a7f0cde22820117b6d17d6bc36f348129527f915d7f4/pydantic_settings-2.16.2.tar.gz", hash = "sha256:3dc08ffabed2bbd5dc2dd55ead7b78b4e4c5cd776aecd04310db5f1224caaf46", size = 309225, upload-time = "2026-10-28T11:14:28.066Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/58/f0/427018098906416f580e3cf1366d3b1abfb408a0652e9f31600c24a1903c/pydantic_settings-2.10.1-py3-none-any.whl", hash = "sha256:a60952460b99cf661dc25c29c0ef171721f98bfcb52ef8d9ea4c943d7c8cc796", size = 45235, upload-time = "2025-06-24T13:26:45.485Z" },
+ { url = "https://files.pythonhosted.org/packages/39/88/4131c51ff87b7cd7f82a1194d0c0a2b7ca68c72d9da04c3b7e69ab91a79f/pydantic_settings-2.16.2-py3-none-any.whl", hash = "sha256:8d523e5c129b097686bde019bd6109bff53f4c8c3f63f1ddf9933ffa42e5ab4f", size = 81994, upload-time = "2026-10-28T11:14:26.716Z" },
]
[[package]]
@@ -3725,6 +3817,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/b7/b95708304cd49b7b6f82fdd039f1748b66ec2b21d6a45180910802f1abf1/rpds_py-0.30.0-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:ac37f9f516c51e5753f27dfdef11a88330f04de2d564be3991384b2f3535d02e", size = 562191, upload-time = "2025-11-30T20:24:36.853Z" },
]
+[[package]]
+name = "s3transfer"
+version = "0.19.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/49/c5/0a5ce655109cb96b8dfad36908a4e108d15f5dc2eff8fbc3146c4312e704/s3transfer-0.19.3.tar.gz", hash = "sha256:8326acc3d056d7f7b8a37110c7d2aea41f67e83f6ae79cd3b5fbcca34c726406", size = 166087, upload-time = "2026-10-19T19:19:49.751Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e2/a4/88f9e10498759121060b8050a1554753dfc04df39bbbcc7aad9ecc8d9440/s3transfer-0.19.3-py3-none-any.whl", hash = "sha256:24eb7535804306355e31c952a90022bf5b2f9d760f9a11062c7493a217c08553", size = 90252, upload-time = "2026-10-19T19:19:48.309Z" },
+]
+
[[package]]
name = "shellingham"
version = "1.5.4"
diff --git a/examples/example-ai-dspy/pyproject.toml b/examples/example-ai-dspy/pyproject.toml
index 48e96ffad..c4dbff5b7 100644
--- a/examples/example-ai-dspy/pyproject.toml
+++ b/examples/example-ai-dspy/pyproject.toml
@@ -5,7 +5,7 @@ requires-python = ">=3.10"
dependencies = [
"posthog",
"dspy>=2.5.0",
- "litellm==1.88.6",
+ "litellm==1.100.4",
]
[tool.uv.sources]
diff --git a/examples/example-ai-dspy/uv.lock b/examples/example-ai-dspy/uv.lock
index 60c92785b..3e43adc7d 100644
--- a/examples/example-ai-dspy/uv.lock
+++ b/examples/example-ai-dspy/uv.lock
@@ -7,7 +7,7 @@ resolution-markers = [
]
[options]
-exclude-newer = "2026-10-03T03:16:08.499203Z"
+exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values.
exclude-newer-span = "P7D"
[options.exclude-newer-package]
@@ -291,6 +291,34 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" },
]
+[[package]]
+name = "boto3"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+ { name = "jmespath" },
+ { name = "s3transfer" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fc/8a/64b46f075149f9160da44aa7e1052dd18431b9ad4435beb0cfb02cc48624/boto3-1.43.123.tar.gz", hash = "sha256:055fabb990c5d2f31fce4ca569255bd640cdd11a3ca68c9ecad35f4f8a5b83b5", size = 112638, upload-time = "2026-10-30T19:18:50.085Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/96/b2/a7986c327f80aa6f1544f4cb8f2fa7da4e1fccd472379a21cad0508b8a0e/boto3-1.43.123-py3-none-any.whl", hash = "sha256:d18d66e1e13faa0c25d0b1b8c5ce946e29fb5fc0b6456b655a93a678ff4cc313", size = 140044, upload-time = "2026-10-30T19:18:47.734Z" },
+]
+
+[[package]]
+name = "botocore"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "jmespath" },
+ { name = "python-dateutil" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e0/de/011fc2a47fb066c47064b122498d2fd21f55bc90ea514acbddc37ca0f8c1/botocore-1.43.123.tar.gz", hash = "sha256:80948cb9b1cdf1a1a25809089a42e3a1bc4af0258d198222db6e97dcc660dd0c", size = 16486269, upload-time = "2026-10-30T19:18:44.609Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/db/96/4f2dffd304425c07160ab2c12cb13322d852fd956fe9d4386228c93f02ea/botocore-1.43.123-py3-none-any.whl", hash = "sha256:e30580f9c1282c321529238ff8ff75066096a2adbd0a293c8ae592c21d1733a3", size = 16185987, upload-time = "2026-10-30T19:18:39.794Z" },
+]
+
[[package]]
name = "cachetools"
version = "7.0.5"
@@ -517,7 +545,7 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "dspy", specifier = ">=2.5.0" },
- { name = "litellm", specifier = "==1.88.6" },
+ { name = "litellm", specifier = "==1.100.4" },
{ name = "posthog", directory = "../../" },
]
@@ -526,7 +554,7 @@ name = "exceptiongroup"
version = "1.3.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
- { name = "typing-extensions", marker = "python_full_version < '3.11'" },
+ { name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" }
wheels = [
@@ -1017,6 +1045,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/67/8a/a342b2f0251f3dac4ca17618265d93bf244a2a4d089126e81e4c1056ac50/jiter-0.13.0-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7bb00b6d26db67a05fe3e12c76edc75f32077fb51deed13822dc648fa373bc19", size = 343768, upload-time = "2026-02-02T12:37:55.055Z" },
]
+[[package]]
+name = "jmespath"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/d3/59/322338183ecda247fb5d1763a6cbe46eff7222eaeebafd9fa65d4bf5cb11/jmespath-1.1.0.tar.gz", hash = "sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d", size = 27377, upload-time = "2026-01-22T16:35:26.279Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/14/2f/967ba146e6d58cf6a652da73885f52fc68001525b4197effc174321d70b4/jmespath-1.1.0-py3-none-any.whl", hash = "sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64", size = 20419, upload-time = "2026-01-22T16:35:24.919Z" },
+]
+
[[package]]
name = "json-repair"
version = "0.60.1"
@@ -1055,10 +1092,11 @@ wheels = [
[[package]]
name = "litellm"
-version = "1.88.6"
+version = "1.100.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "aiohttp" },
+ { name = "boto3" },
{ name = "click" },
{ name = "fastuuid" },
{ name = "httpx" },
@@ -1067,13 +1105,21 @@ dependencies = [
{ name = "jsonschema" },
{ name = "openai" },
{ name = "pydantic" },
+ { name = "pydantic-settings", version = "2.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
+ { name = "pydantic-settings", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
{ name = "python-dotenv" },
{ name = "tiktoken" },
{ name = "tokenizers" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/f4/a6/d2312da4d65390f0d899a669731500983c8a10bd89009657680949c5766d/litellm-1.88.6.tar.gz", hash = "sha256:07d947dfe92f137d5296c40285dbcf97cb405b4300d73c0feda48d76468d6eb4", size = 13889078, upload-time = "2026-08-09T00:06:33.818Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/71/63/28fb5696e52f40f4bafd096a3d0ed2c8679a24311ed89c200a280ee3b68a/litellm-1.100.4.tar.gz", hash = "sha256:c031cbc63848be16403725594f6060fe002dc2e65f0866878285d72923ac27ab", size = 17338625, upload-time = "2026-09-29T23:04:57.065Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f7/0b/2e42b95ccca2e2a8a524808e9c414f70a0352165dac589efa01192afb8ba/litellm-1.88.6-py3-none-any.whl", hash = "sha256:8c01f7e9aebded5b3509128be648518a2ec4f1feb8dfb87a539895091651898b", size = 15271205, upload-time = "2026-08-09T00:06:30.607Z" },
+ { url = "https://files.pythonhosted.org/packages/67/5e/407031806577da6b1f3c9217774dabcc1353345337282093915411596aa9/litellm-1.100.4-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:c86e2e3370674557547022eb9acd8ec842f802bddb2cfa97992332ad56309a53", size = 23902271, upload-time = "2026-09-29T23:04:39.582Z" },
+ { url = "https://files.pythonhosted.org/packages/db/71/a284cce63fa6c37dab677415d146c968d9d802e1eed2778efcdddba49010/litellm-1.100.4-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:737c99748f9a37e74d4927ad9fe311e3f531a5379ea423eb0d1412d3310f1643", size = 23553194, upload-time = "2026-09-29T23:04:43.133Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/55/c16164e6cbae93437f50aaf550c5dcacc7a1ca4f1af80ece2c116fbeb01e/litellm-1.100.4-cp310-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7228d4d12eb332e5e7b7dbfeb41a4182784ad2acf86f6b7eb806565e04912ada", size = 23696180, upload-time = "2026-09-29T23:04:45.734Z" },
+ { url = "https://files.pythonhosted.org/packages/ff/09/d99612074d3e114c449fc928d7374f09d8e87cc74dc36fdbb466fc1b9f5a/litellm-1.100.4-cp310-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:ded14b15466163c76c9a7da0cd091663b4bebbff9aa56724a5905386a9d12532", size = 24066201, upload-time = "2026-09-29T23:04:48.071Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/a0/cc57f435963705f6baeaa717a870a616dd83981217daa81c9de2c2456a0d/litellm-1.100.4-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:eb12645456c19dd56f1fa5d7e165a2a76effb1501ace5d0a4df18efc0ac5c39a", size = 23769546, upload-time = "2026-09-29T23:04:50.353Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/dd/b7b458120100e47fa17718fa7aa7f1953cc01b34ce0439cc9f681cc746a0/litellm-1.100.4-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:aa8e8507678451b18c4369b69506d8948154b2ab4af211454dd062380597c1ce", size = 24166511, upload-time = "2026-09-29T23:04:52.583Z" },
+ { url = "https://files.pythonhosted.org/packages/26/35/51d5be49f6add1bea14a0d47cb4f125fc343150095e2e655aa02cba2e885/litellm-1.100.4-cp310-abi3-win_amd64.whl", hash = "sha256:83342175eb948f146f405735b03c1cb1e5c332aeef6a98cfb31f59233d10426a", size = 23981383, upload-time = "2026-09-29T23:04:54.838Z" },
]
[[package]]
@@ -1652,7 +1698,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.64.1"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "distro" },
@@ -1663,16 +1709,23 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "anthropic", marker = "extra == 'test'", specifier = ">=0.72" },
+ { name = "celery", marker = "extra == 'test'", specifier = ">=5.3,<6" },
{ name = "claude-agent-sdk", marker = "extra == 'test'" },
{ name = "coverage", marker = "extra == 'test'" },
{ name = "distro", specifier = ">=1.5.0" },
{ name = "django", marker = "extra == 'test'", specifier = ">=5.2.15,<6.0" },
{ name = "django-stubs", marker = "extra == 'dev'" },
+ { name = "djangorestframework", marker = "extra == 'test'", specifier = ">=3.15,<4" },
+ { name = "fastapi", marker = "extra == 'test'", specifier = ">=0.115,<1" },
{ name = "fastmcp", marker = "extra == 'test'", specifier = ">=2.0" },
+ { name = "flask", marker = "extra == 'test'", specifier = ">=2.2" },
{ name = "freezegun", marker = "extra == 'test'", specifier = "==1.5.1" },
{ name = "gevent", marker = "implementation_name == 'cpython' and extra == 'test'", specifier = ">=25.4.1" },
{ name = "google-genai", marker = "extra == 'test'" },
{ name = "griffe", marker = "extra == 'dev'" },
+ { name = "griffe", marker = "extra == 'test'" },
+ { name = "griffe2md", marker = "extra == 'dev'" },
+ { name = "griffe2md", marker = "extra == 'test'" },
{ name = "httpx", marker = "extra == 'async'", specifier = ">=0.27.0,<1.0" },
{ name = "jsonschema", marker = "extra == 'test'", specifier = ">=4.0" },
{ name = "langchain", marker = "extra == 'langchain'", specifier = ">=1.3.9" },
@@ -1688,8 +1741,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -1717,7 +1784,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
@@ -1969,6 +2036,41 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/36/c7/cfc8e811f061c841d7990b0201912c3556bfeb99cdcb7ed24adc8d6f8704/pydantic_core-2.41.5-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:56121965f7a4dc965bff783d70b907ddf3d57f6eba29b6d2e5dabfaf07799c51", size = 2145302, upload-time = "2025-11-04T13:43:46.64Z" },
]
+[[package]]
+name = "pydantic-settings"
+version = "2.15.0"
+source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version < '3.11'",
+]
+dependencies = [
+ { name = "pydantic" },
+ { name = "python-dotenv" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/68/ca/31c57507b13119d7d3cfa1576dad2911a4861e3be07b579395f4e9d393f9/pydantic_settings-2.15.0.tar.gz", hash = "sha256:694b793e84f766ba76a90ebdefc01d0a9a045dab0382bee70393da93712ad117", size = 261253, upload-time = "2026-08-07T09:24:57.419Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/30/a4/2bffa9f8e804325a09867f0e9d30795c80ea9f8d62560bd1b6ad6220eb2f/pydantic_settings-2.15.0-py3-none-any.whl", hash = "sha256:0ba092c291c94baceb5eff768aa0d56400a457585bc0175925a5a5510303da42", size = 69413, upload-time = "2026-08-07T09:24:55.839Z" },
+]
+
+[[package]]
+name = "pydantic-settings"
+version = "2.16.2"
+source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version >= '3.11'",
+]
+dependencies = [
+ { name = "pydantic" },
+ { name = "python-dotenv" },
+ { name = "typing-extensions" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d0/31/21d21e0e38a8f5f7a7f0cde22820117b6d17d6bc36f348129527f915d7f4/pydantic_settings-2.16.2.tar.gz", hash = "sha256:3dc08ffabed2bbd5dc2dd55ead7b78b4e4c5cd776aecd04310db5f1224caaf46", size = 309225, upload-time = "2026-10-28T11:14:28.066Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/39/88/4131c51ff87b7cd7f82a1194d0c0a2b7ca68c72d9da04c3b7e69ab91a79f/pydantic_settings-2.16.2-py3-none-any.whl", hash = "sha256:8d523e5c129b097686bde019bd6109bff53f4c8c3f63f1ddf9933ffa42e5ab4f", size = 81994, upload-time = "2026-10-28T11:14:26.716Z" },
+]
+
[[package]]
name = "pygments"
version = "2.20.0"
@@ -1978,6 +2080,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
]
+[[package]]
+name = "python-dateutil"
+version = "2.9.0.post0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
+]
+
[[package]]
name = "python-dotenv"
version = "1.2.4"
@@ -2336,6 +2450,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/b7/b95708304cd49b7b6f82fdd039f1748b66ec2b21d6a45180910802f1abf1/rpds_py-0.30.0-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:ac37f9f516c51e5753f27dfdef11a88330f04de2d564be3991384b2f3535d02e", size = 562191, upload-time = "2025-11-30T20:24:36.853Z" },
]
+[[package]]
+name = "s3transfer"
+version = "0.19.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/49/c5/0a5ce655109cb96b8dfad36908a4e108d15f5dc2eff8fbc3146c4312e704/s3transfer-0.19.3.tar.gz", hash = "sha256:8326acc3d056d7f7b8a37110c7d2aea41f67e83f6ae79cd3b5fbcca34c726406", size = 166087, upload-time = "2026-10-19T19:19:49.751Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e2/a4/88f9e10498759121060b8050a1554753dfc04df39bbbcc7aad9ecc8d9440/s3transfer-0.19.3-py3-none-any.whl", hash = "sha256:24eb7535804306355e31c952a90022bf5b2f9d760f9a11062c7493a217c08553", size = 90252, upload-time = "2026-10-19T19:19:48.309Z" },
+]
+
[[package]]
name = "shellingham"
version = "1.5.4"
@@ -2345,6 +2471,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
]
+[[package]]
+name = "six"
+version = "1.17.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },
+]
+
[[package]]
name = "sniffio"
version = "1.3.1"
diff --git a/examples/example-ai-gemini/uv.lock b/examples/example-ai-gemini/uv.lock
index 0402b9905..e90030424 100644
--- a/examples/example-ai-gemini/uv.lock
+++ b/examples/example-ai-gemini/uv.lock
@@ -43,11 +43,11 @@ wheels = [
[[package]]
name = "certifi"
-version = "2026.10.19"
+version = "2026.10.23"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" },
]
[[package]]
@@ -597,7 +597,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.75.11"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -645,9 +645,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -675,7 +688,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
@@ -697,11 +710,11 @@ wheels = [
[[package]]
name = "pyasn1"
-version = "0.6.4"
+version = "0.6.5"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a4/9a/23310166d960def5897e91fe20e5b724601b02a22e84ba1f94232c0b7f67/pyasn1-0.6.4.tar.gz", hash = "sha256:9c447d8431c947fe4c8febc4ed9e760bc29011a5b01e5c74b67025bd9fb8ce81", size = 151262, upload-time = "2026-07-09T01:12:33.988Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/88/7e/3c0da41061a2021cac7cd524fd57092adbe5b515e8bf9005702e366802e2/pyasn1-0.6.5.tar.gz", hash = "sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47", size = 155152, upload-time = "2026-10-27T06:32:49.125Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/9a/3b/6163796d69c3977d1e4287bea4a6979161cbbdd170ebb430511e8e1999ce/pyasn1-0.6.4-py3-none-any.whl", hash = "sha256:deda9277cfd454080ec40b207fb6df82206a3a2688735233cdcd8d3d565f088b", size = 84410, upload-time = "2026-07-09T01:12:32.92Z" },
+ { url = "https://files.pythonhosted.org/packages/19/1f/3eefd5c84c35cae44549ce1c7f7e58f7945b34f5a6bce07a135438522073/pyasn1-0.6.5-py3-none-any.whl", hash = "sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587", size = 84807, upload-time = "2026-10-27T06:32:48.045Z" },
]
[[package]]
diff --git a/examples/example-ai-langchain/uv.lock b/examples/example-ai-langchain/uv.lock
index 00c05f8ec..a6c8d1a9d 100644
--- a/examples/example-ai-langchain/uv.lock
+++ b/examples/example-ai-langchain/uv.lock
@@ -43,11 +43,11 @@ wheels = [
[[package]]
name = "certifi"
-version = "2026.10.19"
+version = "2026.10.23"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" },
]
[[package]]
@@ -444,7 +444,7 @@ wheels = [
[[package]]
name = "langgraph"
-version = "1.2.9"
+version = "1.2.19"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "langchain-core" },
@@ -454,22 +454,22 @@ dependencies = [
{ name = "pydantic" },
{ name = "xxhash" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/41/4b/0d1130e26b41a99dcc88353bbe7162a1f255c4db746bd94024268e6af27b/langgraph-1.2.9.tar.gz", hash = "sha256:385f87bc1802c35af7e0aa479278ecba8582d103515eb48256cb2ddcd42d0bd4", size = 722869, upload-time = "2026-07-10T01:30:14.985Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/ba/10/329dc49ce3fc40e36faafd407f08607fe3fab75613e709a66758b53faac2/langgraph-1.2.19.tar.gz", hash = "sha256:4a00fa1aad2b5fc2d3a789a8e9eaf993f76218ca924b434902ecf1bbaaf300f6", size = 782618, upload-time = "2026-10-30T22:23:32.962Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/41/16/0b8dc48823f1326f3e0c8012a3c07a40da6f194299e2ec080df236287baf/langgraph-1.2.9-py3-none-any.whl", hash = "sha256:c2d98ad94333937922ba04148641c1da2bfe45b5b8e55d7b6dcb0bb2df809e76", size = 247473, upload-time = "2026-07-10T01:30:13.733Z" },
+ { url = "https://files.pythonhosted.org/packages/d7/9e/bd29e368fb16feea8d24270d377d56c34b49afea371717124f19cdfa890c/langgraph-1.2.19-py3-none-any.whl", hash = "sha256:6094a5cbed52a77d8c74c276fcd2056abde7b2836eab1c7a6b74bacbd1a269b3", size = 262285, upload-time = "2026-10-30T22:23:31.334Z" },
]
[[package]]
name = "langgraph-checkpoint"
-version = "4.1.1"
+version = "4.3.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "langchain-core" },
{ name = "ormsgpack" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/83/47/886af6f886f0bff2273164a45f008694e48a96ff3cd25ff0228f2aa9480e/langgraph_checkpoint-4.1.1.tar.gz", hash = "sha256:6c2bdb530c91f91d7d9c1bd100925d0fc4f498d418c17f3587d1526279482a25", size = 184020, upload-time = "2026-05-22T16:57:38.503Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/f0/c4/f4107f50dd07169d08d95766cd69104231e694f44a1b25b68ad8b393712d/langgraph_checkpoint-4.3.1.tar.gz", hash = "sha256:625e7c78a72b33e7c47f7e87ca051060fb90aa66f5fd551c472c08376fb669cb", size = 182679, upload-time = "2026-10-26T19:57:31.416Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/bd/b4/71425e3e38be92611300b9cc5e46a5bf98ab23f5ea8a75b73d02a2f1413c/langgraph_checkpoint-4.1.1-py3-none-any.whl", hash = "sha256:25d29144b082827218e7bc3f1e9b0566a4bb007895cd6cc26f66a8428739f56e", size = 56212, upload-time = "2026-05-22T16:57:37.203Z" },
+ { url = "https://files.pythonhosted.org/packages/f3/40/4251d676b5c585d42175c901175d4bff56e22939625e18bcef781fc3e893/langgraph_checkpoint-4.3.1-py3-none-any.whl", hash = "sha256:215a826935c8db4d9676e79fd95943e5b3847d78604390898e1d98581cc594e5", size = 58093, upload-time = "2026-10-26T19:57:30.361Z" },
]
[[package]]
@@ -487,7 +487,7 @@ wheels = [
[[package]]
name = "langgraph-sdk"
-version = "0.4.4"
+version = "0.4.12"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx" },
@@ -496,9 +496,9 @@ dependencies = [
{ name = "orjson" },
{ name = "websockets" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/3f/ae/91446c1fffa04a2dc1f81afbfb5bfff3590452891a72bd9098a656ab2657/langgraph_sdk-0.4.4.tar.gz", hash = "sha256:4e651ffa09de695681579396375377bdde23bedbc8e35b070e615cbd5af7da8b", size = 345789, upload-time = "2026-08-27T21:25:22.593Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/24/44/3b07ae42ebfd3cc343201a2ff708d470867082810e747ea5d8dd85de50ec/langgraph_sdk-0.4.12.tar.gz", hash = "sha256:2f7ea2b9a7048e1ff9c3be7308b36eb56d6bfcccbe8100aeea6db688002219e0", size = 369804, upload-time = "2026-11-03T18:10:16.606Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/43/d5/2ad7f3a835c6fcebf58b6669552536ecd52d2dfe4cf49c6c36648fd83572/langgraph_sdk-0.4.4-py3-none-any.whl", hash = "sha256:39afe416c91742925e6f8a93715f566d499b36e1b636b804a4ffe3190e4f4e64", size = 162270, upload-time = "2026-08-27T21:25:21.072Z" },
+ { url = "https://files.pythonhosted.org/packages/fb/7c/3789d5bfa872f87ed8443177baf5fe51da5840ccbabdbe87dac3fc65e9bd/langgraph_sdk-0.4.12-py3-none-any.whl", hash = "sha256:cfc2e659a3daa615062a29cfa39eea00b5ea58d2683dbf2f4487fc4244a98078", size = 170444, upload-time = "2026-11-03T18:10:15.309Z" },
]
[[package]]
@@ -848,7 +848,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.75.11"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -896,9 +896,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -926,7 +939,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
diff --git a/examples/example-ai-langgraph/uv.lock b/examples/example-ai-langgraph/uv.lock
index 436b5d46a..11180b80f 100644
--- a/examples/example-ai-langgraph/uv.lock
+++ b/examples/example-ai-langgraph/uv.lock
@@ -47,11 +47,11 @@ wheels = [
[[package]]
name = "certifi"
-version = "2026.10.19"
+version = "2026.10.23"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" },
]
[[package]]
@@ -477,7 +477,7 @@ wheels = [
[[package]]
name = "langgraph-sdk"
-version = "0.4.4"
+version = "0.4.6"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx" },
@@ -486,9 +486,9 @@ dependencies = [
{ name = "orjson" },
{ name = "websockets" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/3f/ae/91446c1fffa04a2dc1f81afbfb5bfff3590452891a72bd9098a656ab2657/langgraph_sdk-0.4.4.tar.gz", hash = "sha256:4e651ffa09de695681579396375377bdde23bedbc8e35b070e615cbd5af7da8b", size = 345789, upload-time = "2026-08-27T21:25:22.593Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/78/85/54edf4902c0378510f09a009f64e3d3f5644aeeb51d13cf67ec380a5245b/langgraph_sdk-0.4.6.tar.gz", hash = "sha256:ea5b1749d70987d741c9b9fe2b7e1c5f7da7e4d102f64e390333c1890c9bbd5b", size = 350632, upload-time = "2026-10-06T14:17:53.641Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/43/d5/2ad7f3a835c6fcebf58b6669552536ecd52d2dfe4cf49c6c36648fd83572/langgraph_sdk-0.4.4-py3-none-any.whl", hash = "sha256:39afe416c91742925e6f8a93715f566d499b36e1b636b804a4ffe3190e4f4e64", size = 162270, upload-time = "2026-08-27T21:25:21.072Z" },
+ { url = "https://files.pythonhosted.org/packages/6c/c7/69d13026db3577c157877dea47a9dc5fffd3dcde2d1ab8009fa8f7e5f6a6/langgraph_sdk-0.4.6-py3-none-any.whl", hash = "sha256:57122b02bda41d37a97a5e09eb018aa8c9b3dc85c433880073779bd9324b7eea", size = 162390, upload-time = "2026-10-06T14:17:52.134Z" },
]
[[package]]
@@ -834,7 +834,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.75.11"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -882,9 +882,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -912,7 +925,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
diff --git a/examples/example-ai-litellm/pyproject.toml b/examples/example-ai-litellm/pyproject.toml
index d3e0b35da..aaa2879c8 100644
--- a/examples/example-ai-litellm/pyproject.toml
+++ b/examples/example-ai-litellm/pyproject.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"posthog",
- "litellm==1.88.6",
+ "litellm==1.100.4",
]
[tool.uv.sources]
diff --git a/examples/example-ai-litellm/uv.lock b/examples/example-ai-litellm/uv.lock
index 43da30da9..dd170f784 100644
--- a/examples/example-ai-litellm/uv.lock
+++ b/examples/example-ai-litellm/uv.lock
@@ -1,9 +1,13 @@
version = 1
revision = 5
requires-python = ">=3.10"
+resolution-markers = [
+ "python_full_version >= '3.11'",
+ "python_full_version < '3.11'",
+]
[options]
-exclude-newer = "2026-10-03T03:16:09.116916Z"
+exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values.
exclude-newer-span = "P7D"
[options.exclude-newer-package]
@@ -260,6 +264,34 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" },
]
+[[package]]
+name = "boto3"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+ { name = "jmespath" },
+ { name = "s3transfer" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/fc/8a/64b46f075149f9160da44aa7e1052dd18431b9ad4435beb0cfb02cc48624/boto3-1.43.123.tar.gz", hash = "sha256:055fabb990c5d2f31fce4ca569255bd640cdd11a3ca68c9ecad35f4f8a5b83b5", size = 112638, upload-time = "2026-10-30T19:18:50.085Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/96/b2/a7986c327f80aa6f1544f4cb8f2fa7da4e1fccd472379a21cad0508b8a0e/boto3-1.43.123-py3-none-any.whl", hash = "sha256:d18d66e1e13faa0c25d0b1b8c5ce946e29fb5fc0b6456b655a93a678ff4cc313", size = 140044, upload-time = "2026-10-30T19:18:47.734Z" },
+]
+
+[[package]]
+name = "botocore"
+version = "1.43.123"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "jmespath" },
+ { name = "python-dateutil" },
+ { name = "urllib3" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/e0/de/011fc2a47fb066c47064b122498d2fd21f55bc90ea514acbddc37ca0f8c1/botocore-1.43.123.tar.gz", hash = "sha256:80948cb9b1cdf1a1a25809089a42e3a1bc4af0258d198222db6e97dcc660dd0c", size = 16486269, upload-time = "2026-10-30T19:18:44.609Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/db/96/4f2dffd304425c07160ab2c12cb13322d852fd956fe9d4386228c93f02ea/botocore-1.43.123-py3-none-any.whl", hash = "sha256:e30580f9c1282c321529238ff8ff75066096a2adbd0a293c8ae592c21d1733a3", size = 16185987, upload-time = "2026-10-30T19:18:39.794Z" },
+]
+
[[package]]
name = "certifi"
version = "2026.10.23"
@@ -415,7 +447,7 @@ dependencies = [
[package.metadata]
requires-dist = [
- { name = "litellm", specifier = "==1.88.6" },
+ { name = "litellm", specifier = "==1.100.4" },
{ name = "posthog", directory = "../../" },
]
@@ -424,7 +456,7 @@ name = "exceptiongroup"
version = "1.3.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
- { name = "typing-extensions", marker = "python_full_version < '3.13'" },
+ { name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" }
wheels = [
@@ -852,6 +884,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/67/8a/a342b2f0251f3dac4ca17618265d93bf244a2a4d089126e81e4c1056ac50/jiter-0.13.0-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7bb00b6d26db67a05fe3e12c76edc75f32077fb51deed13822dc648fa373bc19", size = 343768, upload-time = "2026-02-02T12:37:55.055Z" },
]
+[[package]]
+name = "jmespath"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/d3/59/322338183ecda247fb5d1763a6cbe46eff7222eaeebafd9fa65d4bf5cb11/jmespath-1.1.0.tar.gz", hash = "sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d", size = 27377, upload-time = "2026-01-22T16:35:26.279Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/14/2f/967ba146e6d58cf6a652da73885f52fc68001525b4197effc174321d70b4/jmespath-1.1.0-py3-none-any.whl", hash = "sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64", size = 20419, upload-time = "2026-01-22T16:35:24.919Z" },
+]
+
[[package]]
name = "jsonschema"
version = "4.23.0"
@@ -881,10 +922,11 @@ wheels = [
[[package]]
name = "litellm"
-version = "1.88.6"
+version = "1.100.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "aiohttp" },
+ { name = "boto3" },
{ name = "click" },
{ name = "fastuuid" },
{ name = "httpx" },
@@ -893,13 +935,21 @@ dependencies = [
{ name = "jsonschema" },
{ name = "openai" },
{ name = "pydantic" },
+ { name = "pydantic-settings", version = "2.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
+ { name = "pydantic-settings", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
{ name = "python-dotenv" },
{ name = "tiktoken" },
{ name = "tokenizers" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/f4/a6/d2312da4d65390f0d899a669731500983c8a10bd89009657680949c5766d/litellm-1.88.6.tar.gz", hash = "sha256:07d947dfe92f137d5296c40285dbcf97cb405b4300d73c0feda48d76468d6eb4", size = 13889078, upload-time = "2026-08-09T00:06:33.818Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/71/63/28fb5696e52f40f4bafd096a3d0ed2c8679a24311ed89c200a280ee3b68a/litellm-1.100.4.tar.gz", hash = "sha256:c031cbc63848be16403725594f6060fe002dc2e65f0866878285d72923ac27ab", size = 17338625, upload-time = "2026-09-29T23:04:57.065Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f7/0b/2e42b95ccca2e2a8a524808e9c414f70a0352165dac589efa01192afb8ba/litellm-1.88.6-py3-none-any.whl", hash = "sha256:8c01f7e9aebded5b3509128be648518a2ec4f1feb8dfb87a539895091651898b", size = 15271205, upload-time = "2026-08-09T00:06:30.607Z" },
+ { url = "https://files.pythonhosted.org/packages/67/5e/407031806577da6b1f3c9217774dabcc1353345337282093915411596aa9/litellm-1.100.4-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:c86e2e3370674557547022eb9acd8ec842f802bddb2cfa97992332ad56309a53", size = 23902271, upload-time = "2026-09-29T23:04:39.582Z" },
+ { url = "https://files.pythonhosted.org/packages/db/71/a284cce63fa6c37dab677415d146c968d9d802e1eed2778efcdddba49010/litellm-1.100.4-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:737c99748f9a37e74d4927ad9fe311e3f531a5379ea423eb0d1412d3310f1643", size = 23553194, upload-time = "2026-09-29T23:04:43.133Z" },
+ { url = "https://files.pythonhosted.org/packages/0c/55/c16164e6cbae93437f50aaf550c5dcacc7a1ca4f1af80ece2c116fbeb01e/litellm-1.100.4-cp310-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7228d4d12eb332e5e7b7dbfeb41a4182784ad2acf86f6b7eb806565e04912ada", size = 23696180, upload-time = "2026-09-29T23:04:45.734Z" },
+ { url = "https://files.pythonhosted.org/packages/ff/09/d99612074d3e114c449fc928d7374f09d8e87cc74dc36fdbb466fc1b9f5a/litellm-1.100.4-cp310-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:ded14b15466163c76c9a7da0cd091663b4bebbff9aa56724a5905386a9d12532", size = 24066201, upload-time = "2026-09-29T23:04:48.071Z" },
+ { url = "https://files.pythonhosted.org/packages/6e/a0/cc57f435963705f6baeaa717a870a616dd83981217daa81c9de2c2456a0d/litellm-1.100.4-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:eb12645456c19dd56f1fa5d7e165a2a76effb1501ace5d0a4df18efc0ac5c39a", size = 23769546, upload-time = "2026-09-29T23:04:50.353Z" },
+ { url = "https://files.pythonhosted.org/packages/d5/dd/b7b458120100e47fa17718fa7aa7f1953cc01b34ce0439cc9f681cc746a0/litellm-1.100.4-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:aa8e8507678451b18c4369b69506d8948154b2ab4af211454dd062380597c1ce", size = 24166511, upload-time = "2026-09-29T23:04:52.583Z" },
+ { url = "https://files.pythonhosted.org/packages/26/35/51d5be49f6add1bea14a0d47cb4f125fc343150095e2e655aa02cba2e885/litellm-1.100.4-cp310-abi3-win_amd64.whl", hash = "sha256:83342175eb948f146f405735b03c1cb1e5c332aeef6a98cfb31f59233d10426a", size = 23981383, upload-time = "2026-09-29T23:04:54.838Z" },
]
[[package]]
@@ -1219,7 +1269,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.64.1"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "distro" },
@@ -1230,16 +1280,23 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "anthropic", marker = "extra == 'test'", specifier = ">=0.72" },
+ { name = "celery", marker = "extra == 'test'", specifier = ">=5.3,<6" },
{ name = "claude-agent-sdk", marker = "extra == 'test'" },
{ name = "coverage", marker = "extra == 'test'" },
{ name = "distro", specifier = ">=1.5.0" },
{ name = "django", marker = "extra == 'test'", specifier = ">=5.2.15,<6.0" },
{ name = "django-stubs", marker = "extra == 'dev'" },
+ { name = "djangorestframework", marker = "extra == 'test'", specifier = ">=3.15,<4" },
+ { name = "fastapi", marker = "extra == 'test'", specifier = ">=0.115,<1" },
{ name = "fastmcp", marker = "extra == 'test'", specifier = ">=2.0" },
+ { name = "flask", marker = "extra == 'test'", specifier = ">=2.2" },
{ name = "freezegun", marker = "extra == 'test'", specifier = "==1.5.1" },
{ name = "gevent", marker = "implementation_name == 'cpython' and extra == 'test'", specifier = ">=25.4.1" },
{ name = "google-genai", marker = "extra == 'test'" },
{ name = "griffe", marker = "extra == 'dev'" },
+ { name = "griffe", marker = "extra == 'test'" },
+ { name = "griffe2md", marker = "extra == 'dev'" },
+ { name = "griffe2md", marker = "extra == 'test'" },
{ name = "httpx", marker = "extra == 'async'", specifier = ">=0.27.0,<1.0" },
{ name = "jsonschema", marker = "extra == 'test'", specifier = ">=4.0" },
{ name = "langchain", marker = "extra == 'langchain'", specifier = ">=1.3.9" },
@@ -1255,8 +1312,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -1284,7 +1355,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
@@ -1536,6 +1607,41 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/36/c7/cfc8e811f061c841d7990b0201912c3556bfeb99cdcb7ed24adc8d6f8704/pydantic_core-2.41.5-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:56121965f7a4dc965bff783d70b907ddf3d57f6eba29b6d2e5dabfaf07799c51", size = 2145302, upload-time = "2025-11-04T13:43:46.64Z" },
]
+[[package]]
+name = "pydantic-settings"
+version = "2.15.0"
+source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version < '3.11'",
+]
+dependencies = [
+ { name = "pydantic" },
+ { name = "python-dotenv" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/68/ca/31c57507b13119d7d3cfa1576dad2911a4861e3be07b579395f4e9d393f9/pydantic_settings-2.15.0.tar.gz", hash = "sha256:694b793e84f766ba76a90ebdefc01d0a9a045dab0382bee70393da93712ad117", size = 261253, upload-time = "2026-08-07T09:24:57.419Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/30/a4/2bffa9f8e804325a09867f0e9d30795c80ea9f8d62560bd1b6ad6220eb2f/pydantic_settings-2.15.0-py3-none-any.whl", hash = "sha256:0ba092c291c94baceb5eff768aa0d56400a457585bc0175925a5a5510303da42", size = 69413, upload-time = "2026-08-07T09:24:55.839Z" },
+]
+
+[[package]]
+name = "pydantic-settings"
+version = "2.16.2"
+source = { registry = "https://pypi.org/simple" }
+resolution-markers = [
+ "python_full_version >= '3.11'",
+]
+dependencies = [
+ { name = "pydantic" },
+ { name = "python-dotenv" },
+ { name = "typing-extensions" },
+ { name = "typing-inspection" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d0/31/21d21e0e38a8f5f7a7f0cde22820117b6d17d6bc36f348129527f915d7f4/pydantic_settings-2.16.2.tar.gz", hash = "sha256:3dc08ffabed2bbd5dc2dd55ead7b78b4e4c5cd776aecd04310db5f1224caaf46", size = 309225, upload-time = "2026-10-28T11:14:28.066Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/39/88/4131c51ff87b7cd7f82a1194d0c0a2b7ca68c72d9da04c3b7e69ab91a79f/pydantic_settings-2.16.2-py3-none-any.whl", hash = "sha256:8d523e5c129b097686bde019bd6109bff53f4c8c3f63f1ddf9933ffa42e5ab4f", size = 81994, upload-time = "2026-10-28T11:14:26.716Z" },
+]
+
[[package]]
name = "pygments"
version = "2.20.0"
@@ -1545,6 +1651,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
]
+[[package]]
+name = "python-dateutil"
+version = "2.9.0.post0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
+]
+
[[package]]
name = "python-dotenv"
version = "1.2.4"
@@ -1903,6 +2021,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/b7/b95708304cd49b7b6f82fdd039f1748b66ec2b21d6a45180910802f1abf1/rpds_py-0.30.0-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:ac37f9f516c51e5753f27dfdef11a88330f04de2d564be3991384b2f3535d02e", size = 562191, upload-time = "2025-11-30T20:24:36.853Z" },
]
+[[package]]
+name = "s3transfer"
+version = "0.19.3"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "botocore" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/49/c5/0a5ce655109cb96b8dfad36908a4e108d15f5dc2eff8fbc3146c4312e704/s3transfer-0.19.3.tar.gz", hash = "sha256:8326acc3d056d7f7b8a37110c7d2aea41f67e83f6ae79cd3b5fbcca34c726406", size = 166087, upload-time = "2026-10-19T19:19:49.751Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/e2/a4/88f9e10498759121060b8050a1554753dfc04df39bbbcc7aad9ecc8d9440/s3transfer-0.19.3-py3-none-any.whl", hash = "sha256:24eb7535804306355e31c952a90022bf5b2f9d760f9a11062c7493a217c08553", size = 90252, upload-time = "2026-10-19T19:19:48.309Z" },
+]
+
[[package]]
name = "shellingham"
version = "1.5.4"
@@ -1912,6 +2042,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
]
+[[package]]
+name = "six"
+version = "1.17.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },
+]
+
[[package]]
name = "sniffio"
version = "1.3.1"
diff --git a/examples/example-ai-llamaindex/uv.lock b/examples/example-ai-llamaindex/uv.lock
index 25decdb56..224e5a424 100644
--- a/examples/example-ai-llamaindex/uv.lock
+++ b/examples/example-ai-llamaindex/uv.lock
@@ -1376,7 +1376,7 @@ wheels = [
[[package]]
name = "nltk"
-version = "3.10.3"
+version = "3.10.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "click" },
@@ -1385,9 +1385,9 @@ dependencies = [
{ name = "regex" },
{ name = "tqdm" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/e0/e6/fe51d2bb1a3b446f59c5c8165999a9fee208bc346af90a7cbf7657bc0d75/nltk-3.10.3.tar.gz", hash = "sha256:bb9327a461c3811c2fa4900e03840401f2126adfb30c0072827c433bd2444ea4", size = 5137152, upload-time = "2026-08-12T23:46:37.258Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/3a/cb/bbaa9be58e95d21729c6b9194376610230e0755f6de0bf38b6acc0dce079/nltk-3.10.4.tar.gz", hash = "sha256:44679f4e9220abfd496d2c8cdb22f8425ccbe557604f9aa5cacb1c44003dabc1", size = 4300570, upload-time = "2026-10-21T11:34:35.851Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/b6/6d/ebd2af4640b12168fdf0cb74b6118df2f32a2f62ec7e0c06fbfd80706639/nltk-3.10.3-py3-none-any.whl", hash = "sha256:ff9598a8e20518ee0d557745890cc4435b9578489e2dcbc69c4f81fa060caf7c", size = 1798643, upload-time = "2026-08-12T23:44:13.478Z" },
+ { url = "https://files.pythonhosted.org/packages/a2/04/e7816813e409ca874ba2fcc35455db0e4130b79eb277e1f9edd270ca3c69/nltk-3.10.4-py3-none-any.whl", hash = "sha256:769ba5413f265b7d3e87cd163cc28efa01e29eeef8bb6080bc907949d9fcfb51", size = 1722994, upload-time = "2026-10-21T11:34:27.975Z" },
]
[[package]]
@@ -1826,7 +1826,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.76.0"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -1874,9 +1874,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -1904,7 +1917,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
diff --git a/examples/example-ai-pydantic-ai/uv.lock b/examples/example-ai-pydantic-ai/uv.lock
index 6e0b9ef75..bd65c6af3 100644
--- a/examples/example-ai-pydantic-ai/uv.lock
+++ b/examples/example-ai-pydantic-ai/uv.lock
@@ -321,15 +321,15 @@ wheels = [
[[package]]
name = "authlib"
-version = "1.7.2"
+version = "1.9.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "cryptography" },
{ name = "joserfc" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/36/98/7d93f30d029643c0275dbc0bd6d5a6f670661ee6c9a94d93af7ab4887600/authlib-1.7.2.tar.gz", hash = "sha256:2cea25fefcd4e7173bdf1372c0afc265c8034b23a8cd5dcb6a9164b826c64231", size = 176511, upload-time = "2026-05-06T08:10:23.116Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/c9/dc/087c08741a98d234c9b98beef8a28d3c309f814d14b6156422c5815bf6d6/authlib-1.9.1.tar.gz", hash = "sha256:5c7d9848f47cac340f060f76ae0bc09b59f5c8e89cc1bb032d4370a0c55b5974", size = 182700, upload-time = "2026-10-14T14:17:52.307Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/fb/95/adcb68e20c34162e9135f370d6e31737719c2b6f94bc953fe7ed1f10fe21/authlib-1.7.2-py2.py3-none-any.whl", hash = "sha256:3e1faedc9d87e7d56a164eca3ccb6ace0d61b94abe83e92242f8dc8bba9b4a9f", size = 259548, upload-time = "2026-05-06T08:10:21.436Z" },
+ { url = "https://files.pythonhosted.org/packages/39/44/a46089266de32a0d809023b6bf31b80a1f26a46954446a7ce695a565cbea/authlib-1.9.1-py2.py3-none-any.whl", hash = "sha256:8b9be8b1e5174dcbf5520e984f1a22dc2edae5b6e40a61d4cedbf86b97e9e69b", size = 266042, upload-time = "2026-10-14T14:17:50.695Z" },
]
[[package]]
@@ -880,19 +880,19 @@ wheels = [
[[package]]
name = "fastmcp"
-version = "3.4.2"
+version = "3.4.10"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "fastmcp-slim", extra = ["client", "server"] },
]
-sdist = { url = "https://files.pythonhosted.org/packages/29/18/46beaec18c9f86a599ae3f9cdf6677dd6b50240cfd844d18233710b47f13/fastmcp-3.4.2.tar.gz", hash = "sha256:b468722946fc467c3796a6572f7a14d93d48c014cf8fea12910245220cbbe4e1", size = 28756849, upload-time = "2026-06-06T01:30:35.694Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/7e/ce/b2057fd2d3e453048ffae962c746ef7bcb9cf6700086fb1dfcff8a8ba65d/fastmcp-3.4.10.tar.gz", hash = "sha256:c6474855d6230cce4feb7084d654ba518578b25856c6ef26a2ff2d806ef68969", size = 28866789, upload-time = "2026-10-20T14:49:39.101Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/58/4d/8b1ba42251160e11ca34686344572121432c23a082d56ef6bbdec5888fc1/fastmcp-3.4.2-py3-none-any.whl", hash = "sha256:c87a62b029f0c5400ada85f683629345d2466c39169f0cb853e487b2f7308c08", size = 8018, upload-time = "2026-06-06T01:30:38.118Z" },
+ { url = "https://files.pythonhosted.org/packages/40/c4/72da20dfbfce1c99e3c70bc973e736744daf6d461de138f52f9aaa558959/fastmcp-3.4.10-py3-none-any.whl", hash = "sha256:68f422db0a7c6228142663f17d9f79a5a12a509e1408a8ac207b3e442e166e38", size = 8026, upload-time = "2026-10-20T14:49:37.137Z" },
]
[[package]]
name = "fastmcp-slim"
-version = "3.4.2"
+version = "3.4.10"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "platformdirs" },
@@ -902,9 +902,9 @@ dependencies = [
{ name = "rich" },
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/a3/2e/d627b28b7403ecc526991ef732921b08bde010006e6148635f053fd29f4c/fastmcp_slim-3.4.2.tar.gz", hash = "sha256:290646e0955a516235a317151034559aa48336cb843d3f006131aedad8759bb4", size = 576291, upload-time = "2026-06-06T01:30:12.553Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/98/3b/28be7f0963fee1c848e78898d801e1232dd2e05b6e37026c400a788caa9a/fastmcp_slim-3.4.10.tar.gz", hash = "sha256:d80ae606ead8dfefa1f21b009929824210ea87eb4b422653a1be8dca61797ccd", size = 610326, upload-time = "2026-10-20T14:49:15.096Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/f7/58/22afebf18df7260b09148199cbeb90cdcc4b3a4e1b5d7460e3591c3a7add/fastmcp_slim-3.4.2-py3-none-any.whl", hash = "sha256:bdc72492212681ca502755fa8acc0457f559295da1fc3dfc0599adc1c04b82f3", size = 749195, upload-time = "2026-06-06T01:30:11.22Z" },
+ { url = "https://files.pythonhosted.org/packages/7c/28/1e0681b524191ee170f40e8e800fd3785084e12806fc46675c70d7f8fa43/fastmcp_slim-3.4.10-py3-none-any.whl", hash = "sha256:f388941db8bdf38999e6c9d2536c4cd59a6571908d851cee2d10ee59f4e53532", size = 785895, upload-time = "2026-10-20T14:49:13.466Z" },
]
[package.optional-dependencies]
@@ -1542,14 +1542,14 @@ wheels = [
[[package]]
name = "joserfc"
-version = "1.7.1"
+version = "1.7.6"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "cryptography" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/44/90/25cb27518750218e4f850be63d8bbb2343efaad1c01c3571aaa4b3c33bd7/joserfc-1.7.1.tar.gz", hash = "sha256:77d0b76514879c68c6f433bc5b7357a4ab72008ff1e33d8379fd11d72bd8ca81", size = 233181, upload-time = "2026-06-08T07:21:33.412Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/cd/db/ec5b5fe07a7bda62cd2c2d619daf160eb7442b979c7cd61bbe0262108de9/joserfc-1.7.6.tar.gz", hash = "sha256:fb1cf6d2977318bef976c2ed2ef2167cc5f8ade8fc96f034e38f7abd656907c4", size = 236091, upload-time = "2026-10-18T23:12:18.43Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/b3/00/fa62404c3e347f946faa13aa21085205f9cc06ad17671e37f81a51662ae8/joserfc-1.7.1-py3-none-any.whl", hash = "sha256:b3e3d655612e2e1ef67b2600f2f420e12e537b020208fab1761fad647319c164", size = 70423, upload-time = "2026-06-08T07:21:32.001Z" },
+ { url = "https://files.pythonhosted.org/packages/98/40/63886ba742c6fd9e6dd222e20b8d54012fbc933465350c7747c4ed5b31e4/joserfc-1.7.6-py3-none-any.whl", hash = "sha256:e2d72e3fa937ed8ddd42ad8c1cc337a43e7ffd02efa572a2aa15e2764a05b506", size = 71588, upload-time = "2026-10-18T23:12:17.085Z" },
]
[[package]]
@@ -2111,7 +2111,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.76.0"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -2159,9 +2159,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -2189,7 +2202,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
@@ -2362,11 +2375,11 @@ memory = [
[[package]]
name = "pyasn1"
-version = "0.6.4"
+version = "0.6.5"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a4/9a/23310166d960def5897e91fe20e5b724601b02a22e84ba1f94232c0b7f67/pyasn1-0.6.4.tar.gz", hash = "sha256:9c447d8431c947fe4c8febc4ed9e760bc29011a5b01e5c74b67025bd9fb8ce81", size = 151262, upload-time = "2026-07-09T01:12:33.988Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/88/7e/3c0da41061a2021cac7cd524fd57092adbe5b515e8bf9005702e366802e2/pyasn1-0.6.5.tar.gz", hash = "sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47", size = 155152, upload-time = "2026-10-27T06:32:49.125Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/9a/3b/6163796d69c3977d1e4287bea4a6979161cbbdd170ebb430511e8e1999ce/pyasn1-0.6.4-py3-none-any.whl", hash = "sha256:deda9277cfd454080ec40b207fb6df82206a3a2688735233cdcd8d3d565f088b", size = 84410, upload-time = "2026-07-09T01:12:32.92Z" },
+ { url = "https://files.pythonhosted.org/packages/19/1f/3eefd5c84c35cae44549ce1c7f7e58f7945b34f5a6bce07a135438522073/pyasn1-0.6.5-py3-none-any.whl", hash = "sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587", size = 84807, upload-time = "2026-10-27T06:32:48.045Z" },
]
[[package]]
diff --git a/examples/example-ai-semantic-kernel/uv.lock b/examples/example-ai-semantic-kernel/uv.lock
index b19ee0951..bed187c0a 100644
--- a/examples/example-ai-semantic-kernel/uv.lock
+++ b/examples/example-ai-semantic-kernel/uv.lock
@@ -432,11 +432,11 @@ wheels = [
[[package]]
name = "certifi"
-version = "2026.10.19"
+version = "2026.10.23"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" },
]
[[package]]
@@ -2032,7 +2032,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.75.11"
+version = "7.86.6"
source = { directory = "../../" }
dependencies = [
{ name = "backoff" },
@@ -2080,9 +2080,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -2110,7 +2123,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
diff --git a/openfeature-provider/CHANGELOG.md b/openfeature-provider/CHANGELOG.md
index d665cae6f..9bb007b32 100644
--- a/openfeature-provider/CHANGELOG.md
+++ b/openfeature-provider/CHANGELOG.md
@@ -4,6 +4,102 @@ 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`.
+## 0.1.158 — 2026-11-11
+
+### Patch changes
+
+- Updated dependencies: posthog@7.87.1
+
+## 0.1.157 — 2026-11-11
+
+### Patch changes
+
+- Updated dependencies: posthog@7.87.0
+
+## 0.1.156 — 2026-11-10
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.6
+
+## 0.1.155 — 2026-11-10
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.5
+
+## 0.1.154 — 2026-11-09
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.4
+
+## 0.1.153 — 2026-11-09
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.3
+
+## 0.1.152 — 2026-11-09
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.2
+
+## 0.1.151 — 2026-11-09
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.1
+
+## 0.1.150 — 2026-11-06
+
+### Patch changes
+
+- Updated dependencies: posthog@7.86.0
+
+## 0.1.149 — 2026-11-06
+
+### Patch changes
+
+- Updated dependencies: posthog@7.85.0
+
+## 0.1.148 — 2026-11-06
+
+### Patch changes
+
+- Updated dependencies: posthog@7.84.3
+
+## 0.1.147 — 2026-11-06
+
+### Patch changes
+
+- Updated dependencies: posthog@7.84.2
+
+## 0.1.146 — 2026-11-05
+
+### Patch changes
+
+- Updated dependencies: posthog@7.84.1
+
+## 0.1.145 — 2026-11-05
+
+### Patch changes
+
+- Updated dependencies: posthog@7.84.0
+
+## 0.1.144 — 2026-11-05
+
+### Patch changes
+
+- Updated dependencies: posthog@7.83.3
+
+## 0.1.143 — 2026-11-04
+
+### Patch changes
+
+- Updated dependencies: posthog@7.83.2
+
## 0.1.142 — 2026-11-03
### Patch changes
diff --git a/openfeature-provider/pyproject.toml b/openfeature-provider/pyproject.toml
index 940b97515..6ca561bfa 100644
--- a/openfeature-provider/pyproject.toml
+++ b/openfeature-provider/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "openfeature-provider-posthog"
-version = "0.1.142"
+version = "0.1.158"
description = "Official PostHog provider for the OpenFeature Python SDK."
readme = "README.md"
authors = [{ name = "PostHog", email = "engineering@posthog.com" }]
diff --git a/playgrounds/fastapi-async-client/uv.lock b/playgrounds/fastapi-async-client/uv.lock
index 3548a8c74..cd4842634 100644
--- a/playgrounds/fastapi-async-client/uv.lock
+++ b/playgrounds/fastapi-async-client/uv.lock
@@ -56,11 +56,11 @@ wheels = [
[[package]]
name = "certifi"
-version = "2026.10.19"
+version = "2026.10.23"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
+ { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" },
]
[[package]]
@@ -399,7 +399,7 @@ wheels = [
[[package]]
name = "posthog"
-version = "7.75.4"
+version = "7.86.6"
source = { editable = "../../" }
dependencies = [
{ name = "backoff" },
@@ -446,9 +446,22 @@ requires-dist = [
{ name = "mypy", marker = "extra == 'dev'" },
{ name = "mypy-baseline", marker = "extra == 'dev'" },
{ name = "openai-agents", marker = "extra == 'test'", specifier = ">=0.18" },
+ { name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-exporter-otlp-proto-http", marker = "extra == 'test'", specifier = ">=1.20.0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-aiohttp-client", marker = "extra == 'test'", specifier = ">=0.60b0" },
{ name = "opentelemetry-instrumentation-celery", marker = "extra == 'test'", specifier = ">=0.41b0" },
+ { name = "opentelemetry-instrumentation-django", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-flask", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-httpx", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-requests", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-sqlite3", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'metrics'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-system-metrics", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-instrumentation-wsgi", marker = "extra == 'test'", specifier = ">=0.60b0" },
+ { name = "opentelemetry-sdk", marker = "extra == 'metrics'", specifier = ">=1.39.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'otel'", specifier = ">=1.20.0" },
{ name = "opentelemetry-sdk", marker = "extra == 'test'", specifier = ">=1.20.0" },
{ name = "packaging", marker = "extra == 'dev'" },
@@ -476,7 +489,7 @@ requires-dist = [
{ name = "zstandard", marker = "extra == 'test'", specifier = ">=0.23.0" },
{ name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.23.0" },
]
-provides-extras = ["langchain", "async", "zstd", "otel", "dev", "test"]
+provides-extras = ["langchain", "async", "zstd", "otel", "metrics", "dev", "test"]
[package.metadata.requires-dev]
dev = [{ name = "claude-agent-sdk", specifier = ">=0.1.50" }]
diff --git a/posthog/CHANGELOG.md b/posthog/CHANGELOG.md
index 9d3f8ad37..c554996eb 100644
--- a/posthog/CHANGELOG.md
+++ b/posthog/CHANGELOG.md
@@ -1,5 +1,150 @@
# posthog
+## 7.87.1 — 2026-11-11
+
+### Patch changes
+
+- [c28716c2](https://github.com/posthog/posthog-python/commit/c28716c20d75b4ca5dfe2aaedd4f14ff7086a769) Fix `flag_fallback_cache_url` for Redis URLs with an IPv6 host: the brackets are kept, so the Redis flag cache is no longer disabled. — Thanks @ioannisj!
+
+## 7.87.0 — 2026-11-11
+
+### Minor changes
+
+- [5febfd9b](https://github.com/posthog/posthog-python/commit/5febfd9b13d9d78e2f0cd253356badabf4e51c65) Send `$experiment_exposure` for config version 2 experiment splits, and send the reason code and rule attribution on `$feature_flag_called` for config version 2 flags in place of `$feature_flag_reason`. — Thanks @andehen!
+
+## 7.86.6 — 2026-11-10
+
+### Patch changes
+
+- [4d732304](https://github.com/posthog/posthog-python/commit/4d732304a94f06f12ad61ec538832c9a671ceeb1) The Anthropic wrapper now reports `$ai_reasoning_tokens` from `usage.output_tokens_details.thinking_tokens`, for both regular and streaming responses. — Thanks @pcbeingused333!
+- [1342bb0b](https://github.com/posthog/posthog-python/commit/1342bb0bac0de26c81bcef95206a2a3db36b9025) Treat NaN exception rate-limit settings as invalid numbers so autocapture keeps working and bucket limits remain finite. — Thanks @peterolkhov for your first contribution 🎉!
+- [8c6b328d](https://github.com/posthog/posthog-python/commit/8c6b328d3440409887636ccd96d6e19b9825eb55) Local evaluation of relative date filters now clamps the day after every month or year subtracted, as the SDK spec requires. A `2m` filter evaluated on March 31 resolved to January 31 and now resolves to January 28, and `4y` on February 29 resolves to February 28 of the target year. — Thanks @luantaraschi!
+
+## 7.86.5 — 2026-11-10
+
+### Patch changes
+
+- [53770bc3](https://github.com/posthog/posthog-python/commit/53770bc3a28e3436a75507d533fbde6063595044) Events captured inside a Celery task now carry that task's own `celery_*` properties. Before, a task published from inside another task, such as a child task, a retry or a chord callback, reported the publishing task's `celery_task_name`, `celery_task_id` and `celery_retry_count`. — Thanks @eli-r-ph!
+- [d572d099](https://github.com/posthog/posthog-python/commit/d572d0999ef553ddb5f6a8f36eb6d5e1c7c39b17) `AsyncPosthog` no longer breaks two exception paths that read `enable_exception_autocapture`, a setting `AsyncPosthog` does not have:
+
+ - The LangChain callback handler no longer loses a failed run's `$ai_generation`, `$ai_span` or `$ai_trace` event. LangChain swallowed the error, so the event was never sent. The failed event is now sent without an `$exception`.
+ - `new_context(client=)` no longer raises `AttributeError`. Without `capture_exceptions`, it now leaves exceptions uncaptured; pass `capture_exceptions=True` to capture them. — Thanks @eli-r-ph!
+
+## 7.86.4 — 2026-11-09
+
+### Patch changes
+
+- [2c35f047](https://github.com/posthog/posthog-python/commit/2c35f0472a45b809e7b024a31edf1c85c60a391a) Capture an `$ai_generation` error event when `create(stream=True)` fails before the stream starts (bad key, rate limit, invalid model) in the OpenAI chat, OpenAI Responses, Anthropic and Gemini wrappers, sync and async. Previously only errors raised mid-stream were captured. — Thanks @pcbeingused333!
+
+## 7.86.3 — 2026-11-09
+
+### Patch changes
+
+- [2a2e5788](https://github.com/posthog/posthog-python/commit/2a2e5788b31170a3971359af10a561b128bfea03) An exception passed to `capture_exception` without being raised now gets its synthesized stack in outermost-first order, without the SDK's own capture frames, and with `mechanism.synthetic` set to `true`. — Thanks @luantaraschi!
+
+## 7.86.2 — 2026-11-09
+
+### Patch changes
+
+- [3c398e59](https://github.com/posthog/posthog-python/commit/3c398e597284a7624ee56f589ac070df72600ba7) With `capture_mode="v1"`, capture now retries `404` and `429` responses like `408` and `500`, `502`, `503`, `504`, with the same backoff and `Retry-After` handling. Before, both failed the batch at once. — Thanks @andehen!
+
+## 7.86.1 — 2026-11-09
+
+### Patch changes
+
+- [bf3adb3f](https://github.com/posthog/posthog-python/commit/bf3adb3ff90feb11bd7cc06e655451ef6a526edd) A flag record that the server marks `failed` no longer returns a payload, even when the record still carries `metadata.payload`. A failed flag reads as disabled, so `get_feature_flag_payload()`, `get_feature_flag_result().payload` and a snapshot's `get_flag_payload()` now return `None` for it, and its `$feature_flag_called` events leave out `$feature_flag_payload`. `get_all_flags_and_payloads()` and `get_feature_payloads()` already left it out. This applies to responses from both `/flags?v=4` and older servers. — Thanks @andehen!
+
+## 7.86.0 — 2026-11-06
+
+### Minor changes
+
+- [0aa5df1](https://github.com/posthog/posthog-python/commit/0aa5df18d1c60769de1307677b1e0e649eb023e8) MCP analytics now matches the cross-SDK MCP spec ahead of 1.0:
+
+ - `instrument()` sends `$mcp_unknown_tool` instead of a failed `$mcp_tool_call` and `$exception` when a `tools/call` names a tool your server never registered. Insights that count failed tool calls stop counting these. A call naming no tool sends nothing. A raw low-level server has no registry the SDK can read, so a failed call there stays a failed tool call.
+ - FastMCP's stock logging, timing, error-handling, and similar middleware no longer turns off `llm_model` injection on standalone `fastmcp.FastMCP`.
+ - Manual capture without a `session_id` now sends a fresh `ses_` session id and uses it as the `distinct_id`, instead of no `$session_id` and an `anonymous` person.
+ - Truncated string properties now fit their limit with the `...` marker included, so `$mcp_tool_name` and other names stop at 256 characters instead of 259. — Thanks @lucasheriques!
+- [5f2ee56](https://github.com/posthog/posthog-python/commit/5f2ee56bb0f2b3815e863045c6506a35ae4053b8) `posthog.mcp` is now stable. From this release, a minor or patch release of `posthog` no longer makes breaking changes to the `posthog.mcp` API, renames or removes a `$mcp_*` event or property, changes its type, or changes which requests send an event, so your saved insights keep working across upgrades. New events and properties can still arrive in minor releases. Upgrading needs no code change. — Thanks @lucasheriques!
+
+### Patch changes
+
+- [d8a7ff0](https://github.com/posthog/posthog-python/commit/d8a7ff0efa49eb4cf0be8a1b30c1370d6e322553) On FastMCP 2.x servers with middleware, `posthog.mcp` no longer tries to read the advertised tool schema on each call. FastMCP 2.x can only list tools through request middleware, which can spend rate limits, so the lookup failed and logged an error on every call. Argument names there stay redacted in `$mcp_input_keys`, as before. — Thanks @lucasheriques!
+
+## 7.85.0 — 2026-11-06
+
+### Minor changes
+
+- [778f386](https://github.com/posthog/posthog-python/commit/778f386eaacd1ea9379852c3b032a9f19a6271ea) MCP analytics tool definitions change in three ways:
+
+ - `get_more_tools` and `send_feedback` declare `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint` as `false`, because a call records data in your PostHog project. Their annotations no longer carry a `title`.
+ - The injected `context` argument has a shorter description.
+ - The injected `llm_model` argument is always optional.
+
+ These changes alter your published tool definitions. If your server is listed in the ChatGPT or Claude directories, those platforms may re-review the updated tools. — Thanks @lucasheriques!
+
+## 7.84.3 — 2026-11-06
+
+### Patch changes
+
+- [3f93a34](https://github.com/posthog/posthog-python/commit/3f93a347939779e63f0176bf0a1396b07f98002c) Exclude client-only feature flags from definition-load warnings about experience continuity and unsupported definitions, without changing local evaluation. — Thanks @marandaneto!
+
+## 7.84.2 — 2026-11-06
+
+### Patch changes
+
+- [11585fb](https://github.com/posthog/posthog-python/commit/11585fba6517aa3c33e657e5b94103e65469563e) Stop retrying `/flags` requests when the connection is refused, so the flag error surfaces right away instead of after the retry backoff. — Thanks @luantaraschi!
+
+## 7.84.1 — 2026-11-05
+
+### Patch changes
+
+- [f3116ff](https://github.com/posthog/posthog-python/commit/f3116ffca51ba3dcac8527bb0c50505bab079bdc) Reworded the descriptions of the injected `conversation_id` and `llm_model` arguments and the `get_more_tools` and `send_feedback` virtual tools so they describe the field instead of instructing the model. This changes your published tool definitions; if your server is listed in the ChatGPT or Claude directories, those platforms may re-review the updated tools. — Thanks @lucasheriques!
+
+## 7.84.0 — 2026-11-05
+
+### Minor changes
+
+- [063f1ce](https://github.com/posthog/posthog-python/commit/063f1cece68ee0d6e4d644d4b6fe0fbe335e3b29) `posthog.emails.send()` can now send email content your code rendered, such as HTML from Jinja or React Email. Give the email a `template_key` and a `subject`, and pass `html`, `text` or both.
+
+ ```python
+ posthog = Posthog("phc_...", secret_key="phs_...")
+
+ result = posthog.emails.send(
+ to="user@example.com",
+ distinct_id="user_123",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ )
+
+ # "delivered", "bounced", ...
+ status = posthog.emails.get(result.id).status
+ ```
+
+ You need a project secret API key, the kind that starts with `phs_`. Create one under **Project secret API keys** in your project settings. Set its **Transactional email** scope to Write to send emails, or to Read for a key that only reads statuses. Pass it to the client as `secret_key`. Set `app_host` to your PostHog app URL when you self-host PostHog or send through a reverse proxy.
+
+ PostHog records each email's delivery, opens and clicks on the person with that `distinct_id`. It groups every email with the same `template_key`, so you see their metrics and logs in one place. The SDK retries a request that hits a network error, a rate limit or an outage twice by default. Every send carries an idempotency key, so a retry never sends the email twice. Pass your own `idempotency_key`, such as `welcome:user_123`, and your job runner's retries are safe too.
+
+ A send with your own content also takes `from_`, `reply_to` and `capture_engagement=False`. Set `migrated_from` on the client to tell PostHog which email provider you moved from. A failed call raises an `EmailError` with PostHog's `code` and the HTTP `status_code`.
+
+ Docs: [Send transactional emails with Python](https://posthog.com/docs/workflows/transactional-emails/python) and the [transactional email overview](https://posthog.com/docs/workflows/transactional-emails). — Thanks @Silthus!
+
+### Patch changes
+
+- [b741c65](https://github.com/posthog/posthog-python/commit/b741c65a5cd0e503aaf915e695cdb4d54686d9f9) The LangChain callback handler no longer reports too few input tokens for a non-streamed `ChatAnthropic` call that reads or writes the prompt cache. It took the raw Anthropic usage from `response_metadata`, whose input tokens already exclude the cache, and subtracted the cache tokens again, so a cached call usually reported 0 input tokens. It now reads LangChain's standard `usage_metadata` first, as it already did for streamed calls. — Thanks @jaeminbird for your first contribution 🎉!
+
+## 7.83.3 — 2026-11-05
+
+### Patch changes
+
+- [7cd0d8a](https://github.com/posthog/posthog-python/commit/7cd0d8a4a9cadafc92bc479c4ec209436476132c) Streaming Gemini calls that fail now record the HTTP status of the google-genai error (for example 429 or 503) in `$ai_http_status`. Before, `capture_streaming_event` read only `status_code`, so these events were captured with a status of 0. — Thanks @pcbeingused333!
+
+## 7.83.2 — 2026-11-04
+
+### Patch changes
+
+- [ae2dcf2](https://github.com/posthog/posthog-python/commit/ae2dcf2eaa76fa2693ed8ebe19bbf22054661acb) Local evaluation now respects early access feature enrollment. A flag with feature enrollment uses the `$feature_enrollment/` person property when you pass it, and otherwise falls back to the flags service. Before, it returned `False` for enrolled people who matched no release condition, while the flags service returned `True`. — Thanks @puemos for your first contribution 🎉!
+
## 7.83.1 — 2026-11-03
### Patch changes
diff --git a/posthog/__init__.py b/posthog/__init__.py
index 22667f3f2..00d1f0af4 100644
--- a/posthog/__init__.py
+++ b/posthog/__init__.py
@@ -551,7 +551,7 @@ def capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]:
Examples:
```python
# Context and capture usage
- from posthog import new_context, identify_context, tag_context, capture
+ from posthog import new_context, identify_context, tag, capture
# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)
with new_context():
# Associate this context with some user, by distinct_id
@@ -572,7 +572,7 @@ def capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]:
capture('purchase', groups={'company': 'id:5'})
# Adding a tag to the current context will cause it to appear on all subsequent events
- tag_context('some-tag', 'some-value')
+ tag('some-tag', 'some-value')
capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict
```
diff --git a/posthog/ai/anthropic/_anthropic_stream.py b/posthog/ai/anthropic/_anthropic_stream.py
index 2df160ef8..7c76cc369 100644
--- a/posthog/ai/anthropic/_anthropic_stream.py
+++ b/posthog/ai/anthropic/_anthropic_stream.py
@@ -62,6 +62,12 @@ def consume(self, event: Any) -> None:
# (server tools can emit several in one stream). Keep the
# latest total; a field the event omits leaves the prior one.
self.usage_stats["output_tokens"] = output_tokens
+ # thinking tokens on a message_delta are cumulative as well
+ thinking_tokens = extract_anthropic_usage_from_event(event).get(
+ "reasoning_tokens"
+ )
+ if thinking_tokens is not None:
+ self.usage_stats["reasoning_tokens"] = thinking_tokens
if getattr(event, "type", None) == "content_block_start":
block, tool = handle_anthropic_content_block_start(event)
diff --git a/posthog/ai/anthropic/anthropic.py b/posthog/ai/anthropic/anthropic.py
index 8bfc53438..27399d516 100644
--- a/posthog/ai/anthropic/anthropic.py
+++ b/posthog/ai/anthropic/anthropic.py
@@ -6,6 +6,7 @@
"Please install the Anthropic SDK to use this feature: 'pip install anthropic'"
)
+import logging
import time
import uuid
from typing import Any, Dict, List, Optional
@@ -31,6 +32,8 @@
)
from posthog.client import Client as PostHogClient
+_log = logging.getLogger("posthog")
+
class Anthropic(anthropic.Anthropic):
"""
@@ -176,7 +179,28 @@ def _create_streaming(
**kwargs: Any,
):
start_time = time.time()
- response = super().create(**kwargs)
+ try:
+ response = super().create(**kwargs)
+ except Exception as exc:
+ accumulator = _AnthropicStreamAccumulator()
+ try:
+ self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ accumulator.usage_stats,
+ time.time() - start_time,
+ accumulator.content_blocks,
+ accumulator.accumulated_content,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
return self._track_streaming_response(
response,
posthog_distinct_id,
diff --git a/posthog/ai/anthropic/anthropic_async.py b/posthog/ai/anthropic/anthropic_async.py
index 6e63852b0..473a39acc 100644
--- a/posthog/ai/anthropic/anthropic_async.py
+++ b/posthog/ai/anthropic/anthropic_async.py
@@ -6,6 +6,7 @@
"Please install the Anthropic SDK to use this feature: 'pip install anthropic'"
)
+import logging
import time
import uuid
from typing import Any, Dict, List, Optional
@@ -31,6 +32,8 @@
)
from posthog.client import Client as PostHogClient
+_log = logging.getLogger("posthog")
+
class AsyncAnthropic(anthropic.AsyncAnthropic):
"""
@@ -176,7 +179,28 @@ async def _create_streaming(
**kwargs: Any,
):
start_time = time.time()
- response = await super().create(**kwargs)
+ try:
+ response = await super().create(**kwargs)
+ except Exception as exc:
+ accumulator = _AnthropicStreamAccumulator()
+ try:
+ await self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ accumulator.usage_stats,
+ time.time() - start_time,
+ accumulator.content_blocks,
+ accumulator.accumulated_content,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
return self._track_streaming_response(
response,
posthog_distinct_id,
diff --git a/posthog/ai/anthropic/anthropic_converter.py b/posthog/ai/anthropic/anthropic_converter.py
index 1e476c5c5..1ee525e72 100644
--- a/posthog/ai/anthropic/anthropic_converter.py
+++ b/posthog/ai/anthropic/anthropic_converter.py
@@ -242,6 +242,15 @@ def extract_anthropic_stop_reason(response: Any) -> Optional[str]:
return getattr(response, "stop_reason", None)
+def _extract_thinking_tokens(usage: Any) -> int:
+ """Return usage.output_tokens_details.thinking_tokens (0 if absent or null)."""
+ details = getattr(usage, "output_tokens_details", None)
+ thinking = getattr(details, "thinking_tokens", None)
+ if isinstance(thinking, int) and not isinstance(thinking, bool):
+ return thinking
+ return 0
+
+
def extract_anthropic_usage_from_response(response: Any) -> TokenUsage:
"""
Extract usage from a full Anthropic response (non-streaming).
@@ -273,6 +282,10 @@ def extract_anthropic_usage_from_response(response: Any) -> TokenUsage:
if cache_creation and cache_creation > 0:
result["cache_creation_input_tokens"] = cache_creation
+ thinking_tokens = _extract_thinking_tokens(response.usage)
+ if thinking_tokens > 0:
+ result["reasoning_tokens"] = thinking_tokens
+
web_search_count = extract_anthropic_web_search_count(response)
if web_search_count > 0:
result["web_search_count"] = web_search_count
@@ -319,6 +332,10 @@ def extract_anthropic_usage_from_event(event: Any) -> TokenUsage:
if hasattr(event, "usage") and event.usage:
usage["output_tokens"] = getattr(event.usage, "output_tokens", 0)
+ thinking_tokens = _extract_thinking_tokens(event.usage)
+ if thinking_tokens > 0:
+ usage["reasoning_tokens"] = thinking_tokens
+
# Extract web search count from usage
if hasattr(event.usage, "server_tool_use"):
server_tool_use = event.usage.server_tool_use
diff --git a/posthog/ai/gemini/gemini.py b/posthog/ai/gemini/gemini.py
index 9ae6be168..9e17c017a 100644
--- a/posthog/ai/gemini/gemini.py
+++ b/posthog/ai/gemini/gemini.py
@@ -1,3 +1,4 @@
+import logging
import time
from typing import Any, Dict, Optional
@@ -29,6 +30,8 @@
format_gemini_streaming_output as format_gemini_streaming_output,
)
+_log = logging.getLogger("posthog")
+
class Client:
"""
@@ -274,11 +277,36 @@ def _generate_content_streaming(
):
start_time = time.time()
usage_stats: TokenUsage = TokenUsage()
- accumulated_content = []
+ accumulated_content: list[Any] = []
stop_reason: Optional[str] = None
kwargs_without_stream = {"model": model, "contents": contents, **kwargs}
- response = self._client.models.generate_content_stream(**kwargs_without_stream)
+ try:
+ response = self._client.models.generate_content_stream(
+ **kwargs_without_stream
+ )
+ except Exception as exc:
+ try:
+ self._capture_streaming_event(
+ model,
+ contents,
+ distinct_id,
+ trace_id,
+ properties,
+ privacy_mode,
+ groups,
+ kwargs,
+ usage_stats,
+ time.time() - start_time,
+ accumulated_content,
+ stop_reason=stop_reason,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
def generator():
nonlocal usage_stats
diff --git a/posthog/ai/gemini/gemini_async.py b/posthog/ai/gemini/gemini_async.py
index 0a5566d98..cd143ec3e 100644
--- a/posthog/ai/gemini/gemini_async.py
+++ b/posthog/ai/gemini/gemini_async.py
@@ -1,3 +1,4 @@
+import logging
import time
from typing import Any, Dict, Optional
@@ -29,6 +30,8 @@
format_gemini_streaming_output as format_gemini_streaming_output,
)
+_log = logging.getLogger("posthog")
+
class AsyncClient:
"""
@@ -257,13 +260,36 @@ async def _generate_content_streaming(
):
start_time = time.time()
usage_stats: TokenUsage = TokenUsage()
- accumulated_content = []
+ accumulated_content: list[Any] = []
stop_reason: Optional[str] = None
kwargs_without_stream = {"model": model, "contents": contents, **kwargs}
- response = await self._client.aio.models.generate_content_stream(
- **kwargs_without_stream
- )
+ try:
+ response = await self._client.aio.models.generate_content_stream(
+ **kwargs_without_stream
+ )
+ except Exception as exc:
+ try:
+ self._capture_streaming_event(
+ model,
+ contents,
+ distinct_id,
+ trace_id,
+ properties,
+ privacy_mode,
+ groups,
+ kwargs,
+ usage_stats,
+ time.time() - start_time,
+ accumulated_content,
+ stop_reason=stop_reason,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
async def async_generator():
nonlocal usage_stats
diff --git a/posthog/ai/langchain/callbacks.py b/posthog/ai/langchain/callbacks.py
index 57d2daeb4..62ce088fe 100644
--- a/posthog/ai/langchain/callbacks.py
+++ b/posthog/ai/langchain/callbacks.py
@@ -610,9 +610,9 @@ def _capture_exception_and_update_properties(
options: Dict[str, Any],
) -> Dict[str, Any]:
# An `$exception` event carries the message and stack, which echo prompts and output.
- if not self._ph_client.enable_exception_autocapture or _privacy_mode_enabled(
- self._ph_client, self._privacy_mode
- ):
+ if not getattr(
+ self._ph_client, "enable_exception_autocapture", False
+ ) or _privacy_mode_enabled(self._ph_client, self._privacy_mode):
return event_properties
exception_options = dict(options)
@@ -994,11 +994,12 @@ def _parse_usage_model(
# Both cache_read and cache_write tokens should be subtracted since Anthropic's raw API
# reports input_tokens as tokens NOT read from or used to create a cache.
# For other providers (OpenAI, etc.), input_tokens already excludes cache tokens as expected.
- # Match logic consistent with plugin-server: exact match on provider OR substring match on model
+ # Match logic consistent with plugin-server: exact match on provider, substring
+ # match on model, or a Claude model under another provider (e.g. Vertex AI)
is_anthropic = False
if provider and provider.lower() == "anthropic":
is_anthropic = True
- elif model and "anthropic" in model.lower():
+ elif model and ("anthropic" in model.lower() or model.lower().startswith("claude")):
is_anthropic = True
if is_anthropic and normalized_usage.input_tokens:
@@ -1072,12 +1073,15 @@ def _parse_usage(
if isinstance(response_metadata, dict)
else None
)
- ollama_usage = getattr(
- message_chunk, "usage_metadata", None
- ) # for Ollama
+ # LangChain's standard usage, which also covers Ollama
+ usage_metadata = getattr(message_chunk, "usage_metadata", None)
+ # Prefer the standard usage: its input_tokens include cache reads
+ # and writes, as the Anthropic subtraction in _parse_usage_model
+ # expects. ChatAnthropic also copies the raw API usage, whose
+ # input_tokens already exclude the cache, into response_metadata.
chunk_usage = (
- bedrock_anthropic_usage or bedrock_titan_usage or ollama_usage
+ usage_metadata or bedrock_anthropic_usage or bedrock_titan_usage
)
if chunk_usage:
llm_usage = _parse_usage_model(chunk_usage, provider, model)
diff --git a/posthog/ai/openai/openai.py b/posthog/ai/openai/openai.py
index 420a0ed55..872da2316 100644
--- a/posthog/ai/openai/openai.py
+++ b/posthog/ai/openai/openai.py
@@ -1,3 +1,4 @@
+import logging
import time
import uuid
from typing import TYPE_CHECKING as _TYPE_CHECKING, Any, Dict, Optional
@@ -41,6 +42,8 @@
merge_provider_override,
)
+_log = logging.getLogger("posthog")
+
class OpenAI(openai.OpenAI):
"""
@@ -177,7 +180,26 @@ def _create_streaming(
):
start_time = time.time()
state = _ResponsesStreamState()
- response = self._original.create(**kwargs)
+ try:
+ response = self._original.create(**kwargs)
+ except Exception as exc:
+ try:
+ self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ state,
+ time.time() - start_time,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
def generator():
stream_error: Optional[BaseException] = None
@@ -428,7 +450,26 @@ def _create_streaming(
**(stream_options if isinstance(stream_options, dict) else {}),
"include_usage": True,
}
- response = self._original.create(**kwargs)
+ try:
+ response = self._original.create(**kwargs)
+ except Exception as exc:
+ try:
+ self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ state,
+ time.time() - start_time,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
def generator():
stream_error: Optional[BaseException] = None
diff --git a/posthog/ai/openai/openai_async.py b/posthog/ai/openai/openai_async.py
index 1f3fa4ca5..9b08ccd62 100644
--- a/posthog/ai/openai/openai_async.py
+++ b/posthog/ai/openai/openai_async.py
@@ -1,3 +1,4 @@
+import logging
import time
import uuid
from typing import TYPE_CHECKING as _TYPE_CHECKING, Any, Dict, Optional
@@ -42,6 +43,8 @@
merge_provider_override,
)
+_log = logging.getLogger("posthog")
+
class AsyncOpenAI(openai.AsyncOpenAI):
"""
@@ -178,7 +181,26 @@ async def _create_streaming(
):
start_time = time.time()
state = _ResponsesStreamState()
- response = await self._original.create(**kwargs)
+ try:
+ response = await self._original.create(**kwargs)
+ except Exception as exc:
+ try:
+ await self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ state,
+ time.time() - start_time,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
async def async_generator():
stream_error: Optional[BaseException] = None
@@ -432,7 +454,26 @@ async def _create_streaming(
**(stream_options if isinstance(stream_options, dict) else {}),
"include_usage": True,
}
- response = await self._original.create(**kwargs)
+ try:
+ response = await self._original.create(**kwargs)
+ except Exception as exc:
+ try:
+ await self._capture_streaming_event(
+ posthog_distinct_id,
+ posthog_trace_id,
+ posthog_properties,
+ posthog_privacy_mode,
+ posthog_groups,
+ kwargs,
+ state,
+ time.time() - start_time,
+ error=exc,
+ )
+ except Exception:
+ # Telemetry must never replace the provider's own error, and the
+ # fixed text avoids echoing prompt or error content into logs.
+ _log.warning("[PostHog] Failed to capture streaming connect error")
+ raise
async def async_generator():
stream_error: Optional[BaseException] = None
diff --git a/posthog/ai/utils.py b/posthog/ai/utils.py
index a832cd679..efc987c78 100644
--- a/posthog/ai/utils.py
+++ b/posthog/ai/utils.py
@@ -1163,9 +1163,7 @@ def capture_streaming_event(
event_data["privacy_mode"],
finalize_ai_content(event_data["formatted_output"], ph_client),
),
- "$ai_http_status": (
- getattr(error, "status_code", 0) if error is not None else 200
- ),
+ "$ai_http_status": (_get_http_status(error) if error is not None else 200),
**({"$ai_input_tokens": input_tokens} if input_tokens is not None else {}),
**({"$ai_output_tokens": output_tokens} if output_tokens is not None else {}),
"$ai_latency": event_data["latency"],
@@ -1216,6 +1214,9 @@ def capture_streaming_event(
cache_creation = event_data["usage_stats"].get("cache_creation_input_tokens", 0)
event_properties["$ai_cache_read_input_tokens"] = cache_read
event_properties["$ai_cache_creation_input_tokens"] = cache_creation
+ reasoning = event_data["usage_stats"].get("reasoning_tokens")
+ if isinstance(reasoning, int) and reasoning > 0:
+ event_properties["$ai_reasoning_tokens"] = reasoning
else:
optional_token_fields = [
"cache_read_input_tokens",
diff --git a/posthog/args.py b/posthog/args.py
index 9822c333f..8b63430ed 100644
--- a/posthog/args.py
+++ b/posthog/args.py
@@ -5,6 +5,9 @@
Any,
Dict,
FrozenSet,
+ List,
+ Mapping,
+ NamedTuple,
Union,
Tuple,
Type,
@@ -72,6 +75,27 @@ class OptionalCaptureArgs(TypedDict):
_capture_trace_context: NotRequired[
bool
] # Internal: add the active OpenTelemetry span's ids even when capture_trace_context is off. Used by capture_exception.
+ _pinned_properties: NotRequired[
+ Optional["_PinnedProperties"]
+ ] # Internal: properties fixed after super properties are merged. Used by config version 2 flag events.
+ _before_send_drops: NotRequired[
+ Optional[List[str]]
+ ] # Internal: gets the event name when before_send drops the event. Used by flag event dedupe.
+
+
+class _PinnedProperties(NamedTuple):
+ """Internal: event properties that super properties cannot change.
+
+ Applied to the fully-enriched properties, after super properties are merged and
+ before any allowlist: ``removed`` names are dropped, then ``values`` are set.
+ """
+
+ removed: FrozenSet[str]
+ values: Mapping[str, Any]
+
+ def apply(self, properties: Dict[str, Any]) -> Dict[str, Any]:
+ kept = {k: v for k, v in properties.items() if k not in self.removed}
+ return {**kept, **self.values}
class OptionalSetArgs(TypedDict):
diff --git a/posthog/async_client.py b/posthog/async_client.py
index 2840e2b84..5914a1720 100644
--- a/posthog/async_client.py
+++ b/posthog/async_client.py
@@ -32,7 +32,13 @@
async_flags as _async_flags,
async_remote_config as _async_remote_config,
)
-from .args import ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
+from .args import (
+ ID_TYPES,
+ ExceptionArg,
+ OptionalCaptureArgs,
+ OptionalSetArgs,
+ _PinnedProperties,
+)
from .capture_compression import (
CaptureCompression,
_resolve_capture_ai_compression,
@@ -49,9 +55,9 @@
from .capture_send import _CAPTURE_AI_V1_PATH, _CAPTURE_V1_PATH
from .client import (
MAX_DICT_SIZE as _MAX_DICT_SIZE,
- _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES,
Client as _SyncClient,
_add_context_session_id,
+ _capture_flag_events,
_context_tag_defaults,
_explicit_distinct_id,
_group_identify_distinct_id,
@@ -97,6 +103,7 @@
)
from .release_id import _resolve_release_id
from .request import QuotaLimitError, determine_server_host, normalize_host
+from .types import FeatureFlag as _FeatureFlag
from .types import (
FlagValue,
_has_untyped_flag_records,
@@ -179,6 +186,7 @@ def __init__(
app_host: Optional[str] = None,
email_request_timeout_seconds: float = 15,
email_request_max_retries: int = 2,
+ migrated_from: Optional[str] = None,
) -> None:
if flush_at <= 0:
raise ValueError("flush_at must be greater than zero")
@@ -239,10 +247,13 @@ def __init__(
else resolved_secret_key
) or None
self.personal_api_key = self.secret_key
- _validate_options(email_request_timeout_seconds, email_request_max_retries)
+ _validate_options(
+ email_request_timeout_seconds, email_request_max_retries, migrated_from
+ )
self.app_host = app_host
self.email_request_timeout_seconds = email_request_timeout_seconds
self.email_request_max_retries = email_request_max_retries
+ self.migrated_from = migrated_from
self.feature_flags_request_timeout_seconds = (
feature_flags_request_timeout_seconds
)
@@ -250,6 +261,9 @@ def __init__(
0, feature_flags_request_max_retries
)
self.distinct_ids_feature_flags_reported = SizeLimitedDict(_MAX_DICT_SIZE, set)
+ # $experiment_exposure dedupe, kept apart from $feature_flag_called's so that a
+ # reported call never suppresses its exposure. Same bound and eviction.
+ self._experiment_exposures_reported = SizeLimitedDict(_MAX_DICT_SIZE, set)
self._feature_flag_evaluations_host_cache: Optional[
_FeatureFlagEvaluationsHost
] = None
@@ -346,10 +360,10 @@ def __init__(
@property
def emails(self) -> AsyncEmails:
"""
- Send transactional email from PostHog email templates, and read the
- status of each email sent with ``get``.
+ 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 the ``hog_flow:write``
+ Needs ``secret_key``, a project secret API key with the ``transactional_email:write``
scope, and ``posthog[async]``. Sends go to ``app_host``, or to the PostHog
Cloud app host of ``host``. ``email_request_timeout_seconds`` and
``email_request_max_retries`` configure each send. A disabled or shut-down
@@ -374,6 +388,7 @@ def emails(self) -> AsyncEmails:
app_host=self.app_host,
timeout=self.email_request_timeout_seconds,
max_retries=self.email_request_max_retries,
+ migrated_from=self.migrated_from,
)
return self._emails
@@ -533,6 +548,7 @@ def _prepare_event(
self,
msg: dict[str, Any],
property_allowlist=None,
+ pinned_properties=None,
) -> tuple[Optional[dict[str, Any]], Optional[str]]:
if self.disabled or not self._accepting:
return None, None
@@ -608,6 +624,7 @@ def _event_defaults(
system_properties: Optional[dict[str, Any]] = None,
flag_properties: Optional[dict[str, Any]] = None,
trace_properties: Optional[dict[str, Any]] = None,
+ pinned_properties: Optional[_PinnedProperties] = None,
) -> _EventDefaults:
return _build_event_defaults(
super_properties=self.super_properties,
@@ -625,6 +642,7 @@ def _event_defaults(
trace_properties=trace_properties,
library_id="posthog-python",
library_version=VERSION,
+ pinned_properties=pinned_properties,
)
def _build_capture_event(
@@ -669,6 +687,7 @@ def _build_capture_event(
disable_geoip=kwargs.get("disable_geoip"),
system_properties=system_context(),
flag_properties=flag_properties,
+ pinned_properties=kwargs.get("_pinned_properties"),
trace_properties=(
_get_current_otel_span_properties()
if self.capture_trace_context
@@ -1265,38 +1284,29 @@ def _capture_feature_flag_called_if_needed(
disable_geoip: Optional[bool] = None,
has_experiment: Optional[bool] = None,
minimal_flag_called_events: bool = False,
+ details: Optional[_FeatureFlag] = None,
+ value_from_details: bool = False,
) -> None:
- groups_key = (
- tuple(sorted((str(k), str(v)) for k, v in groups.items())) if groups else ()
- )
- reported_key = (key, response, groups_key)
- reported_flags = self.distinct_ids_feature_flags_reported.get(distinct_id)
- if reported_flags is None:
- reported_flags = set()
- self.distinct_ids_feature_flags_reported[distinct_id] = reported_flags
- if reported_key in reported_flags:
- return
-
- if has_experiment is not None:
- properties["$feature_flag_has_experiment"] = has_experiment
- capture_kwargs: dict[str, Any] = {}
- if minimal_flag_called_events and has_experiment is False:
- capture_kwargs["_property_allowlist"] = (
- _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
- )
capture_groups = {
str(group_type): _stringify_id(group_key)
for group_type, group_key in (groups or {}).items()
}
- self.capture(
- "$feature_flag_called",
+ _capture_flag_events(
+ self.capture,
+ self.distinct_ids_feature_flags_reported,
+ self._experiment_exposures_reported,
distinct_id=distinct_id,
+ key=key,
+ response=response,
properties=properties,
- groups=capture_groups,
+ groups=groups,
+ capture_groups=capture_groups,
disable_geoip=disable_geoip,
- **capture_kwargs,
+ has_experiment=has_experiment,
+ minimal_flag_called_events=minimal_flag_called_events,
+ details=details,
+ value_from_details=value_from_details,
)
- reported_flags.add(reported_key)
def _pending_queue_items(self) -> int:
return sum(lane.pending_items() for lane in self._lanes)
@@ -1470,6 +1480,7 @@ async def shutdown(self) -> None:
errors.append(error)
self.distinct_ids_feature_flags_reported.clear()
+ self._experiment_exposures_reported.clear()
self._closed = True
if errors and self.debug:
raise errors[0]
diff --git a/posthog/bucketed_rate_limiter.py b/posthog/bucketed_rate_limiter.py
index 7cf24be90..0bd7549cc 100644
--- a/posthog/bucketed_rate_limiter.py
+++ b/posthog/bucketed_rate_limiter.py
@@ -3,6 +3,7 @@
# Kept behaviorally identical so rate limiting is consistent across SDKs.
import logging
+import math
import threading
import time
from typing import Callable, Dict, Hashable, Optional, Union
@@ -15,7 +16,11 @@
def _clamp_to_range(value, min_value: Number, max_value: Number, label: str) -> Number:
- if isinstance(value, bool) or not isinstance(value, (int, float)):
+ if (
+ isinstance(value, bool)
+ or not isinstance(value, (int, float))
+ or (isinstance(value, float) and math.isnan(value))
+ ):
log.warning(f"{label} must be a number. Using max value {max_value}.")
return max_value
if value > max_value:
diff --git a/posthog/capture_compression.py b/posthog/capture_compression.py
index 257c80c88..08db9e994 100644
--- a/posthog/capture_compression.py
+++ b/posthog/capture_compression.py
@@ -29,6 +29,12 @@ class CaptureCompression(str, Enum):
server decodes (``br`` is accepted by the server too but is intentionally
left out for now). Inheriting from ``str`` keeps the members comparable to
and serializable as their token values.
+
+ Values:
+ NONE: Sends the body uncompressed.
+ GZIP: gzip, from the standard library.
+ DEFLATE: zlib (RFC 1950), from the standard library.
+ ZSTD: Faster and smaller, but needs ``pip install posthog[zstd]``.
"""
NONE = "none"
diff --git a/posthog/capture_event.py b/posthog/capture_event.py
index 42da0e554..ddd8b38c6 100644
--- a/posthog/capture_event.py
+++ b/posthog/capture_event.py
@@ -25,12 +25,15 @@
from collections.abc import Collection, Mapping
from dataclasses import dataclass
from datetime import datetime, timezone
-from typing import Any, Optional
+from typing import TYPE_CHECKING, Any, Optional
from uuid import UUID
from posthog.utils import _normalize_timestamp, _rfc3339_timestamp, _uuid7
from posthog.utils import clean as _clean
+if TYPE_CHECKING:
+ from posthog.args import _PinnedProperties
+
log = logging.getLogger("posthog")
# Sentinel properties lifted to top-level string fields on the event.
@@ -137,6 +140,7 @@ class _EventDefaults:
property_allowlist: Optional[Collection[str]] = None
trace_properties: Optional[Mapping[str, Any]] = None
library: Optional[tuple[str, str]] = None
+ pinned_properties: Optional["_PinnedProperties"] = None
def _is_library_value(value: Any) -> bool:
@@ -161,6 +165,7 @@ def _build_event_defaults(
trace_properties: Optional[Mapping[str, Any]] = None,
library_id: str,
library_version: str,
+ pinned_properties: Optional["_PinnedProperties"] = None,
) -> _EventDefaults:
"""Order the layers: per-call arguments, context, global, then SDK values.
@@ -173,6 +178,8 @@ def _build_event_defaults(
active OpenTelemetry span) are SDK values that fill as a pair.
``library_id`` and ``library_version`` are the SDK's own ``$lib`` and
``$lib_version``. They fill as a pair below every other layer.
+ ``pinned_properties`` is config version 2 flag attribution that no layer
+ may change or add to; it applies after every layer.
"""
call_properties = (
{} if call_disable_geoip is None else {"$geoip_disable": call_disable_geoip}
@@ -201,6 +208,7 @@ def _build_event_defaults(
property_allowlist=property_allowlist,
trace_properties=trace_properties,
library=(library_id, library_version),
+ pinned_properties=pinned_properties,
)
@@ -251,6 +259,13 @@ def _fill_event_defaults(
properties[key] = _clean(value)
if defaults.library is not None:
_fill_library(properties, defaults.library, allowlist)
+ if defaults.pinned_properties is not None:
+ # After every layer, so a context tag or super property never changes
+ # or adds config version 2 flag attribution. The allowlist still wins.
+ properties = defaults.pinned_properties.apply(properties)
+ if allowlist is not None:
+ properties = {k: v for k, v in properties.items() if k in allowlist}
+ msg["properties"] = properties
options = _event_options(msg.get("options"))
for option_layer in defaults.option_layers:
for key, value in option_layer.items():
diff --git a/posthog/client.py b/posthog/client.py
index b775b0d79..fb3e1bce0 100644
--- a/posthog/client.py
+++ b/posthog/client.py
@@ -6,6 +6,7 @@
import logging
import math
import os
+import re
import sys
import threading
import time
@@ -13,14 +14,33 @@
import weakref
from contextvars import ContextVar
from datetime import datetime, timedelta, timezone
-from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union, cast
+from typing import (
+ Any,
+ Callable,
+ Dict,
+ FrozenSet,
+ List,
+ Mapping,
+ NamedTuple,
+ Optional,
+ Set,
+ Tuple,
+ Union,
+ cast,
+)
from uuid import UUID, uuid4
from typing_extensions import Unpack
from posthog._async_utils import _BackgroundEventLoopRunner
from posthog._disabled_lane_queue import _DisabledLaneQueue
-from posthog.args import ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
+from posthog.args import (
+ ID_TYPES,
+ ExceptionArg,
+ OptionalCaptureArgs,
+ OptionalSetArgs,
+ _PinnedProperties,
+)
from posthog.metrics_capture import (
_DEFAULT_FLUSH_INTERVAL_SECONDS,
PostHogMetrics,
@@ -420,6 +440,20 @@ def wrapper(self, *args, **kwargs):
}
)
+# A config version 2 event also keeps its attribution when minimized. Only those
+# events use this wider allowlist, so a config version 1 event is trimmed as before,
+# even when super properties happen to use these names.
+_MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES: frozenset[str] = (
+ _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
+ | {
+ "$feature_flag_config_version",
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_id",
+ "$feature_flag_rule_type",
+ "$feature_flag_variant_key",
+ }
+)
+
def _parse_has_experiment(value: Any) -> Optional[bool]:
"""Server-reported experiment linkage; anything but an explicit bool means unknown."""
@@ -432,6 +466,401 @@ def _metadata_has_experiment(metadata: Any) -> Optional[bool]:
return metadata.has_experiment if isinstance(metadata, FlagMetadata) else None
+# The reason code and rule type of the one outcome that sends ``$experiment_exposure``:
+# a variant assigned by an experiment rule.
+_EXPERIMENT_SPLIT_REASON = "experiment_split"
+_EXPERIMENT_RULE_TYPE = "experiment"
+
+# The reason codes of a config version 2 record that report the rule that produced
+# the result, and the rule types each one allows. Any other reason code, and any
+# failed record, reports no rule, even if the record names one.
+_RULE_TYPES_BY_REASON_CODE: Dict[str, FrozenSet[str]] = {
+ "targeting_match": frozenset({"targeted_release", "percentage_rollout"}),
+ _EXPERIMENT_SPLIT_REASON: frozenset({_EXPERIMENT_RULE_TYPE}),
+ "rollout_miss": frozenset({"percentage_rollout", _EXPERIMENT_RULE_TYPE}),
+ "experiment_paused": frozenset({_EXPERIMENT_RULE_TYPE}),
+ "holdout": frozenset({_EXPERIMENT_RULE_TYPE}),
+}
+
+# Properties a super property must not add to, or change on, a config version 2
+# ``$feature_flag_called``: the attribution, which is set again from the record
+# after super properties are merged, and the fields such an event never carries.
+# The flag identity of the read is set again with the attribution.
+_V2_FLAG_CALLED_PINNED = frozenset(
+ {
+ "$feature_flag_config_version",
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_id",
+ "$feature_flag_rule_type",
+ "$feature_flag_variant_key",
+ "$feature_flag_reason",
+ "$feature_flag_forced_variant",
+ "$feature_flag_experiment_id",
+ }
+)
+
+# Properties an ``$experiment_exposure`` never carries, even from a super property.
+_EXPOSURE_FORBIDDEN = frozenset(
+ {
+ "$feature_flag_config_version",
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$experiment_exposure_source",
+ "$feature_flag_experiment_id",
+ "$feature_flag_forced_variant",
+ }
+)
+
+# ``$experiment_exposure`` copies these from the ``$feature_flag_called`` of the same
+# read, when it has them.
+_EXPOSURE_PROPERTIES_FROM_FLAG_CALLED = (
+ "$feature_flag_id",
+ "$feature_flag_version",
+ "$feature_flag_request_id",
+ "$feature_flag_evaluated_at",
+)
+
+
+def _v4_field(record: Any, name: str) -> Any:
+ """Read a ``/flags?v=4`` field of a parsed flag record or its metadata, such as
+ ``failed`` or ``config_version``.
+
+ These fields stay private, as ``_failed``, ``_config_version`` and so on, until
+ the typed flag accessors make them public under their wire names. Either spelling
+ is read, so the two changes can land in either order.
+ """
+ return getattr(record, name, getattr(record, f"_{name}", None))
+
+
+# The rule ID's wire format: a hyphenated UUID, as the contract's event schemas
+# require.
+_UUID_PATTERN = re.compile(
+ r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
+)
+
+
+def _is_uuid(value: Any) -> bool:
+ return isinstance(value, str) and _UUID_PATTERN.fullmatch(value) is not None
+
+
+class _RuleAttribution(NamedTuple):
+ """What a config version 2 flag record reports on its flag events."""
+
+ reason_code: Optional[str]
+ rule_id: Optional[str]
+ rule_type: Optional[str]
+ # Set only for a complete experiment split, the outcome that sends an exposure.
+ variant_key: Optional[str]
+
+ def flag_called_properties(self) -> Dict[str, Any]:
+ properties: Dict[str, Any] = {"$feature_flag_config_version": 2}
+ if self.reason_code is not None:
+ properties["$feature_flag_reason_code"] = self.reason_code
+ if self.rule_id is not None:
+ properties["$feature_flag_rule_id"] = self.rule_id
+ if self.rule_type is not None:
+ properties["$feature_flag_rule_type"] = self.rule_type
+ if self.variant_key is not None:
+ properties["$feature_flag_variant_key"] = self.variant_key
+ return properties
+
+
+def _rule_attribution(details: Optional[FeatureFlag]) -> Optional[_RuleAttribution]:
+ """Read the event attribution of a config version 2 flag record.
+
+ Returns ``None`` for anything else: no record, an unreadable record, a config
+ version 1 record, or a record from a server without typed values. Only the
+ evaluation details are read, never the value a getter returned.
+
+ The config version and reason code are always reported. The rule ID and rule
+ type are reported together or not at all, only for a targeting match, a rollout
+ miss, a paused experiment, a holdout and a complete experiment split, and only
+ with a rule type the reason code allows (``_RULE_TYPES_BY_REASON_CODE``). A
+ record with no rule ID, no rule type or another rule type, such as a targeting
+ match that names an experiment rule, reports neither. A rule ID that is not a
+ UUID counts as missing. So does a failed record or any other reason code,
+ including one this SDK does not know, and a record with no reason code. The
+ variant key is reported only for a complete experiment split: reason
+ ``experiment_split``, rule type ``experiment``, a rule ID and a variant key (any
+ string, including an empty one). A split without all of them is malformed. A
+ record that reports no rule keeps its reason, reports no rule ID, rule type or
+ variant, and sends no exposure. Its identity is never guessed from the value,
+ the key or an earlier result.
+ """
+ if details is None or not isinstance(details.metadata, FlagMetadata):
+ return None
+ metadata = details.metadata
+ if _v4_field(metadata, "config_version") != 2:
+ return None
+ reason_code = (details.reason.code if details.reason else None) or None
+ allowed_rule_types = _RULE_TYPES_BY_REASON_CODE.get(reason_code or "")
+ if _v4_field(details, "failed") is True or allowed_rule_types is None:
+ return _RuleAttribution(reason_code, None, None, None)
+ rule_id = _v4_field(metadata, "rule_id")
+ rule_type = _v4_field(metadata, "rule_type")
+ if not _is_uuid(rule_id) or rule_type not in allowed_rule_types:
+ return _RuleAttribution(reason_code, None, None, None)
+ if reason_code != _EXPERIMENT_SPLIT_REASON:
+ # Only an experiment split assigns a variant.
+ return _RuleAttribution(reason_code, rule_id, rule_type, None)
+ variant_key = _v4_field(metadata, "variant_key")
+ if not isinstance(variant_key, str):
+ return _RuleAttribution(reason_code, None, None, None)
+ return _RuleAttribution(reason_code, rule_id, rule_type, variant_key)
+
+
+_flag_events_log = logging.getLogger("posthog")
+
+# Guards the check and the reservation of config version 2 flag event dedupe keys on
+# both clients. It is held only for the dict and set operations, never while an event
+# is captured.
+_flag_event_keys_lock = threading.Lock()
+
+
+def _reinit_flag_event_keys_lock_after_fork() -> None:
+ global _flag_event_keys_lock
+ # A parent thread can hold the lock at fork time. Replace it, never acquire it.
+ _flag_event_keys_lock = threading.Lock()
+
+
+if hasattr(os, "register_at_fork"):
+ os.register_at_fork(after_in_child=_reinit_flag_event_keys_lock_after_fork)
+
+
+def _reserve_dedupe_key(
+ reported_by_distinct_id: Dict[Any, Any], distinct_id: Any, dedupe_key: Any
+) -> Optional[Set[Any]]:
+ """Reserve ``dedupe_key`` for ``distinct_id`` unless a read already holds it.
+
+ The check and the reservation are one step, so when concurrent reads have the
+ same key, only one of them gets it. Returns the set that now holds the key, for
+ ``_capture_once``. Returns ``None`` when the key is already there: the event was
+ reported, or another read is capturing it.
+ """
+ with _flag_event_keys_lock:
+ reported = reported_by_distinct_id.get(distinct_id)
+ if reported is None:
+ reported = set()
+ reported_by_distinct_id[distinct_id] = reported
+ if dedupe_key in reported:
+ return None
+ reported.add(dedupe_key)
+ return reported
+
+
+def _capture_once(
+ capture: Callable[..., Any],
+ reported: Set[Any],
+ dedupe_key: Any,
+ event: str,
+ **kwargs: Any,
+) -> None:
+ """Capture one flag event whose key ``_reserve_dedupe_key`` reserved, and keep
+ the key unless capture failed.
+
+ The key stays reserved while capture runs, so concurrent reads do not send the
+ same event twice. It is released when capture raises, or returns ``None``
+ because the event could not be queued (a full or closed queue, opt-out or a
+ disabled client), so a later read tries again. An event that ``before_send``
+ drops keeps its key: the application chose to drop it, and every later read
+ would be dropped the same way. A failure is logged and never reaches the read.
+ """
+ before_send_drops: List[str] = []
+ try:
+ accepted = capture(
+ event, _before_send_drops=before_send_drops, **kwargs
+ ) is not None or bool(before_send_drops)
+ except Exception:
+ _flag_events_log.exception("[FEATURE FLAGS] Failed to capture %s", event)
+ accepted = False
+ if not accepted:
+ with _flag_event_keys_lock:
+ reported.discard(dedupe_key)
+
+
+def _capture_flag_events(
+ capture: Callable[..., Any],
+ flag_calls_reported: Dict[Any, Any],
+ exposures_reported: Dict[Any, Any],
+ *,
+ distinct_id: ID_TYPES,
+ key: str,
+ response: Optional[FlagValue],
+ properties: Dict[str, Any],
+ groups: Optional[Mapping[str, Union[str, int]]],
+ capture_groups: Mapping[str, Any],
+ disable_geoip: Optional[bool],
+ has_experiment: Optional[bool],
+ minimal_flag_called_events: bool,
+ details: Optional[FeatureFlag],
+ value_from_details: bool,
+) -> None:
+ """Send the flag events of one flag read: ``$feature_flag_called`` and, for an
+ experiment split, ``$experiment_exposure``.
+
+ Every read that sends flag events comes here, on both clients: the single-flag
+ getters and the reads of an ``evaluate_flags()`` snapshot. Both events are built
+ from ``details``, the parsed ``/flags`` record that supplied the value, and the
+ call's ``properties``; the flag is never evaluated again.
+
+ ``$feature_flag_called`` is sent if the (distinct_id, flag, response, groups)
+ tuple hasn't already been reported on this client. Group context is included so
+ that group-scoped flags fire a separate event for each group a user is evaluated
+ under. A config version 2 record that supplied the reported value
+ (``value_from_details``) adds its attribution to the event and to that tuple, so
+ equal-valued A/A arms, successive experiments of one flag, and holdouts are each
+ reported. Its reason code replaces the human-readable ``$feature_flag_reason``.
+ A config version 1 event and tuple are unchanged, and so are those of a read
+ whose value the record did not supply.
+
+ ``has_experiment`` is the server-reported signal for whether the flag is linked
+ to an experiment (``None`` when the server did not report it). When the
+ server-controlled gate is on and the flag is known non-experiment, the event is
+ trimmed to a strict allowlist; any missing signal sends the full legacy shape,
+ and experiment-linked flags keep the full set for exposure analysis.
+
+ ``minimal_flag_called_events`` is the gate as observed by the evaluation that
+ produced ``response``, not a fresh read of client-wide state: both callers
+ resolve it themselves (the snapshot pins it at construction; the single-flag
+ path reads it from the specific local/remote source that produced the value) so
+ a concurrent poller refresh or another ``/flags`` call can't reshape an event
+ after the fact.
+
+ ``$experiment_exposure`` is sent for a complete config version 2 experiment
+ split whose record supplied the reported value (``value_from_details``), once
+ per distinct ID, groups, flag, rule and variant. It has its own dedupe, so a
+ ``$feature_flag_called`` already reported never suppresses it.
+
+ Both config version 2 events are attempted independently: a failed capture of
+ one does not stop the other, and keeps no dedupe key, so a later read tries
+ again. An event that ``before_send`` drops keeps its key. Each key is reserved
+ before its capture, in the same step as the check, so concurrent reads of one
+ outcome send each event once. Their attribution is pinned after super properties
+ are merged, so a super property can neither change it nor add a field the event
+ never carries. The flag key, the response and the evaluation source are pinned
+ the same way on both events, so the pair always reports the same read.
+ Config version 1 events are sent and deduped as before.
+ """
+ groups_key = (
+ tuple(sorted((str(k), str(v)) for k, v in groups.items())) if groups else ()
+ )
+ # Only a record that supplied the reported value attributes it. A caller's
+ # match_value and a stale cached value are reported as before, with no config
+ # version 2 properties, even when a config version 2 record came with them.
+ attribution = _rule_attribution(details) if value_from_details else None
+ # What both config version 2 events report about the read itself. Each event
+ # pins it, so a super property cannot make the pair disagree.
+ flag_identity = {
+ "$feature_flag": key,
+ "$feature_flag_response": response,
+ "locally_evaluated": properties.get("locally_evaluated") is True,
+ }
+ feature_flag_reported_key: Tuple[Any, ...] = (key, response, groups_key)
+ if attribution is not None:
+ feature_flag_reported_key += (2, *attribution)
+
+ # The set this read records its $feature_flag_called key in, or None when the
+ # read sends no $feature_flag_called.
+ reported_flags: Optional[Set[Any]]
+ if attribution is None:
+ reported_flags = flag_calls_reported.get(distinct_id)
+ if reported_flags is None:
+ reported_flags = set()
+ flag_calls_reported[distinct_id] = reported_flags
+ if feature_flag_reported_key in reported_flags:
+ reported_flags = None
+ else:
+ reported_flags = _reserve_dedupe_key(
+ flag_calls_reported, distinct_id, feature_flag_reported_key
+ )
+
+ if reported_flags is not None:
+ if attribution is not None:
+ properties.pop("$feature_flag_reason", None)
+ properties.update(attribution.flag_called_properties())
+ # Record the server's experiment signal when known, so minimization's impact
+ # can be measured by segmenting on it.
+ if has_experiment is not None:
+ properties["$feature_flag_has_experiment"] = has_experiment
+
+ # Minimize iff the server-controlled gate is on AND the flag is known to have
+ # no linked experiment. Any missing signal (gate absent, has_experiment
+ # missing) fails safe to the full legacy shape.
+ should_minimize = minimal_flag_called_events and has_experiment is False
+ # Only thread the internal allowlist through when minimizing, so the
+ # full-property path's capture() call signature stays unchanged.
+ extra_capture_kwargs: Dict[str, Any] = {}
+ if should_minimize:
+ extra_capture_kwargs["_property_allowlist"] = (
+ _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
+ if attribution is None
+ else _MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES
+ )
+
+ if attribution is None:
+ # Config version 1 events are sent and deduped as before.
+ capture(
+ "$feature_flag_called",
+ distinct_id=distinct_id,
+ properties=properties,
+ groups=capture_groups,
+ disable_geoip=disable_geoip,
+ **extra_capture_kwargs,
+ )
+ reported_flags.add(feature_flag_reported_key)
+ else:
+ _capture_once(
+ capture,
+ reported_flags,
+ feature_flag_reported_key,
+ "$feature_flag_called",
+ distinct_id=distinct_id,
+ properties=properties,
+ groups=capture_groups,
+ disable_geoip=disable_geoip,
+ _pinned_properties=_PinnedProperties(
+ _V2_FLAG_CALLED_PINNED,
+ {**attribution.flag_called_properties(), **flag_identity},
+ ),
+ **extra_capture_kwargs,
+ )
+
+ if attribution is None or attribution.variant_key is None:
+ return
+
+ # The value, request ID, evaluation time and evaluation source are left out, so
+ # one assignment is one exposure however often it is read.
+ exposure_key = (key, groups_key, 2, attribution.rule_id, attribution.variant_key)
+ reported_exposures = _reserve_dedupe_key(
+ exposures_reported, str(distinct_id), exposure_key
+ )
+ if reported_exposures is None:
+ return
+
+ exposure_properties: Dict[str, Any] = {
+ name: properties[name]
+ for name in _EXPOSURE_PROPERTIES_FROM_FLAG_CALLED
+ if name in properties
+ }
+ exposure_identity = {
+ **flag_identity,
+ "$feature_flag_variant_key": attribution.variant_key,
+ "$feature_flag_rule_id": attribution.rule_id,
+ }
+ exposure_properties.update(exposure_identity)
+ _capture_once(
+ capture,
+ reported_exposures,
+ exposure_key,
+ "$experiment_exposure",
+ distinct_id=distinct_id,
+ properties=exposure_properties,
+ groups=capture_groups,
+ disable_geoip=disable_geoip,
+ _pinned_properties=_PinnedProperties(_EXPOSURE_FORBIDDEN, exposure_identity),
+ )
+
+
class _Lane:
"""A capture lane: a queue drained by its own consumer pool, posting to one endpoint.
@@ -800,6 +1229,7 @@ def __init__(
app_host: Optional[str] = None,
email_request_timeout_seconds: float = 15,
email_request_max_retries: int = 2,
+ migrated_from: Optional[str] = None,
):
"""
Initialize a new PostHog client instance.
@@ -836,9 +1266,8 @@ def __init__(
poll_interval: Seconds between local feature flag definition refreshes.
secret_key: A Personal API Key or Project Secret API Key, used to
authenticate local feature flag evaluation, remote config
- payloads, and decrypted flag payloads. Example::
-
- posthog.Client(project_api_key, secret_key="phx_...")
+ payloads, and decrypted flag payloads. For example,
+ `posthog.Client(project_api_key, secret_key="phx_...")`.
personal_api_key: Deprecated alias for ``secret_key``. Still honored
for backwards compatibility; prefer ``secret_key``, which also
@@ -867,6 +1296,8 @@ def __init__(
email_request_max_retries: Number of retries for an email send after a
network error, a rate limit, or an unavailable service. Defaults to 2.
Set to 0 when a job runner already retries the send.
+ migrated_from: The email provider you moved from, such as
+ ``"resend"``. ``emails`` sends it with every request.
super_properties: Properties for every captured event. They fill
only keys the event leaves unset, before ``before_send`` runs.
``$set``, ``$set_once``, ``$groups`` and ``$group_set`` fill
@@ -1035,6 +1466,9 @@ def __init__(
)
self.poller: Optional[Poller] = None
self.distinct_ids_feature_flags_reported = SizeLimitedDict(MAX_DICT_SIZE, set)
+ # $experiment_exposure dedupe, kept apart from $feature_flag_called's so that a
+ # reported call never suppresses its exposure. Same bound and eviction.
+ self._experiment_exposures_reported = SizeLimitedDict(MAX_DICT_SIZE, set)
self.flag_fallback_cache_url = flag_fallback_cache_url
self.flag_cache = self._initialize_flag_cache(flag_fallback_cache_url)
self.flag_definition_version = 0
@@ -1178,10 +1612,13 @@ def __init__(
else resolved_secret_key
) or None
self.personal_api_key = self.secret_key
- _validate_options(email_request_timeout_seconds, email_request_max_retries)
+ _validate_options(
+ email_request_timeout_seconds, email_request_max_retries, migrated_from
+ )
self.app_host = app_host
self.email_request_timeout_seconds = email_request_timeout_seconds
self.email_request_max_retries = email_request_max_retries
+ self.migrated_from = migrated_from
if debug:
# Ensures that debug level messages are logged when debug mode is on.
# Otherwise, defaults to WARNING level. See https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided
@@ -1347,10 +1784,10 @@ def run_as_callback(sample):
@property
def emails(self) -> Emails:
"""
- Send transactional email from PostHog email templates, and read the
- status of each email sent with ``get``.
+ 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 the ``hog_flow:write``
+ Needs ``secret_key``, a project secret API key with the ``transactional_email:write``
scope. Sends go to ``app_host``, or to the PostHog Cloud app host of
``host``. ``email_request_timeout_seconds`` and ``email_request_max_retries``
configure each send. A disabled or shut-down client sends nothing. See
@@ -1376,6 +1813,7 @@ def emails(self) -> Emails:
app_host=self.app_host,
timeout=self.email_request_timeout_seconds,
max_retries=self.email_request_max_retries,
+ migrated_from=self.migrated_from,
)
return self._emails
@@ -1967,6 +2405,8 @@ def _capture(
# Internal, set for minimal $feature_flag_called events: a strict allowlist
# applied to the fully-enriched properties dict just before enqueueing.
property_allowlist = kwargs.get("_property_allowlist", None)
+ pinned_properties = kwargs.get("_pinned_properties", None)
+ before_send_drops = kwargs.get("_before_send_drops", None)
properties = dict(properties or {})
@@ -2090,6 +2530,8 @@ def _capture(
system_properties=system_context(),
flag_properties=extra_properties,
trace_properties=trace_properties,
+ pinned_properties=pinned_properties,
+ before_send_drops=before_send_drops,
)
def _parse_send_feature_flags(self, send_feature_flags) -> SendFeatureFlagsOptions:
@@ -2427,7 +2869,7 @@ def capture_exception(
# Some code that might fail
pass
except Exception as e:
- posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)
+ posthog.capture_exception(e, distinct_id='user_distinct_id', properties=additional_properties)
```
Category:
@@ -2713,6 +3155,8 @@ def _enqueue(
system_properties=None,
flag_properties=None,
trace_properties=None,
+ pinned_properties=None,
+ before_send_drops=None,
):
# type: (...) -> Optional[str]
"""Push a new `msg` onto a lane's queue (analytics when unspecified), return the event uuid or None."""
@@ -2762,6 +3206,7 @@ def _enqueue(
trace_properties=trace_properties,
library_id=self._library_id,
library_version=self._library_version,
+ pinned_properties=pinned_properties,
),
)
@@ -2783,6 +3228,8 @@ def _enqueue(
modified_msg = self.before_send(msg)
if modified_msg is None:
self.log.debug("Event dropped by before_send callback")
+ if before_send_drops is not None:
+ before_send_drops.append(msg["event"])
return None
if not isinstance(modified_msg, dict):
_log_before_send_bad_return(self.log, event_name, modified_msg)
@@ -3429,6 +3876,11 @@ def _shutdown_once(self, errors: list[Exception]) -> None:
self.distinct_ids_feature_flags_reported.clear,
errors,
)
+ self._run_lifecycle_cleanup(
+ "Failed to clear experiment exposure deduplication state on shutdown",
+ self._experiment_exposures_reported.clear,
+ errors,
+ )
if self.exception_capture:
self._run_lifecycle_cleanup(
@@ -3734,6 +4186,8 @@ def _classify_unresolvable_flags(
unresolvable: Dict[str, Tuple[UnresolvedFlagReason, str]] = {}
for flag in snapshot["flags"]:
try:
+ if flag.get("evaluation_runtime") == "client":
+ continue
key = flag["key"]
reason = _get_definition_unresolved_reason(
flag,
@@ -4295,6 +4749,9 @@ def _get_feature_flag_result(
flag_result = None
flag_details = None
+ # Whether flag_details supplied the value this read reports. Only then may the
+ # read report config version 2 attribution or send $experiment_exposure.
+ value_from_details = False
request_id = None
evaluated_at = None
feature_flag_error: Optional[str] = None
@@ -4408,6 +4865,11 @@ def _get_feature_flag_result(
self.log.debug(
f"Successfully computed flag remotely: #{key} -> #{flag_result}"
)
+ # A payload lookup for a caller's match_value reports that value, not
+ # the record's. A failure above falls back to a stale cached value.
+ value_from_details = (
+ flag_details is not None and override_match_value is None
+ )
except QuotaLimitError as e:
self.log.warning(f"[FEATURE FLAGS] Quota limit exceeded: {e}")
feature_flag_error = FeatureFlagError.QUOTA_LIMITED
@@ -4469,6 +4931,7 @@ def _get_feature_flag_result(
minimal_flag_called_events,
local_flag_id=local_flag_id,
local_flag_version=local_flag_version,
+ value_from_details=value_from_details,
)
return flag_result
@@ -4490,6 +4953,9 @@ def get_feature_flag_result(
Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely
depending on whether local evaluation is enabled and the flag can be locally evaluated.
This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.
+ When the flag was evaluated remotely and its config version 2 record is a complete experiment
+ split (an experiment rule with a rule ID and a variant key), it also captures the
+ `$experiment_exposure` event, once per distinct ID, groups, flag, rule and variant.
Examples:
```python
@@ -4760,6 +5226,11 @@ def _capture_feature_flag_called(
minimal_flag_called_events: bool = False,
local_flag_id: Optional[int] = None,
local_flag_version: Optional[int] = None,
+ *,
+ # Keyword-only, and false by default: a caller that does not say the record
+ # supplied the value reports no config version 2 attribution and sends no
+ # $experiment_exposure.
+ value_from_details: bool = False,
):
properties: dict[str, Any] = {
"$feature_flag": key,
@@ -4800,6 +5271,8 @@ def _capture_feature_flag_called(
disable_geoip=disable_geoip,
has_experiment=has_experiment,
minimal_flag_called_events=minimal_flag_called_events,
+ details=flag_details,
+ value_from_details=value_from_details,
)
def _capture_feature_flag_called_if_needed(
@@ -4813,66 +5286,35 @@ def _capture_feature_flag_called_if_needed(
disable_geoip: Optional[bool] = None,
has_experiment: Optional[bool] = None,
minimal_flag_called_events: bool = False,
+ details: Optional[FeatureFlag] = None,
+ value_from_details: bool = False,
) -> None:
- """Fire a ``$feature_flag_called`` event if the (distinct_id, flag, response,
- groups) tuple hasn't already been reported on this client. Group context is
- included so that group-scoped flags fire a separate event for each group a user
- is evaluated under. Shared by the single-flag evaluation path and
- ``FeatureFlagEvaluations.is_enabled() / get_flag()`` so both paths dedupe
- identically.
-
- ``has_experiment`` is the server-reported signal for whether the flag is linked
- to an experiment (``None`` when the server did not report it). When the
- server-controlled gate is on and the flag is known non-experiment, the event is
- trimmed to a strict allowlist; any missing signal sends the full legacy shape,
- and experiment-linked flags keep the full set for exposure analysis.
-
- ``minimal_flag_called_events`` is the gate as observed by the evaluation that
- produced ``response``, not a fresh read of client-wide state: both callers
- resolve it themselves (the snapshot pins it at construction; the single-flag
- path reads it from the specific local/remote source that produced the value)
- so a concurrent poller refresh or another ``/flags`` call can't reshape an
- event after the fact.
+ """Send the flag events of a flag read: ``$feature_flag_called`` and, for an
+ experiment split, ``$experiment_exposure``. See ``_capture_flag_events``.
+
+ Shared by the single-flag evaluation path and the reads of a
+ ``FeatureFlagEvaluations`` snapshot, so every read reports and dedupes
+ identically. ``details`` is the parsed ``/flags`` record of the read, or
+ ``None`` for a locally evaluated flag. ``value_from_details`` says whether that
+ record supplied the reported value; only then does the read report config
+ version 2 attribution or send an exposure.
"""
- groups_key = (
- tuple(sorted((str(k), str(v)) for k, v in groups.items())) if groups else ()
- )
- feature_flag_reported_key = (key, response, groups_key)
-
- reported_flags = self.distinct_ids_feature_flags_reported.get(distinct_id)
- if reported_flags is None:
- reported_flags = set()
- self.distinct_ids_feature_flags_reported[distinct_id] = reported_flags
-
- if feature_flag_reported_key in reported_flags:
- return
-
- # Record the server's experiment signal when known, so minimization's impact
- # can be measured by segmenting on it.
- if has_experiment is not None:
- properties["$feature_flag_has_experiment"] = has_experiment
-
- # Minimize iff the server-controlled gate is on AND the flag is known to have
- # no linked experiment. Any missing signal (gate absent, has_experiment
- # missing) fails safe to the full legacy shape.
- should_minimize = minimal_flag_called_events and has_experiment is False
- # Only thread the internal allowlist through when minimizing, so the
- # full-property path's capture() call signature stays unchanged.
- extra_capture_kwargs: dict[str, Any] = {}
- if should_minimize:
- extra_capture_kwargs["_property_allowlist"] = (
- _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
- )
-
- self.capture(
- "$feature_flag_called",
+ _capture_flag_events(
+ self.capture,
+ self.distinct_ids_feature_flags_reported,
+ self._experiment_exposures_reported,
distinct_id=distinct_id,
+ key=key,
+ response=response,
properties=properties,
- groups=groups or {},
+ groups=groups,
+ capture_groups=groups or {},
disable_geoip=disable_geoip,
- **extra_capture_kwargs,
+ has_experiment=has_experiment,
+ minimal_flag_called_events=minimal_flag_called_events,
+ details=details,
+ value_from_details=value_from_details,
)
- reported_flags.add(feature_flag_reported_key)
def get_remote_config_payload(self, key: str):
"""
@@ -5419,9 +5861,10 @@ def _initialize_flag_cache(self, cache_url):
redis_url = f"{parsed.scheme}://"
if parsed.username or parsed.password:
redis_url += f"{parsed.username or ''}:{parsed.password or ''}@"
- redis_url += (
- f"{parsed.hostname or 'localhost'}:{parsed.port or 6379}"
- )
+ host = parsed.hostname or "localhost"
+ if ":" in host:
+ host = f"[{host}]"
+ redis_url += f"{host}:{parsed.port or 6379}"
if parsed.path:
redis_url += parsed.path
diff --git a/posthog/contexts.py b/posthog/contexts.py
index 1f9a00b8e..d01f2dbcb 100644
--- a/posthog/contexts.py
+++ b/posthog/contexts.py
@@ -184,7 +184,7 @@ def _get_active_span_context() -> Dict[str, Optional[str]]:
def _default_capture_exceptions(client: Optional["Client"] = None) -> bool:
if client is not None:
- return client.enable_exception_autocapture
+ return getattr(client, "enable_exception_autocapture", False)
from . import default_client, enable_exception_autocapture
diff --git a/posthog/emails.py b/posthog/emails.py
index 00b660f55..bbfb85470 100644
--- a/posthog/emails.py
+++ b/posthog/emails.py
@@ -1,11 +1,13 @@
-"""Transactional email, sent from an email template in PostHog.
+"""Transactional email, sent from an email template in PostHog or from content in your code.
Setup:
1. In PostHog, open the email template under Workflows, make it transactional,
and copy its ID. ``template_id`` is that UUID.
-2. Create a project secret API key (``phs_...``) with Workflow write access
- (``hog_flow:write``) in your project settings. The project API key
+2. Create a project secret API key (``phs_...``) with the "Send transactional
+ email" preset (``transactional_email:write``) in your project settings. Add
+ ``transactional_email:read`` too if you read email statuses with a key that
+ can't send. Keys made with ``hog_flow:write`` still work. The project API key
(``phc_...``) captures events but cannot send email.
3. Send from the client you already use, or from :class:`Emails` in a process
that only sends email:
@@ -22,6 +24,15 @@
idempotency_key="welcome:user_123",
)
print(result.id) # the queued email
+
+# Content you rendered for this recipient, named by a key
+posthog.emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ distinct_id="user_123",
+)
```
``posthog.emails`` above is the client's property. For async code, use
@@ -44,13 +55,17 @@
:class:`Emails`, when a job runner already retries the send, and pass an
``idempotency_key`` that names the email, such as ``welcome:user_123``.
+Moving from another email provider: set ``migrated_from``, such as
+``"resend"``, on the client or on :class:`Emails`, so PostHog knows where your
+sends came from.
+
Errors: a send that is not queued raises :class:`EmailError`. Branch on
``code``. The ones a setup usually hits:
- ``missing_secret_key``: the client has no ``secret_key``.
- ``missing_app_host``: the client's ``host`` is not PostHog Cloud. Set ``app_host``.
- ``authentication_failed`` (401) or ``permission_denied`` (403): the key is
- wrong, or it lacks ``hog_flow:write``.
+ wrong, or it lacks ``transactional_email:write``.
- ``not_found`` (404): the template ID is wrong, or transactional email is not
enabled for the project.
- ``client_disabled``: the client is disabled, so it sends nothing.
@@ -58,9 +73,9 @@
Status: ``emails.get(message_id)`` reads what happened to a sent email, for
30 days after the send, as an :class:`EmailStatus`. A key with only
-``hog_flow:read`` can read statuses but not send. ``get`` raises ``not_found``
-(404) for an unknown ID, an email older than 30 days, or for a few seconds
-after the send.
+``transactional_email:read`` can read statuses but not send. ``get`` raises
+``not_found`` (404) for an unknown ID, an email older than 30 days, or for a
+few seconds after the send.
Cleanup: ``shutdown()`` on the client closes its email connections. Close a
standalone :class:`Emails` with ``close()`` or a ``with`` block.
@@ -85,10 +100,21 @@
from dataclasses import dataclass
from datetime import datetime
from types import TracebackType
-from typing import Any, Callable, Mapping, Optional, TypeVar, Union
+from typing import (
+ Any,
+ Callable,
+ Mapping,
+ Optional,
+ Sequence,
+ TypedDict,
+ TypeVar,
+ Union,
+ overload,
+)
from uuid import UUID, uuid4
import requests
+from typing_extensions import NotRequired, Unpack
from .capture_send import _parse_retry_after
from .request import (
@@ -102,19 +128,23 @@
__all__ = [
"AsyncEmails",
+ "CodeEmailArgs",
"EmailError",
"EmailStatus",
"EmailWarning",
"Emails",
"SendEmailResult",
+ "TemplateEmailArgs",
]
log = logging.getLogger("posthog")
_SEND_PATH = "/api/projects/@current/messaging/send/email/"
_STATUS_PATH = "/api/projects/@current/messaging/emails/{message_id}/"
+_TEMPLATE_KEY = re.compile(r"[a-zA-Z0-9_-]{1,400}")
_MAX_RETRY_DELAY = 30.0
_IDEMPOTENCY_KEY = re.compile(r"^[\x21-\x7e]{1,255}$")
+_HEADER_TOKEN = re.compile(r"[\x21-\x7e]+")
_IN_FLIGHT_CODES = frozenset({"idempotency_key_in_flight"})
_QUOTA_CODES = frozenset({"quota_limited"})
@@ -125,6 +155,17 @@ class EmailError(Exception):
Branch on ``code``, PostHog's stable error code, or on ``name``, a coarse
category of the failure. The message never contains the secret key or the
request body.
+
+ Attributes:
+ name: A coarse category of the failure.
+ code: PostHog's stable error code.
+ message: What went wrong. It never contains the secret key or the request body.
+ status_code: The HTTP status of the response, or ``None`` when none arrived.
+ why: PostHog's explanation of the failure, when it gave one.
+ fix: What to change to fix it, when PostHog said.
+ docs_url: A docs page about the error, when PostHog gave one.
+ field: The request field the error is about, when there is one.
+ retry_after: Seconds to wait before retrying, when PostHog said.
"""
def __init__(
@@ -161,13 +202,99 @@ class EmailWarning:
@dataclass(frozen=True)
class SendEmailResult:
- """The queued email. ``id`` is its message ID."""
+ """The queued email. ``id`` is its message ID.
+
+ Attributes:
+ id: The email's message ID.
+ replayed: ``True`` when the response says PostHog replayed an earlier send for
+ the same ``idempotency_key`` instead of sending again.
+ warnings: Warnings PostHog returned about the request.
+ """
id: str
replayed: bool = False
warnings: tuple[EmailWarning, ...] = ()
+class _RecipientArgs(TypedDict):
+ to: str
+ distinct_id: NotRequired[Optional[str]]
+ idempotency_key: NotRequired[Optional[str]]
+ max_retries: NotRequired[Optional[int]]
+
+
+class TemplateEmailArgs(_RecipientArgs):
+ """A send of an email template made in PostHog, named by its ID.
+
+ Args:
+ to: One recipient email address.
+ template_id: The UUID of a template made transactional in PostHog.
+ template_data: Values for the template's ``{{ variables.* }}``
+ placeholders.
+ distinct_id: The recipient's distinct ID in your product.
+ idempotency_key: 1 to 255 visible ASCII characters.
+ max_retries: Overrides the client's maximum number of retries for this
+ send. ``0`` turns retries off.
+ """
+
+ template_id: Union[str, UUID]
+ template_data: NotRequired[Optional[Mapping[str, Any]]]
+
+
+class CodeEmailArgs(_RecipientArgs):
+ """A send of email content that your code rendered for one recipient, named by a key.
+
+ The content goes out as is. To send a React email, render it to HTML in
+ your app first.
+
+ An optional field passed as ``None`` counts as left out.
+
+ Args:
+ to: One recipient email address.
+ template_key: Names the email, so its metrics, logs and status group
+ under it. Letters, digits, ``-`` and ``_``, at most 400.
+ subject: The subject line.
+ html: The HTML body. Give ``html``, ``text`` or both.
+ text: The plain-text body. Without it, PostHog derives it from
+ ``html``. HTML with no text in it, such as a single image, goes out
+ without a plain-text part.
+ from_: A verified sender, such as ``"Acme "``.
+ reply_to: One address or a list of addresses. An empty list sends no reply-to.
+ capture_engagement: Capture the email's opens and clicks as events of
+ the recipient. Defaults to ``True``. A project whose admin turned
+ engagement capture off captures nothing, whatever the send asks. A
+ template made in PostHog follows the project's setting, so the
+ template form doesn't take it.
+ distinct_id: The recipient's distinct ID in your product.
+ idempotency_key: 1 to 255 visible ASCII characters. Template sends
+ and code sends share one set of keys: a key already used for
+ another email, or for a ``template_id`` send, raises
+ ``idempotency_key_reused``. A retry with the same key returns the
+ first send's result, also when its workflow was paused since.
+ max_retries: Overrides the client's maximum number of retries for this
+ send. ``0`` turns retries off.
+ """
+
+ template_key: str
+ subject: str
+ html: NotRequired[Optional[str]]
+ text: NotRequired[Optional[str]]
+ from_: NotRequired[Optional[str]]
+ reply_to: NotRequired[Optional[Union[str, Sequence[str]]]]
+ capture_engagement: NotRequired[Optional[bool]]
+
+
+_OPTIONAL_CODE_FIELDS = frozenset(
+ {
+ "html",
+ "text",
+ "from_",
+ "reply_to",
+ "capture_engagement",
+ }
+)
+
+
@dataclass(frozen=True)
class EmailStatus:
"""What happened to an email that ``send()`` queued.
@@ -185,6 +312,13 @@ class EmailStatus:
``reason`` says why a failed email was not sent, such as
``provider_error`` or ``recipient_suppressed``, or gives the bounce type of
a bounced email: ``hard``, ``soft`` or ``unknown``. It is ``None`` otherwise.
+
+ Attributes:
+ id: The email's message ID.
+ status: Where the email is now, one of the values above.
+ created_at: When PostHog queued the email.
+ status_at: When the email reached its current status.
+ reason: Why a failed email was not sent, or a bounced email's bounce type.
"""
id: str
@@ -202,6 +336,114 @@ class _PreparedSend:
max_retries: Optional[int] = None
+def _prepare(args: Mapping[str, Any]) -> _PreparedSend:
+ is_template_form = "template_id" in args
+ if is_template_form == ("template_key" in args):
+ raise TypeError("Pass either template_id or template_key.")
+ form = TemplateEmailArgs if is_template_form else CodeEmailArgs
+ unexpected = sorted(set(args) - set(form.__annotations__))
+ if unexpected:
+ raise TypeError(
+ f"send() got arguments that the {'template' if is_template_form else 'code'} "
+ f"form doesn't take: {', '.join(unexpected)}."
+ )
+ if "to" not in args:
+ raise TypeError("send() is missing the argument to.")
+ if is_template_form:
+ return _prepare_send(
+ args["to"],
+ args["template_id"],
+ args.get("template_data"),
+ args.get("distinct_id"),
+ args.get("idempotency_key"),
+ args.get("max_retries"),
+ )
+ return _prepare_code_send(args)
+
+
+def _prepare_code_send(args: Mapping[str, Any]) -> _PreparedSend:
+ args = {
+ name: value
+ for name, value in args.items()
+ if value is not None or name not in _OPTIONAL_CODE_FIELDS
+ }
+ if "subject" not in args:
+ raise TypeError("send() is missing the argument subject.")
+ to, distinct_id, idempotency_key = _recipient(
+ args["to"], args.get("distinct_id"), args.get("idempotency_key")
+ )
+ max_retries = _retry_limit(args.get("max_retries"))
+ template_key = args["template_key"]
+ if not isinstance(template_key, str) or not _TEMPLATE_KEY.fullmatch(template_key):
+ raise ValueError(
+ "template_key can only have letters, digits, hyphens (-) and underscores (_), at most 400."
+ )
+ content = {"subject": _nonempty_text(args, "subject")}
+ content.update(
+ {field: _string(args, field) for field in ("html", "text") if field in args}
+ )
+ if "html" not in content and "text" not in content:
+ raise TypeError("send() needs html, text or both.")
+ if not (content.get("html") or content.get("text")):
+ raise ValueError("html or text must be a nonempty string.")
+
+ payload: dict[str, Any] = {"to": to, "template_key": template_key, **content}
+ if distinct_id is not None:
+ payload["distinct_id"] = distinct_id
+ payload.update(_sender(args))
+ return _PreparedSend(
+ path=_SEND_PATH,
+ body=_encode(payload),
+ idempotency_key=idempotency_key,
+ max_retries=max_retries,
+ )
+
+
+def _sender(args: Mapping[str, Any]) -> dict[str, Any]:
+ sender: dict[str, Any] = {}
+ if "from_" in args:
+ sender["from"] = _nonempty_text(args, "from_")
+ reply_to = _addresses("reply_to", args["reply_to"]) if "reply_to" in args else []
+ if reply_to:
+ sender["reply_to"] = reply_to
+ capture_engagement = args.get("capture_engagement", True)
+ if not isinstance(capture_engagement, bool):
+ raise TypeError("capture_engagement must be True or False.")
+ sender["capture_engagement"] = capture_engagement
+ return sender
+
+
+def _addresses(field: str, value: Any) -> list[str]:
+ addresses = [value] if isinstance(value, str) else value
+ if not isinstance(addresses, Sequence) or not all(
+ isinstance(address, str) for address in addresses
+ ):
+ raise TypeError(f"{field} must be one address or a list of addresses.")
+ if not all(address.strip() for address in addresses):
+ raise ValueError(f"{field} must not hold a blank address.")
+ return list(addresses)
+
+
+def _string(args: Mapping[str, Any], name: str) -> str:
+ value = args[name]
+ if not isinstance(value, str):
+ raise TypeError(f"{name} must be a string.")
+ return value
+
+
+def _nonempty_text(args: Mapping[str, Any], name: str) -> str:
+ value = _string(args, name)
+ if not value:
+ raise ValueError(f"{name} must not be empty.")
+ return value
+
+
+def _encode(payload: Mapping[str, Any]) -> bytes:
+ return json.dumps(
+ payload, cls=DatetimeSerializer, separators=(",", ":"), ensure_ascii=False
+ ).encode("utf-8")
+
+
def _prepare_send(
to: str,
template_id: Union[str, UUID],
@@ -210,10 +452,8 @@ def _prepare_send(
idempotency_key: Optional[str],
max_retries: Optional[int] = None,
) -> _PreparedSend:
- if not isinstance(to, str):
- raise TypeError("to must be one email address as a string.")
- if not to.strip():
- raise ValueError("to must not be empty.")
+ to, distinct_id, idempotency_key = _recipient(to, distinct_id, idempotency_key)
+ max_retries = _retry_limit(max_retries)
try:
template_uuid = (
template_id if isinstance(template_id, UUID) else UUID(template_id)
@@ -222,6 +462,29 @@ def _prepare_send(
raise ValueError("template_id must be the template's UUID.") from None
if template_data is not None and not isinstance(template_data, Mapping):
raise TypeError("template_data must be a mapping.")
+
+ payload: dict[str, Any] = {
+ "template_id": str(template_uuid),
+ "to": to,
+ "message_data": clean(dict(template_data or {})),
+ }
+ if distinct_id is not None:
+ payload["distinct_id"] = distinct_id
+ return _PreparedSend(
+ path=_SEND_PATH,
+ body=json.dumps(payload, cls=DatetimeSerializer).encode("utf-8"),
+ idempotency_key=idempotency_key,
+ max_retries=max_retries,
+ )
+
+
+def _recipient(
+ to: Any, distinct_id: Any, idempotency_key: Any
+) -> tuple[str, Optional[str], str]:
+ if not isinstance(to, str):
+ raise TypeError("to must be one email address as a string.")
+ if not to.strip():
+ raise ValueError("to must not be empty.")
if distinct_id is not None and (
not isinstance(distinct_id, str) or not distinct_id
):
@@ -234,26 +497,17 @@ def _prepare_send(
raise ValueError(
"idempotency_key must be 1 to 255 visible ASCII characters without spaces."
)
+ return to, distinct_id, idempotency_key
+
+
+def _retry_limit(max_retries: Any) -> Optional[int]:
if max_retries is not None and (
isinstance(max_retries, bool)
or not isinstance(max_retries, int)
or max_retries < 0
):
raise ValueError("max_retries must be a nonnegative integer.")
-
- payload: dict[str, Any] = {
- "template_id": str(template_uuid),
- "to": to,
- "message_data": clean(dict(template_data or {})),
- }
- if distinct_id is not None:
- payload["distinct_id"] = distinct_id
- return _PreparedSend(
- path=_SEND_PATH,
- body=json.dumps(payload, cls=DatetimeSerializer).encode("utf-8"),
- idempotency_key=idempotency_key,
- max_retries=max_retries,
- )
+ return max_retries
def _status_path(message_id: Union[str, UUID]) -> str:
@@ -266,7 +520,9 @@ def _status_path(message_id: Union[str, UUID]) -> str:
return _STATUS_PATH.format(message_id=message_uuid)
-def _validate_options(timeout: float, max_retries: int) -> None:
+def _validate_options(
+ timeout: float, max_retries: int, migrated_from: Optional[str]
+) -> None:
if (
isinstance(timeout, bool)
or not isinstance(timeout, (int, float))
@@ -280,6 +536,12 @@ def _validate_options(timeout: float, max_retries: int) -> None:
or max_retries < 0
):
raise ValueError("max_retries must be a nonnegative integer.")
+ if migrated_from is not None and not (
+ isinstance(migrated_from, str) and _HEADER_TOKEN.fullmatch(migrated_from)
+ ):
+ raise ValueError(
+ "migrated_from must be visible ASCII characters, such as 'resend'."
+ )
def _text(value: Any) -> Optional[str]:
@@ -449,24 +711,33 @@ def _log_warnings(result: SendEmailResult) -> None:
log.warning("PostHog email warning %s: %s", warning.code, warning.message)
-def _headers(secret_key: str, idempotency_key: Optional[str]) -> dict[str, str]:
+def _headers(
+ secret_key: str,
+ migrated_from: Optional[str],
+ *,
+ has_body: bool = False,
+ idempotency_key: Optional[str] = None,
+) -> dict[str, str]:
headers = {
"Authorization": f"Bearer {secret_key}",
"Accept": "application/json",
"User-Agent": f"posthog-python/{VERSION}",
}
- if idempotency_key is not None:
+ if has_body:
headers["Content-Type"] = "application/json"
+ if idempotency_key is not None:
headers["Idempotency-Key"] = idempotency_key
+ if migrated_from is not None:
+ headers["X-PostHog-Migrated-From"] = migrated_from
return headers
_SEND_NOT_DONE = "no email was sent"
_GET_NOT_DONE = "no email status was read"
-_SEND_KEY_NEEDED = "Sending email needs secret_key, a project secret API key with the hog_flow:write scope."
+_SEND_KEY_NEEDED = "Sending email needs secret_key, a project secret API key with the transactional_email:write scope."
_GET_KEY_NEEDED = (
"Reading an email status needs secret_key, a project secret API key with the "
- "hog_flow:read or hog_flow:write scope."
+ "transactional_email:read or transactional_email:write scope."
)
_ResultT = TypeVar("_ResultT")
_Parse = Callable[[int, Any, Optional[str]], _ResultT]
@@ -491,13 +762,15 @@ def __init__(
timeout: float,
max_retries: int,
disabled: bool,
+ migrated_from: Optional[str],
) -> None:
- _validate_options(timeout, max_retries)
+ _validate_options(timeout, max_retries, migrated_from)
self.secret_key = secret_key.strip() if isinstance(secret_key, str) else None
self.host = determine_app_host(host)
self.timeout = timeout
self.max_retries = max_retries
self.disabled = disabled
+ self.migrated_from = migrated_from
self._parent_disabled: Callable[[], bool] = lambda: False
self._admit: Callable[[], Optional[Callable[[], None]]] = lambda: _no_op
self._host_error: Optional[str] = None
@@ -526,7 +799,7 @@ def _secret_key(self, key_needed: str) -> str:
class Emails(_EmailsBase):
- """Sends transactional email from PostHog email templates.
+ """Sends transactional email from PostHog email templates or from content in your code.
``host`` is your PostHog app host. PostHog Cloud ingestion hosts map to the
app host, so ``us.i.posthog.com`` sends to ``us.posthog.com``. Any other
@@ -536,7 +809,8 @@ class Emails(_EmailsBase):
to ``max_retries`` times, with the same idempotency key. Set
``max_retries=0`` when a job runner already retries the send. ``timeout``
is in seconds, per request. Pass ``session`` to send through your own
- ``requests.Session``, for example a test double.
+ ``requests.Session``, for example a test double. ``migrated_from``, such
+ as ``"resend"``, tells PostHog which provider your sends came from.
"""
def __init__(
@@ -548,6 +822,7 @@ def __init__(
max_retries: int = 2,
disabled: bool = False,
session: Optional[requests.Session] = None,
+ migrated_from: Optional[str] = None,
) -> None:
super().__init__(
secret_key,
@@ -555,22 +830,25 @@ def __init__(
timeout=timeout,
max_retries=max_retries,
disabled=disabled,
+ migrated_from=migrated_from,
)
self._session: Optional[requests.Session] = session
self._owns_session = session is None
self._session_lock = threading.Lock()
- def send(
- self,
- *,
- to: str,
- template_id: Union[str, UUID],
- template_data: Optional[Mapping[str, Any]] = None,
- distinct_id: Optional[str] = None,
- idempotency_key: Optional[str] = None,
- max_retries: Optional[int] = None,
- ) -> SendEmailResult:
- """Queue one email from a transactional email template.
+ @overload
+ def send(self, **kwargs: Unpack[TemplateEmailArgs]) -> SendEmailResult: ...
+
+ @overload
+ def send(self, **kwargs: Unpack[CodeEmailArgs]) -> SendEmailResult: ...
+
+ def send(self, **kwargs: Any) -> SendEmailResult:
+ """Queue one email, from a template in PostHog or from content in your code.
+
+ Pass exactly one form. The template form names a template made in
+ PostHog with ``template_id``. The code form names the email with
+ ``template_key`` and passes ``subject`` and ``html``, ``text`` or both:
+ see :class:`CodeEmailArgs`.
Args:
to: One recipient email address.
@@ -608,29 +886,40 @@ def send(
distinct_id="user_123",
idempotency_key="welcome:user_123",
)
+ emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ distinct_id="user_123",
+ )
```
"""
- prepared = _prepare_send(
- to, template_id, template_data, distinct_id, idempotency_key, max_retries
- )
+ prepared = _prepare(kwargs)
finish = self._start(_SEND_NOT_DONE)
try:
- headers = _headers(
- self._secret_key(_SEND_KEY_NEEDED), prepared.idempotency_key
- )
- result = self._call(
- "POST",
- prepared.path,
- prepared.body,
- headers,
- _parse_response,
- prepared.max_retries,
- )
+ result = self._deliver(prepared, self._secret_key(_SEND_KEY_NEEDED))
finally:
finish()
_log_warnings(result)
return result
+ def _deliver(self, prepared: _PreparedSend, secret_key: str) -> SendEmailResult:
+ headers = _headers(
+ secret_key,
+ self.migrated_from,
+ has_body=True,
+ idempotency_key=prepared.idempotency_key,
+ )
+ return self._call(
+ "POST",
+ prepared.path,
+ prepared.body,
+ headers,
+ _parse_response,
+ prepared.max_retries,
+ )
+
def get(self, message_id: Union[str, UUID]) -> EmailStatus:
"""Read what happened to an email that :meth:`send` queued.
@@ -658,7 +947,7 @@ def get(self, message_id: Union[str, UUID]) -> EmailStatus:
path = _status_path(message_id)
finish = self._start(_GET_NOT_DONE)
try:
- headers = _headers(self._secret_key(_GET_KEY_NEEDED), None)
+ headers = _headers(self._secret_key(_GET_KEY_NEEDED), self.migrated_from)
return self._call("GET", path, None, headers, _parse_status_response)
finally:
finish()
@@ -753,6 +1042,7 @@ def __init__(
max_retries: int = 2,
disabled: bool = False,
http_client: Any = None,
+ migrated_from: Optional[str] = None,
) -> None:
super().__init__(
secret_key,
@@ -760,21 +1050,19 @@ def __init__(
timeout=timeout,
max_retries=max_retries,
disabled=disabled,
+ migrated_from=migrated_from,
)
self._client: Any = http_client
self._owns_client = http_client is None
- async def send(
- self,
- *,
- to: str,
- template_id: Union[str, UUID],
- template_data: Optional[Mapping[str, Any]] = None,
- distinct_id: Optional[str] = None,
- idempotency_key: Optional[str] = None,
- max_retries: Optional[int] = None,
- ) -> SendEmailResult:
- """Queue one email from a transactional email template.
+ @overload
+ async def send(self, **kwargs: Unpack[TemplateEmailArgs]) -> SendEmailResult: ...
+
+ @overload
+ async def send(self, **kwargs: Unpack[CodeEmailArgs]) -> SendEmailResult: ...
+
+ async def send(self, **kwargs: Any) -> SendEmailResult:
+ """Queue one email, from a template in PostHog or from content in your code.
Takes the same arguments and raises the same errors as
:meth:`Emails.send`.
@@ -789,27 +1077,33 @@ async def send(
)
```
"""
- prepared = _prepare_send(
- to, template_id, template_data, distinct_id, idempotency_key, max_retries
- )
+ prepared = _prepare(kwargs)
finish = self._start(_SEND_NOT_DONE)
try:
- headers = _headers(
- self._secret_key(_SEND_KEY_NEEDED), prepared.idempotency_key
- )
- result = await self._call(
- "POST",
- prepared.path,
- prepared.body,
- headers,
- _parse_response,
- prepared.max_retries,
- )
+ result = await self._deliver(prepared, self._secret_key(_SEND_KEY_NEEDED))
finally:
finish()
_log_warnings(result)
return result
+ async def _deliver(
+ self, prepared: _PreparedSend, secret_key: str
+ ) -> SendEmailResult:
+ headers = _headers(
+ secret_key,
+ self.migrated_from,
+ has_body=True,
+ idempotency_key=prepared.idempotency_key,
+ )
+ return await self._call(
+ "POST",
+ prepared.path,
+ prepared.body,
+ headers,
+ _parse_response,
+ prepared.max_retries,
+ )
+
async def get(self, message_id: Union[str, UUID]) -> EmailStatus:
"""Read what happened to an email that :meth:`send` queued.
@@ -819,7 +1113,7 @@ async def get(self, message_id: Union[str, UUID]) -> EmailStatus:
path = _status_path(message_id)
finish = self._start(_GET_NOT_DONE)
try:
- headers = _headers(self._secret_key(_GET_KEY_NEEDED), None)
+ headers = _headers(self._secret_key(_GET_KEY_NEEDED), self.migrated_from)
return await self._call("GET", path, None, headers, _parse_status_response)
finally:
finish()
@@ -915,10 +1209,15 @@ def _client_emails(
app_host: Optional[str],
timeout: float,
max_retries: int,
+ migrated_from: Optional[str],
) -> _EmailsT:
if app_host:
emails = factory(
- secret_key, host=app_host, timeout=timeout, max_retries=max_retries
+ secret_key,
+ host=app_host,
+ timeout=timeout,
+ max_retries=max_retries,
+ migrated_from=migrated_from,
)
emails._parent_disabled = is_disabled
emails._admit = admit
@@ -930,6 +1229,7 @@ def _client_emails(
host=inferred_host if is_cloud else None,
timeout=timeout,
max_retries=max_retries,
+ migrated_from=migrated_from,
)
if not is_cloud:
# A custom host is often an ingestion proxy, which must not receive the secret key.
diff --git a/posthog/exception_utils.py b/posthog/exception_utils.py
index 65037ca01..f597500b9 100644
--- a/posthog/exception_utils.py
+++ b/posthog/exception_utils.py
@@ -722,9 +722,12 @@ def single_exception_from_error_tuple(
exception_value["mechanism"].setdefault("handled", True)
exception_value["mechanism"].pop("source", None)
- # Python capture inputs are runtime exceptions and this builder never
- # replaces their stack with an SDK-generated current stack.
- exception_value["mechanism"].setdefault("synthetic", False)
+ # The stack is synthetic only when the SDK built it, which happens for an
+ # exception that was passed to capture without ever being raised.
+ exception_value["mechanism"].setdefault(
+ "synthetic",
+ tb is not None and _is_synthesized_traceback(exc_value, tb),
+ )
is_exception_group = BaseExceptionGroup is not None and isinstance(
exc_value, BaseExceptionGroup
@@ -1089,13 +1092,50 @@ def exc_info_from_error(error):
return exc_info
+_SYNTHESIZED_TRACEBACK_ATTR = "__posthog_synthesized_traceback"
+
+# Taken from this module's name because the posthoganalytics mirror is the same
+# code under another package name.
+_SDK_PACKAGE = __name__.partition(".")[0]
+
+
+class _SynthesizedTraceback:
+ """Holds the traceback the SDK built for an exception that was never raised."""
+
+ __slots__ = ("traceback",)
+
+ def __init__(self, traceback):
+ # type: (TracebackType) -> None
+ self.traceback = traceback
+
+ def __reduce__(self):
+ # A pickle or deep copy of the exception has no traceback to mark, and a
+ # traceback can't be pickled. Reducing to None also keeps this class out
+ # of the pickle, so it still loads where the SDK isn't installed.
+ return (type(None), ())
+
+
+def _is_synthesized_traceback(exc_value, tb):
+ # type: (Optional[BaseException], TracebackType) -> bool
+ marker = getattr(exc_value, _SYNTHESIZED_TRACEBACK_ATTR, None)
+ return marker is not None and marker.traceback is tb
+
+
+def _is_sdk_frame(frame):
+ # type: (FrameType) -> bool
+ module = frame.f_globals.get("__name__") or ""
+ return module == _SDK_PACKAGE or module.startswith(_SDK_PACKAGE + ".")
+
+
def construct_artificial_traceback(e):
# type: (BaseException) -> None
if getattr(e, "__traceback__", None) is not None:
return
+ # Collect the current stack innermost first, leaving out the SDK's own
+ # capture frames so the stack ends where the application called the SDK.
depth = 0
- frames = []
+ frames = [] # type: List[FrameType]
while True:
try:
frame = sys._getframe(depth)
@@ -1103,15 +1143,20 @@ def construct_artificial_traceback(e):
except ValueError:
break
+ if not frames and _is_sdk_frame(frame):
+ continue
frames.append(frame)
- frames.reverse()
-
+ # Link the traceback from the innermost frame outwards, so that following
+ # tb_next walks from the outermost frame to the innermost one, the same
+ # order the interpreter uses for a raised exception.
tb = None
for frame in frames:
tb = types.TracebackType(tb, frame, frame.f_lasti, frame.f_lineno)
- setattr(e, "__traceback__", tb)
+ if tb is not None:
+ setattr(e, "__traceback__", tb)
+ setattr(e, _SYNTHESIZED_TRACEBACK_ATTR, _SynthesizedTraceback(tb))
def _module_in_list(name, items):
diff --git a/posthog/feature_flag_evaluations.py b/posthog/feature_flag_evaluations.py
index 28e5bf31e..8ddd10f49 100644
--- a/posthog/feature_flag_evaluations.py
+++ b/posthog/feature_flag_evaluations.py
@@ -115,16 +115,23 @@ class FeatureFlagEvaluations:
``flags`` option so the captured event carries the exact flag values the code
branched on.
- Example::
-
- flags = posthog.evaluate_flags(distinct_id, person_properties={"plan": "enterprise"})
- if flags.is_enabled("new-dashboard"):
- render_new_dashboard()
- posthog.capture("page_viewed", distinct_id=distinct_id, flags=flags)
+ ```python
+ flags = posthog.evaluate_flags(distinct_id, person_properties={"plan": "enterprise"})
+ if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+ posthog.capture("page_viewed", distinct_id=distinct_id, flags=flags)
+ ```
To narrow the set of flags that get attached to a captured event, use the in-memory
helpers :meth:`only` and :meth:`only_accessed`. To narrow the set of flags requested
from the server in the first place, pass ``flag_keys`` to :meth:`Client.evaluate_flags`.
+
+ Reading a flag sends ``$feature_flag_called``, deduplicated as :meth:`is_enabled`
+ describes. When the flag was evaluated remotely and its config version 2 record is
+ a complete experiment split (an experiment rule with a rule ID and a variant key),
+ the read also sends ``$experiment_exposure``. The SDK sends one exposure per
+ distinct ID, groups, flag, rule and variant. ``send_feature_flag_events=False``
+ suppresses both events.
"""
def __init__(
@@ -387,4 +394,8 @@ def _record_access(self, key: str, send_feature_flag_events: bool) -> None:
properties=properties,
has_experiment=flag.has_experiment if flag else None,
minimal_flag_called_events=self._minimal_flag_called_events,
+ # The record that supplied the value. A remotely evaluated experiment
+ # split also sends $experiment_exposure, whatever this read returned.
+ details=flag.details if isinstance(flag, _RemoteFlagRecord) else None,
+ value_from_details=True,
)
diff --git a/posthog/feature_flags.py b/posthog/feature_flags.py
index cfe847fbb..6634ae367 100644
--- a/posthog/feature_flags.py
+++ b/posthog/feature_flags.py
@@ -99,6 +99,9 @@ class InconclusiveMatchError(Exception):
"""
Raised when local evaluation can't determine a flag's value. ``reason`` says
why, as reported by ``FeatureFlagEvaluations.unresolved_flags``.
+
+ Attributes:
+ reason: Why local evaluation couldn't resolve the flag.
"""
reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
@@ -116,6 +119,9 @@ class RequiresServerEvaluation(Exception):
This error should propagate immediately to trigger API fallback, unlike
InconclusiveMatchError which allows trying other conditions.
+
+ Attributes:
+ reason: Why the flag needs server-side evaluation.
"""
reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
@@ -492,6 +498,21 @@ def match_feature_flag_properties(
flag_filters = flag.get("filters") or {}
+ if flag_filters.get("feature_enrollment") is True:
+ enrollment_key = f"$feature_enrollment/{flag.get('key')}"
+ if flag_filters.get("aggregation_group_type_index") is not None:
+ raise InconclusiveMatchError(
+ "Group flag has feature enrollment, which reads person properties",
+ reason=UnresolvedFlagReason.UNSUPPORTED_DEFINITION,
+ )
+ if enrollment_key not in properties:
+ raise InconclusiveMatchError(
+ f"Flag has feature enrollment and '{enrollment_key}' was not passed",
+ reason=UnresolvedFlagReason.MISSING_CONTEXT,
+ )
+ enrollment = properties[enrollment_key]
+ return enrollment is True or enrollment == "true"
+
# Holdouts are evaluated before release conditions, so a held-out value is excluded
# from the flag's targeting entirely rather than being bucketed into a variant.
holdout_variant = _get_holdout_variant(flag, bucketing_value)
@@ -1594,14 +1615,20 @@ def parse_datetime(value: str) -> datetime.datetime:
# Python's stdlib doesn't provide a calendar-aware month/year delta.
-# Clamp the day to the target month's end to match dateutil.relativedelta behavior.
+# Subtract one unit at a time and clamp the day after every step, so March 31
+# minus two months is January 28 (through February 28), as the SDK spec requires.
def _subtract_months(dt: datetime.datetime, months: int) -> Optional[datetime.datetime]:
- month_index = dt.year * 12 + dt.month - 1 - months
+ current_index = dt.year * 12 + dt.month - 1
+ month_index = current_index - months
year = month_index // 12
month = month_index % 12 + 1
if not 1 <= year <= 9999:
return None
- day = min(dt.day, calendar.monthrange(year, month)[1])
+ day = dt.day
+ for index in range(current_index - 1, month_index - 1, -1):
+ if day <= 28: # Every month has at least 28 days, so nothing clamps further.
+ break
+ day = min(day, calendar.monthrange(index // 12, index % 12 + 1)[1])
return dt.replace(year=year, month=month, day=day)
@@ -1609,7 +1636,9 @@ def _subtract_years(dt: datetime.datetime, years: int) -> Optional[datetime.date
year = dt.year - years
if not 1 <= year <= 9999:
return None
- day = min(dt.day, calendar.monthrange(year, dt.month)[1])
+ # The year before a leap year is never a leap year, so February 29 clamps on
+ # the first step and stays on the 28th.
+ day = 28 if years > 0 and (dt.month, dt.day) == (2, 29) else dt.day
return dt.replace(year=year, day=day)
diff --git a/posthog/integrations/celery.py b/posthog/integrations/celery.py
index c71d816c3..32f035347 100644
--- a/posthog/integrations/celery.py
+++ b/posthog/integrations/celery.py
@@ -320,7 +320,9 @@ def _on_task_prerun(self, *args, **kwargs):
self._apply_propagated_identity(request)
self._enrich_task_span(task_id)
- merged_tags = {**task_properties, **context_tags}
+ # The task's own celery_* values win: tags propagated from a task
+ # that published this one carry that task's values.
+ merged_tags = {**context_tags, **task_properties}
for key, value in merged_tags.items():
contexts.tag(key, value)
for key, value in context_options.items():
diff --git a/posthog/mcp/README.md b/posthog/mcp/README.md
index 474c29c23..fb25bd29a 100644
--- a/posthog/mcp/README.md
+++ b/posthog/mcp/README.md
@@ -34,6 +34,10 @@ but anyone wrapping a server already has it.
MCP analytics events report `$lib: "posthog-python-mcp"` and the installed `posthog` package version in `$lib_version`, so SDK Health can compare MCP traffic with Python SDK releases.
The client's other events, request headers and feature flag requests keep reporting `posthog-python`, so one client can serve both.
+## Versioning
+
+`posthog.mcp` is stable. It ships inside the `posthog` package, so it follows that package's version rather than its own. A minor or patch release of `posthog` doesn't change the `posthog.mcp` API in a breaking way, and doesn't rename or remove a `$mcp_*` event or property, change its type, or change which requests send an event, so saved insights keep working across upgrades. It may add events and properties, and redact more of a captured value. The rules come from the [MCP analytics spec](https://github.com/PostHog/sdk-specs/blob/main/openspec/specs/mcp-analytics/spec.md), section "Event schema stability".
+
## Defaults and opt-outs
A valid echoed conversation handle takes precedence over transport sessions. A request that already carries a transport session or a PostHog session token does not mint a new handle or append a prompt-back block. Requests carrying neither use the conversation fallback.
@@ -190,9 +194,9 @@ contains the sanitized tool arguments and their original names.
Custom dispatchers can call `get_tool_input_properties()` and add its result to
the `properties` argument of `capture_tool_call()`.
-Model capture adds an `llm_model` argument to compatible tool schemas, required on the official
-high-level adapters and optional elsewhere. Dispatch never enforces it, so servers keep working;
-strict-schema clients see the new field. Set `capture_model=False` to leave schemas untouched.
+Model capture adds an optional `llm_model` argument to compatible tool schemas. Dispatch never
+enforces it, so servers keep working; strict-schema clients see the new field. Set
+`capture_model=False` to leave schemas untouched.
Conversation correlation adds an optional `conversation_id` argument and returns a handle in
eligible tool results. Clients must echo it to group later calls; calls without it mint new handles.
Set `enable_conversation_id=False` to retain transport-based session grouping and unchanged
@@ -206,11 +210,9 @@ The SDK records the best model identifier visible to the server as
`$mcp_llm_model`. Recognized client metadata wins and sets
`$mcp_llm_model_source` to `client_metadata`. The SDK also adds an `llm_model`
string to each compatible tool schema as a fallback, recorded with source
-`self_reported`. It is required for custom dispatchers and the official high-level
-MCP SDK adapters. Raw low-level servers and standalone `fastmcp.FastMCP` advertise
-it as optional; the standalone adapter strips it before input validation, so
-requiring it would reject calls. Existing schema strictness is preserved when
-analytics fields are added.
+`self_reported`. It is always optional: an agent that does not know its model would
+otherwise guess one. Existing schema strictness is preserved when analytics fields
+are added.
The recognized metadata path is Codex's `x-codex-turn-metadata.model` field in
request `_meta`. Other clients, including Claude Code, use the self-report path
@@ -238,8 +240,10 @@ On MCP SDK 1.x, standalone FastMCP application middleware can replace or reroute
When it overrides a listing or dispatch hook, PostHog does not inject `llm_model`: a fresh
replica cannot safely distinguish that field from a replacement tool's own argument.
Client metadata capture remains enabled. This also applies to pass-through logging or
-authorization middleware with those hooks; argument-based model capture is skipped so an
-application-owned value cannot be mistaken for analytics. No additional catalog lookup runs
+authorization middleware of your own with those hooks; argument-based model capture is skipped
+so an application-owned value cannot be mistaken for analytics. FastMCP's stock middleware,
+such as `LoggingMiddleware`, `TimingMiddleware`, and `ErrorHandlingMiddleware`, never reroutes a
+tool and does not count; its tool-injection middleware does. No additional catalog lookup runs
during a tool call.
For a custom dispatcher, `PostHogMCP` enables model capture and conversation correlation
@@ -386,6 +390,23 @@ call = posthog.prepare_tool_call(
)
```
+## Calls to tools your server does not have
+
+A `tools/call` naming a tool your server never registered is not a tool call.
+`instrument()` sends `$mcp_unknown_tool` with the requested name as
+`$mcp_tool_name`, and no `$mcp_tool_call` or `$exception`. The agent gets the
+same error as before. A call naming no tool sends nothing.
+
+The SDK asks the tool registry only after the call fails, and records a failed
+tool call whenever the registry can't rule the tool out:
+
+- A disabled tool, or a tool called with invalid arguments, still exists.
+- A raw low-level server has no registry the SDK can read.
+- On standalone `fastmcp.FastMCP`, middleware of your own that overrides a
+ listing or dispatch hook can serve tools the registry lacks.
+- On standalone `fastmcp.FastMCP` 3 and later, a mounted server, proxy, or
+ other provider hides its disabled tools.
+
## Virtual tools on a paginated `tools/list`
`instrument()` advertises up to two tools of its own: `get_more_tools`
diff --git a/posthog/mcp/_event_types.py b/posthog/mcp/_event_types.py
index 7392f90a9..005d08457 100644
--- a/posthog/mcp/_event_types.py
+++ b/posthog/mcp/_event_types.py
@@ -23,3 +23,4 @@ class MCPAnalyticsEventType:
MCP_RESOURCES_READ = "mcp:resources/read"
MCP_TOOLS_CALL = "mcp:tools/call"
MCP_TOOLS_LIST = "mcp:tools/list"
+ MCP_UNKNOWN_TOOL = "mcp:unknown_tool"
diff --git a/posthog/mcp/_instrument_fastmcp.py b/posthog/mcp/_instrument_fastmcp.py
index 78bd1324f..366060141 100644
--- a/posthog/mcp/_instrument_fastmcp.py
+++ b/posthog/mcp/_instrument_fastmcp.py
@@ -167,6 +167,10 @@ async def wrapped(
name, call_arguments, context=context, convert_result=convert_result
)
except Exception as error:
+ if await lifecycle.record_if_unknown_tool(
+ _name_owned_by_real_tool(server, name)
+ ):
+ raise
# The minted prompt-back was never delivered to the agent — don't stamp
# an orphan conversation_id it can't echo (an agent-supplied id is kept).
await lifecycle.record_error(error, (time.monotonic() - start) * 1000)
diff --git a/posthog/mcp/_instrument_lowlevel.py b/posthog/mcp/_instrument_lowlevel.py
index 00bd4ef4d..a8ab58671 100644
--- a/posthog/mcp/_instrument_lowlevel.py
+++ b/posthog/mcp/_instrument_lowlevel.py
@@ -15,10 +15,11 @@
from __future__ import annotations
import functools
+import importlib
import inspect
import time
from functools import lru_cache
-from typing import Any, Dict, List, Optional, Set, Tuple
+from typing import Any, Dict, List, Optional, Set, Tuple, Type
import mcp.types as mcp_types
@@ -36,6 +37,7 @@
copy_tools_list_result,
extract_tools,
is_first_listing_page,
+ is_tool_result_error,
mutate_tool_schema,
prepare_request,
raw_listing_owns_tool_name,
@@ -282,6 +284,10 @@ async def handler(req: Any) -> Any:
try:
result = await original(req)
except Exception as error:
+ if await lifecycle.record_if_unknown_tool(
+ await registered_tool_exists(high_level, name)
+ ):
+ raise
# The @server.call_tool() decorator converts raises into
# CallToolResult(isError=True), but a handler wired straight into
# request_handlers can raise — capture before re-raising so the failed
@@ -333,6 +339,12 @@ async def handler(req: Any) -> Any:
else call_result
)
+ if is_tool_result_error(call_result) and await lifecycle.record_if_unknown_tool(
+ await registered_tool_exists(high_level, name),
+ conversation_id_delivered=delivered,
+ ):
+ return result
+
await lifecycle.record_result(
call_result,
duration_ms,
@@ -573,7 +585,7 @@ async def _name_owned_by_real_tool(
@lru_cache(maxsize=1)
-def _tool_lookup_not_found_errors() -> Tuple[type, ...]:
+def _tool_lookup_not_found_errors() -> Tuple[Type[BaseException], ...]:
"""The fastmcp exceptions that mean "no live tool by that name" -- an answer.
Anything else out of ``get_tool`` is the lookup itself failing. Empty when
fastmcp is absent or has moved them, which makes every failure delegate:
@@ -706,9 +718,13 @@ async def _listed_input_schema(
"""Return the schema that middleware advertises for the current request."""
try:
version = _requested_tool_version(meta)
- candidates = [
- tool for tool in await high_level.list_tools() if tool.name == name
- ]
+ list_tools = getattr(high_level, "list_tools", None)
+ if list_tools is None:
+ # FastMCP 2.x only lists through request middleware, which can
+ # spend rate limits, and its registry can disagree with what that
+ # middleware advertises, so the advertised schema is unknown.
+ return None
+ candidates = [tool for tool in await list_tools() if tool.name == name]
if version is not None:
candidates = [
tool
@@ -793,13 +809,82 @@ def _dispatch_can_differ(server: Any) -> bool:
)
+# Stock fastmcp middleware that observes, times, retries, throttles, denies,
+# caches, or trims a call to the tool it names, and never provides, renames, or
+# reroutes one. The tool-injection family is left out on purpose.
+_STOCK_DISPATCH_PRESERVING_MIDDLEWARE = (
+ ("logging", "LoggingMiddleware"),
+ ("logging", "StructuredLoggingMiddleware"),
+ ("timing", "TimingMiddleware"),
+ ("timing", "DetailedTimingMiddleware"),
+ ("error_handling", "ErrorHandlingMiddleware"),
+ ("error_handling", "RetryMiddleware"),
+ ("rate_limiting", "RateLimitingMiddleware"),
+ ("rate_limiting", "SlidingWindowRateLimitingMiddleware"),
+ ("ping", "PingMiddleware"),
+ ("authorization", "AuthMiddleware"),
+ ("caching", "ResponseCachingMiddleware"),
+ ("response_limiting", "ResponseLimitingMiddleware"),
+)
+
+
@functools.lru_cache(maxsize=1)
def _builtin_middleware_types() -> tuple:
"""The middleware a bare ``FastMCP()`` installs on its own, probed rather
- than named so a new built-in in a later release is still recognised."""
+ than named so a new built-in in a later release is still recognised, plus
+ the stock middleware above that this fastmcp release ships."""
from fastmcp import FastMCP
- return tuple(type(middleware) for middleware in FastMCP("posthog-probe").middleware)
+ stock = []
+ for module, name in _STOCK_DISPATCH_PRESERVING_MIDDLEWARE:
+ try:
+ stock.append(
+ getattr(
+ importlib.import_module(f"fastmcp.server.middleware.{module}"), name
+ )
+ )
+ except (ImportError, AttributeError):
+ continue
+ return tuple(
+ type(middleware) for middleware in FastMCP("posthog-probe").middleware
+ ) + tuple(stock)
+
+
+async def registered_tool_exists(server: Any, name: str) -> Optional[bool]:
+ """Whether jlowin's FastMCP registers ``name``, enabled or not, asked after a
+ failed call to tell an unknown tool from a failed one. A disabled tool still
+ exists: calling it is a failed call. ``None`` when nothing authoritative can
+ say: no registry (a raw low-level server, whose listing may hide tools its
+ dispatcher serves), middleware that can serve tools the registry lacks, or a
+ mounted server or other provider, which hides its disabled tools."""
+ if server is None or _dispatch_can_differ(server):
+ return None
+ try:
+ from fastmcp import FastMCP
+
+ # From 3.x, get_tool hides a disabled tool; the providers still hold it.
+ found = (
+ await server.get_tool(name) is not None
+ or await super(FastMCP, server).get_tool(name) is not None
+ )
+ except _tool_lookup_not_found_errors():
+ found = False
+ except Exception as err: # noqa: BLE001 - analytics must not break the call
+ log(f"PostHog MCP: could not look up tool {name!r} - {err}")
+ return None
+ if found:
+ return True
+ return None if _serves_other_providers(server) else False
+
+
+def _serves_other_providers(server: Any) -> bool:
+ """Whether a FastMCP server serves tools from anywhere but its own
+ registry: a mounted server, a proxy, or a custom provider. FastMCP 2.x
+ keeps mounts in ``_mounted_servers``; 3.x lists them in ``providers``."""
+ if getattr(server, "_mounted_servers", None):
+ return True
+ local = getattr(server, "_local_provider", None)
+ return any(provider is not local for provider in getattr(server, "providers", ()))
def _reference_chain(schema: Dict[str, Any]) -> Optional[List[Dict[str, Any]]]:
diff --git a/posthog/mcp/_instrument_v2.py b/posthog/mcp/_instrument_v2.py
index 58d45f778..b7d597789 100644
--- a/posthog/mcp/_instrument_v2.py
+++ b/posthog/mcp/_instrument_v2.py
@@ -53,6 +53,7 @@
_to_jsonable,
copy_tools_list_result,
is_first_listing_page,
+ is_tool_result_error,
mutate_tool_schema,
params_to_request_dict,
prepare_request,
@@ -66,6 +67,7 @@
start_tools_list_lifecycle,
warn_ownership_lookup_failed,
)
+from ._instrument_lowlevel import registered_tool_exists
from ._internal import MCPAnalyticsData
from ._model_parameters import (
can_inject_model_parameter,
@@ -450,6 +452,10 @@ async def wrapped(
name, call_arguments, context=context, convert_result=convert_result
)
except Exception as error:
+ if await lifecycle.record_if_unknown_tool(
+ _name_owned_by_real_tool_v2(server, name)
+ ):
+ raise
# The outer MCPServer layer converts the raise after this seam; no
# freshly minted handle could have been delivered yet.
await lifecycle.record_error(error, (time.monotonic() - start) * 1000)
@@ -669,6 +675,10 @@ async def handler(ctx: Any, params: Any) -> Any:
try:
result = await original(ctx, params)
except Exception as error:
+ if await lifecycle.record_if_unknown_tool(
+ await registered_tool_exists(standalone, name)
+ ):
+ raise
# Raw v2 handlers raise through to JSON-RPC errors; no freshly minted
# handle could have been delivered yet.
await lifecycle.record_error(error, (time.monotonic() - start) * 1000)
@@ -685,6 +695,12 @@ async def handler(ctx: Any, params: Any) -> Any:
lifecycle.minted_conversation_id,
)
+ if is_tool_result_error(result) and await lifecycle.record_if_unknown_tool(
+ await registered_tool_exists(standalone, name),
+ conversation_id_delivered=delivered,
+ ):
+ return result
+
await lifecycle.record_result(
result, duration_ms, conversation_id_delivered=delivered
)
diff --git a/posthog/mcp/_instrumentation.py b/posthog/mcp/_instrumentation.py
index bd2d1e8b0..37e88b7ff 100644
--- a/posthog/mcp/_instrumentation.py
+++ b/posthog/mcp/_instrumentation.py
@@ -634,6 +634,32 @@ async def record_feedback(self, *, conversation_id_delivered: bool = False) -> s
)
return await handle_feedback(report, self.feedback_options)
+ async def record_if_unknown_tool(
+ self, tool_exists: Optional[bool], *, conversation_id_delivered: bool = False
+ ) -> bool:
+ """Record the failed call as ``$mcp_unknown_tool`` when ``tool_exists``
+ proves the server has no tool by that name, and say whether the call is
+ settled that way. A call naming no tool is settled with no event. The
+ adapter then re-raises or returns its response."""
+ if not self.name:
+ return True
+ if tool_exists is not False:
+ return False
+ conversation_id = self._anchored_conversation_id(conversation_id_delivered)
+ session_id = await self.prepare_session(conversation_id)
+ await record_unknown_tool(
+ self.data,
+ session_id,
+ conversation_id=conversation_id,
+ name=self.name,
+ arguments=self.arguments,
+ client_name=self.client_name,
+ client_version=self.client_version,
+ protocol_version=self.protocol_version,
+ extra=self.extra,
+ )
+ return True
+
async def record_error(self, error: Any, duration_ms: float) -> None:
# A freshly minted handle cannot anchor or be captured when dispatch
# raised: no adapter had an opportunity to deliver it to the agent.
@@ -1200,9 +1226,7 @@ def mutate_tool_schema(
required=context_required,
)
if inject_model:
- schema = _mutate_model_schema(
- data, tool.name, schema, required=context_required
- )
+ schema = _mutate_model_schema(data, tool.name, schema)
else:
# Discard any earlier registered-tool verdict: middleware may now
# advertise or dispatch an application-owned field with the same name.
@@ -1222,9 +1246,7 @@ def mutate_tool_schema(
)
-def _mutate_model_schema(
- data: MCPAnalyticsData, name: str, schema: Any, *, required: bool
-) -> Any:
+def _mutate_model_schema(data: MCPAnalyticsData, name: str, schema: Any) -> Any:
if not is_capture_model_enabled(data.options.capture_model):
return schema
model_was_injected = data.tool_model_parameter_injected.get(name, False)
@@ -1234,7 +1256,6 @@ def _mutate_model_schema(
schema,
name,
get_model_description(data.options.capture_model),
- required=required,
)
data.tool_model_parameter_injected[name] = not app_owns_model and schema_has_param(
schema, "llm_model"
@@ -1400,6 +1421,39 @@ async def record_missing_capability(
log(f"record_missing_capability failed (event dropped): {err}")
+async def record_unknown_tool(
+ data: MCPAnalyticsData,
+ session_id: str,
+ *,
+ conversation_id: Optional[str],
+ name: str,
+ arguments: Optional[Dict[str, Any]],
+ client_name: Optional[str],
+ client_version: Optional[str],
+ protocol_version: Optional[str],
+ extra: Optional[Dict[str, Any]],
+) -> None:
+ """Record a call naming a tool the server never registered as
+ ``$mcp_unknown_tool``. It is not a tool call, so it carries no outcome."""
+ try:
+ event: Dict[str, Any] = {
+ "event_type": MCPAnalyticsEventType.MCP_UNKNOWN_TOOL,
+ "session_id": session_id,
+ "conversation_id": conversation_id,
+ "resource_name": name,
+ "client_name": client_name,
+ "client_version": client_version,
+ "protocol_version": protocol_version,
+ }
+ await _apply_event_properties(
+ data, event, build_tool_call_request(name, arguments), extra
+ )
+ stamp_transport_identity(event, extra)
+ fire_and_forget(capture_event(data, event), data)
+ except Exception as err: # noqa: BLE001 - isolate analytics from the tool path
+ log(f"record_unknown_tool failed (event dropped): {err}")
+
+
async def record_feedback(
data: MCPAnalyticsData,
session_id: str,
diff --git a/posthog/mcp/_model_parameters.py b/posthog/mcp/_model_parameters.py
index 05ee0f29f..be26fd14c 100644
--- a/posthog/mcp/_model_parameters.py
+++ b/posthog/mcp/_model_parameters.py
@@ -33,9 +33,10 @@ def add_model_parameter_to_schema(
input_schema: Optional[Dict[str, Any]],
tool_name: str = "unknown",
description_override: Optional[str] = None,
- required: bool = True,
) -> Optional[Dict[str, Any]]:
- """Return a copied schema with an SDK-owned ``llm_model`` field.
+ """Return a copied schema with an optional, SDK-owned ``llm_model`` field.
+ Never required: an agent that does not know its model would guess one, and
+ a model the client sends in request ``_meta`` wins anyway.
Existing application fields and complex schemas fail closed: the SDK must
never overwrite or later strip a value that belongs to the tool itself.
@@ -58,13 +59,6 @@ def add_model_parameter_to_schema(
"type": "string",
"description": description_override or DEFAULT_MODEL_PARAMETER_DESCRIPTION,
}
- if required:
- required_list = schema.get("required")
- if isinstance(required_list, list):
- if "llm_model" not in required_list:
- required_list.append("llm_model")
- else:
- schema["required"] = ["llm_model"]
return schema
diff --git a/posthog/mcp/_posthog_events.py b/posthog/mcp/_posthog_events.py
index cdfa25874..a0611f855 100644
--- a/posthog/mcp/_posthog_events.py
+++ b/posthog/mcp/_posthog_events.py
@@ -34,6 +34,7 @@
MCPAnalyticsEventType.MCP_RESOURCES_READ: PostHogMCPAnalyticsEvent.RESOURCE_READ,
MCPAnalyticsEventType.MCP_TOOLS_CALL: PostHogMCPAnalyticsEvent.TOOL_CALL,
MCPAnalyticsEventType.MCP_TOOLS_LIST: PostHogMCPAnalyticsEvent.TOOLS_LIST,
+ MCPAnalyticsEventType.MCP_UNKNOWN_TOOL: "$mcp_unknown_tool",
}
_P = PostHogMCPAnalyticsProperty
@@ -144,8 +145,12 @@ def _is_tool_call(event: Event) -> bool:
def _add_common_properties(event: Event, properties: Dict[str, Any]) -> None:
if event.get("resource_name"):
- properties[_P.RESOURCE_NAME] = event["resource_name"]
- if _is_tool_call(event):
+ is_unknown_tool = (
+ event.get("event_type") == MCPAnalyticsEventType.MCP_UNKNOWN_TOOL
+ )
+ if not is_unknown_tool:
+ properties[_P.RESOURCE_NAME] = event["resource_name"]
+ if is_unknown_tool or _is_tool_call(event):
properties[_P.TOOL_NAME] = event["resource_name"]
if event.get("tool_description") and _is_tool_call(event):
properties[_P.TOOL_DESCRIPTION] = event["tool_description"]
diff --git a/posthog/mcp/_sanitization.py b/posthog/mcp/_sanitization.py
index b14f4796d..426d2d29f 100644
--- a/posthog/mcp/_sanitization.py
+++ b/posthog/mcp/_sanitization.py
@@ -14,6 +14,8 @@
from typing import Any, Dict, List, Optional, Set, Tuple
from urllib.parse import SplitResult, parse_qsl, urlencode, urlsplit, urlunsplit
+from ._event_types import MCPAnalyticsEventType
+
# SDK-injected arguments stripped from captured $mcp_parameters (they surface as
# dedicated properties: $mcp_intent and $mcp_conversation_id).
_INJECTED_ARGUMENT_NAMES = ("context", "conversation_id")
@@ -628,8 +630,15 @@ def sanitize_event(event: Dict[str, Any]) -> Dict[str, Any]:
if result.get("parameters") is not None:
result["parameters"] = sanitize_captured_value(result["parameters"])
+ # An unknown tool's name is whatever the agent sent, not one of the
+ # server's identifiers, so it gets the free-text pass.
if result.get("resource_name") is not None:
- result["resource_name"] = _sanitize_resource_name(result["resource_name"])
+ sanitize_name = (
+ sanitize_free_text
+ if result.get("event_type") == MCPAnalyticsEventType.MCP_UNKNOWN_TOOL
+ else _sanitize_resource_name
+ )
+ result["resource_name"] = sanitize_name(result["resource_name"])
# The intent comes straight from an agent-narrated `context` string, so it
# can contain a secret the LLM read aloud or personal data it narrated about
diff --git a/posthog/mcp/_truncation.py b/posthog/mcp/_truncation.py
index 674241a6c..382c64639 100644
--- a/posthog/mcp/_truncation.py
+++ b/posthog/mcp/_truncation.py
@@ -85,9 +85,7 @@ def _visit(
return "[Infinity]" if value > 0 else "[-Infinity]"
return value
if isinstance(value, str):
- if len(value) > max_string_length:
- return value[:max_string_length] + _TRUNCATION_SUFFIX
- return value
+ return truncate_text(value, max_string_length)
if isinstance(value, datetime):
return value.isoformat()
if callable(value):
@@ -161,12 +159,18 @@ def _visit_object(
# --- field-level helpers -----------------------------------------------------
+def truncate_text(value: str, max_length: int) -> str:
+ """``value`` cut to at most ``max_length`` characters, the truncation marker
+ included, keeping its start."""
+ if len(value) <= max_length:
+ return value
+ return value[: max_length - len(_TRUNCATION_SUFFIX)] + _TRUNCATION_SUFFIX
+
+
def _truncate_string(value: Optional[str], max_length: int) -> Optional[str]:
if not isinstance(value, str):
return value
- if len(value) <= max_length:
- return value
- return value[:max_length] + _TRUNCATION_SUFFIX
+ return truncate_text(value, max_length)
def _truncate_stack_frames(frames: Optional[List[Any]]) -> Optional[List[Any]]:
@@ -214,8 +218,7 @@ def _truncate_response_content(response: Any) -> Any:
new_content.append(
{
**block,
- "text": block["text"][:_MAX_CONTENT_TEXT_LENGTH]
- + _TRUNCATION_SUFFIX,
+ "text": truncate_text(block["text"], _MAX_CONTENT_TEXT_LENGTH),
}
)
else:
diff --git a/posthog/mcp/constants.py b/posthog/mcp/constants.py
index de359e693..5fc725b35 100644
--- a/posthog/mcp/constants.py
+++ b/posthog/mcp/constants.py
@@ -18,28 +18,20 @@
INACTIVITY_TIMEOUT_IN_MINUTES = 30
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = (
- "Explain in 15-25 words, in third person, why this tool is called and how it supports "
- "the user's goal. For analytics only. You MUST describe only the abstract purpose of the "
- "tool call. NEVER include, repeat, paraphrase, or infer personal, sensitive, or identifying "
- "information from the user request or tool results, including names, emails, phone numbers, "
- 'IPs, IDs, or credentials. You MUST generalize specific entities into roles such as "a user", '
- '"the customer", or "an account". Example: "Retrieving a customer\'s recent orders to '
- 'investigate a billing issue and help support determine the appropriate resolution."'
+ "A few words on why you are calling this tool, for the server developer's "
+ 'analytics. Describe people and things by role, such as "a customer". Do not '
+ "quote the user or include names, emails, or other personal details."
)
DEFAULT_CONVERSATION_ID_DESCRIPTION = (
- "Pass the exact conversation_id from the server's previous response, unchanged. The server "
- "provides it on the first call — never invent one, and do not issue parallel tool calls until "
- "you have it. Keep passing the same conversation_id for the rest of the conversation, including "
- "after later user messages or on a different task; do not reset it when the user starts a new "
- "request."
+ "The conversation_id this server returned earlier in this conversation, unchanged, including "
+ "after later user messages. Omit it if you have none. Recorded for the server developer's "
+ "analytics."
)
DEFAULT_MODEL_PARAMETER_DESCRIPTION = (
- "The exact model identifier you (the assistant) are running as, taken from your "
- 'system prompt or environment (e.g. "claude-opus-4-8", "gpt-5.2"). Used for '
- 'analytics only. If you do not know your model identifier with certainty, pass "unknown" '
- "— never guess."
+ 'The model identifier you are running as, for example "claude-opus-4-8" or "gpt-5.2". '
+ 'Pass "unknown" if you are not certain. Recorded for the server developer\'s analytics.'
)
POSTHOG_MCP_ANALYTICS_SOURCE = "posthog_mcp_analytics"
diff --git a/posthog/mcp/feedback.py b/posthog/mcp/feedback.py
index fcba7fad1..5cb732b6c 100644
--- a/posthog/mcp/feedback.py
+++ b/posthog/mcp/feedback.py
@@ -11,8 +11,10 @@
from ._internal import _maybe_await
from ._sanitization import sanitize_free_text, sanitize_free_text_value
+from ._truncation import truncate_text
from .constants import PostHogMCPAnalyticsProperty
from .logger import log
+from .tools import VIRTUAL_TOOL_HINTS
from .types import CollectFeedbackOptions, FeedbackReport, JsonRecord
__all__ = ["SEND_FEEDBACK_TOOL_NAME", "send_feedback_result"]
@@ -25,14 +27,11 @@
# Free-text fields are agent-narrated, like `$mcp_intent`; bound them the same way.
_MAX_FEEDBACK_TEXT_LENGTH = 2048
_MAX_FEEDBACK_TOOL_NAME_LENGTH = 256
-_TRUNCATION_SUFFIX = "..."
_DEFAULT_FEEDBACK_DESCRIPTION = (
- "Send feedback about this server to its developers. Most important: report a missing "
- "capability whenever no available tool fits your task, even if you can work around it "
- '(feedback_type "missing_capability"). Also welcome: a tool that failed or confused you, '
- "an unhelpful error, or something that worked well. This records the feedback; it does "
- "not add or change tools. Do not include user PII or sensitive content."
+ "Send feedback about this server to its developers: a capability you needed that no tool "
+ "provides, a tool that failed or misled you, or something that worked well. Records the "
+ "feedback; it does not add or change tools. Leave out personal or sensitive details."
)
_SEND_FEEDBACK_RESULT_TEXT = (
@@ -47,8 +46,7 @@
"description": (
"What kind of feedback this is. Use 'missing_capability' when the tool you "
"needed does not exist in the tool list - nothing failed, the capability is "
- "absent (this is the most valuable report; send it even if you found a "
- "workaround). Use 'issue' when an existing tool behaved badly: it failed, "
+ "absent. Use 'issue' when an existing tool behaved badly: it failed, "
"returned a confusing error, or its description or schema misled you. Use "
"'praise' when something worked notably well. Use 'other' for anything else."
),
@@ -171,17 +169,7 @@ def get_feedback_tool_descriptor(
"properties": properties,
"required": ["feedback_type", "summary", *extra_required],
},
- "annotations": {
- "title": "Send feedback",
- "readOnlyHint": True,
- # Interacts with an external entity: the report lands in analytics.
- "openWorldHint": True,
- # Only records the feedback, so repeat calls are harmless — and
- # advertising it as idempotent makes agents more willing to call it
- # proactively.
- "idempotentHint": True,
- "destructiveHint": False,
- },
+ "annotations": dict(VIRTUAL_TOOL_HINTS),
}
@@ -259,10 +247,6 @@ def build_feedback_intent(report: FeedbackReport) -> str:
return "\n\n".join(part for part in (report.summary, report.details) if part)
-def _truncate_feedback_text(value: str, max_length: int) -> str:
- return value[:max_length] + _TRUNCATION_SUFFIX if len(value) > max_length else value
-
-
def _capture_free_text(value: str) -> str:
"""Agent-narrated free text can contain a secret the LLM read aloud or personal
data it narrated, so it gets exactly the ``$mcp_intent`` pass
@@ -270,7 +254,7 @@ def _capture_free_text(value: str) -> str:
load-bearing, the URL rewrite would percent-encode the ``@`` the email pattern
anchors on), then a length bound. The event pipeline does not process
``event["properties"]``, so this happens here."""
- return _truncate_feedback_text(sanitize_free_text(value), _MAX_FEEDBACK_TEXT_LENGTH)
+ return truncate_text(sanitize_free_text(value), _MAX_FEEDBACK_TEXT_LENGTH)
def _capture_extra_value(value: Any) -> Any:
@@ -280,11 +264,11 @@ def _capture_extra_value(value: Any) -> Any:
JSON-stringified and everything is bounded. Unserializable values are dropped."""
sanitized = sanitize_free_text_value(value)
if isinstance(sanitized, str):
- return _truncate_feedback_text(sanitized, _MAX_FEEDBACK_TEXT_LENGTH)
+ return truncate_text(sanitized, _MAX_FEEDBACK_TEXT_LENGTH)
if sanitized is None or isinstance(sanitized, (bool, int, float)):
return sanitized
try:
- return _truncate_feedback_text(json.dumps(sanitized), _MAX_FEEDBACK_TEXT_LENGTH)
+ return truncate_text(json.dumps(sanitized), _MAX_FEEDBACK_TEXT_LENGTH)
except Exception: # noqa: BLE001 - capture must never raise into the tool path
return None
@@ -317,7 +301,7 @@ def build_feedback_event_properties(report: FeedbackReport) -> JsonRecord:
# Nominally an identifier, but the schema can't stop an agent from
# writing prose into it — so it gets the same free-text pass as the
# other fields.
- properties[PostHogMCPAnalyticsProperty.FEEDBACK_TOOL] = _truncate_feedback_text(
+ properties[PostHogMCPAnalyticsProperty.FEEDBACK_TOOL] = truncate_text(
sanitize_free_text(report.tool_name),
_MAX_FEEDBACK_TOOL_NAME_LENGTH,
)
diff --git a/posthog/mcp/posthog_mcp.py b/posthog/mcp/posthog_mcp.py
index f7ebd90fe..c424ca012 100644
--- a/posthog/mcp/posthog_mcp.py
+++ b/posthog/mcp/posthog_mcp.py
@@ -69,7 +69,7 @@
resolve_collect_feedback_options,
resolve_send_feedback_tool_name,
)
-from .session import derive_session_id_from_conversation
+from .session import derive_session_id_from_conversation, new_session_id
from .tools import build_report_missing_descriptor
from .types import (
CollectFeedbackOptions,
@@ -744,7 +744,7 @@ def _base_event(
) -> Dict[str, Any]:
event: Dict[str, Any] = {
"event_type": event_type,
- "session_id": session_id,
+ "session_id": session_id or new_session_id(),
"conversation_id": conversation_id,
"timestamp": timestamp or datetime.now(timezone.utc),
"properties": properties,
diff --git a/posthog/mcp/tools.py b/posthog/mcp/tools.py
index ef59b7a28..36222bf96 100644
--- a/posthog/mcp/tools.py
+++ b/posthog/mcp/tools.py
@@ -16,6 +16,16 @@
GET_MORE_TOOLS_NAME = "get_more_tools"
+# A call records one event in the server owner's PostHog project: a write
+# outside the conversation that deletes nothing, repeats on every call, and
+# reaches only that project. Fixed so host configuration cannot misdeclare it.
+VIRTUAL_TOOL_HINTS = {
+ "readOnlyHint": False,
+ "destructiveHint": False,
+ "idempotentHint": False,
+ "openWorldHint": False,
+}
+
_GET_MORE_TOOLS_RESULT_TEXT = (
"Unfortunately, we have shown you the full tool list. We have noted your feedback "
"and will work to improve the tool list in the future."
@@ -39,8 +49,8 @@ def build_report_missing_descriptor(name: str = GET_MORE_TOOLS_NAME) -> Dict[str
return {
"name": name,
"description": (
- "Check for additional tools whenever your task might benefit from specialized "
- "capabilities - even if existing tools could work as a fallback."
+ "Report that the user's request needs a capability this server does not have. "
+ "Records the report for the server's developers; it does not return or add tools."
),
"inputSchema": {
"type": "object",
@@ -52,13 +62,7 @@ def build_report_missing_descriptor(name: str = GET_MORE_TOOLS_NAME) -> Dict[str
},
"required": ["context"],
},
- "annotations": {
- "title": "Get More Tools",
- "readOnlyHint": True,
- "openWorldHint": True,
- "idempotentHint": True,
- "destructiveHint": False,
- },
+ "annotations": dict(VIRTUAL_TOOL_HINTS),
}
diff --git a/posthog/request.py b/posthog/request.py
index e8dbd4725..ee8702253 100644
--- a/posthog/request.py
+++ b/posthog/request.py
@@ -12,6 +12,7 @@
import requests
from requests.adapters import HTTPAdapter
from urllib3.connection import HTTPConnection
+from urllib3.exceptions import NewConnectionError
from urllib3.util.retry import Retry
from posthog._logging import _configure_posthog_logging
@@ -318,6 +319,29 @@ def _process_response(
raise APIError(res.status_code, res.text, retry_after=retry_after)
+def _is_connection_refused(exc: BaseException) -> bool:
+ """Return True when a requests transport error wraps a refused connection."""
+ pending: List[Any] = [exc]
+ seen = set()
+ while pending:
+ current = pending.pop()
+ if current is None or id(current) in seen:
+ continue
+ seen.add(id(current))
+ if isinstance(current, ConnectionRefusedError):
+ return True
+ if isinstance(current, BaseException):
+ pending.extend(current.args)
+ pending.append(current.__cause__)
+ # __context__ records whatever exception was being handled, which may
+ # have nothing to do with this request. urllib3 1.x only links the
+ # socket error to NewConnectionError that way, so follow it just there.
+ if isinstance(current, NewConnectionError):
+ pending.append(current.__context__)
+ pending.append(getattr(current, "reason", None))
+ return False
+
+
def _feature_flags_retry_delay(failed_attempt: int) -> float:
return _FEATURE_FLAGS_RETRY_BACKOFF_SECONDS * (2**failed_attempt)
@@ -347,8 +371,12 @@ def flags(
return _process_response(
res, success_message="Feature flags evaluated successfully"
)
- except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
- if failed_attempt >= retries:
+ except (
+ requests.exceptions.ConnectionError,
+ requests.exceptions.Timeout,
+ ) as exc:
+ # A refused connection is not transient, so it is not retried.
+ if failed_attempt >= retries or _is_connection_refused(exc):
raise
except APIError as exc:
if (
diff --git a/posthog/test/ai/anthropic/test_anthropic.py b/posthog/test/ai/anthropic/test_anthropic.py
index 2b846cd3d..e3351e934 100644
--- a/posthog/test/ai/anthropic/test_anthropic.py
+++ b/posthog/test/ai/anthropic/test_anthropic.py
@@ -912,6 +912,70 @@ async def mock_async_create(**kwargs):
assert_cumulative_delta_usage(mock_client.capture_ai.call_args.kwargs["properties"])
+def anthropic_stream_with_thinking_tokens():
+ from types import SimpleNamespace
+
+ events = anthropic_stream_with_server_tool_usage()
+ events[1] = SimpleNamespace(
+ type="message_delta",
+ delta=events[1].delta,
+ usage=SimpleNamespace(
+ input_tokens=10,
+ output_tokens=110,
+ cache_creation_input_tokens=0,
+ cache_read_input_tokens=0,
+ server_tool_use=None,
+ output_tokens_details=SimpleNamespace(thinking_tokens=40),
+ ),
+ )
+ return events
+
+
+def test_streaming_reports_thinking_tokens_as_reasoning_tokens(mock_client):
+ with patch(
+ "anthropic.resources.Messages.create",
+ return_value=iter(anthropic_stream_with_thinking_tokens()),
+ ):
+ client = Anthropic(api_key="test-key", posthog_client=mock_client)
+ response = client.messages.create(
+ model="claude-haiku-4-5",
+ messages=[{"role": "user", "content": "Hello"}],
+ stream=True,
+ )
+ list(response)
+
+ props = mock_client.capture_ai.call_args.kwargs["properties"]
+ assert props["$ai_output_tokens"] == 110
+ assert props["$ai_reasoning_tokens"] == 40
+
+
+@pytest.mark.asyncio
+async def test_streaming_reports_thinking_tokens_as_reasoning_tokens_async(
+ mock_client,
+):
+ async def mock_async_stream():
+ for event in anthropic_stream_with_thinking_tokens():
+ yield event
+
+ async def mock_async_create(**kwargs):
+ return mock_async_stream()
+
+ with patch(
+ "anthropic.resources.messages.AsyncMessages.create",
+ side_effect=mock_async_create,
+ ):
+ client = AsyncAnthropic(api_key="test-key", posthog_client=mock_client)
+ response = await client.messages.create(
+ model="claude-haiku-4-5",
+ messages=[{"role": "user", "content": "Hello"}],
+ stream=True,
+ )
+ [event async for event in response]
+
+ props = mock_client.capture_ai.call_args.kwargs["properties"]
+ assert props["$ai_reasoning_tokens"] == 40
+
+
def anthropic_stream_with_two_cumulative_deltas():
# Server tools can emit more than one message_delta in a single stream,
# and each delta's usage is cumulative: later values replace earlier ones
diff --git a/posthog/test/ai/anthropic/test_anthropic_converter.py b/posthog/test/ai/anthropic/test_anthropic_converter.py
index 15aaeaa6c..aef31a03a 100644
--- a/posthog/test/ai/anthropic/test_anthropic_converter.py
+++ b/posthog/test/ai/anthropic/test_anthropic_converter.py
@@ -157,3 +157,59 @@ def test_streaming_thinking_deltas_accumulate():
],
}
]
+
+
+def test_response_usage_maps_thinking_tokens_to_reasoning_tokens():
+ from types import SimpleNamespace
+
+ from posthog.ai.anthropic.anthropic_converter import (
+ extract_anthropic_usage_from_response,
+ )
+
+ response = SimpleNamespace(
+ usage=SimpleNamespace(
+ input_tokens=10,
+ output_tokens=50,
+ output_tokens_details=SimpleNamespace(thinking_tokens=30),
+ ),
+ content=[],
+ )
+ usage = extract_anthropic_usage_from_response(response)
+ assert usage["output_tokens"] == 50
+ assert usage["reasoning_tokens"] == 30
+
+
+def test_response_usage_null_output_tokens_details_is_absent():
+ from types import SimpleNamespace
+
+ from posthog.ai.anthropic.anthropic_converter import (
+ extract_anthropic_usage_from_response,
+ )
+
+ response = SimpleNamespace(
+ usage=SimpleNamespace(
+ input_tokens=10, output_tokens=50, output_tokens_details=None
+ ),
+ content=[],
+ )
+ assert "reasoning_tokens" not in extract_anthropic_usage_from_response(response)
+
+
+def test_stream_message_delta_thinking_tokens_not_double_counted():
+ from types import SimpleNamespace
+
+ from posthog.ai.anthropic._anthropic_stream import _AnthropicStreamAccumulator
+
+ acc = _AnthropicStreamAccumulator()
+ for output, thinking in [(20, 10), (50, 30)]:
+ acc.consume(
+ SimpleNamespace(
+ type="message_delta",
+ usage=SimpleNamespace(
+ output_tokens=output,
+ output_tokens_details=SimpleNamespace(thinking_tokens=thinking),
+ ),
+ )
+ )
+ assert acc.usage_stats["output_tokens"] == 50
+ assert acc.usage_stats["reasoning_tokens"] == 30
diff --git a/posthog/test/ai/langchain/test_callbacks.py b/posthog/test/ai/langchain/test_callbacks.py
index 55e5dde6d..10df3378a 100644
--- a/posthog/test/ai/langchain/test_callbacks.py
+++ b/posthog/test/ai/langchain/test_callbacks.py
@@ -1736,6 +1736,93 @@ def test_anthropic_provider_subtracts_cache_tokens(mock_client):
assert generation_args["properties"]["$ai_cache_read_input_tokens"] == 800
+def test_chat_anthropic_invoke_does_not_subtract_cache_tokens_twice(mock_client):
+ """ChatAnthropic.invoke puts the raw API usage, whose input_tokens already
+ exclude the cache, in response_metadata next to the standard usage_metadata."""
+ from langchain_core.outputs import LLMResult, ChatGeneration
+ from langchain_core.messages import AIMessage
+ from uuid import uuid4
+
+ cb = CallbackHandler(mock_client)
+ run_id = uuid4()
+ cb._set_llm_metadata(
+ serialized={},
+ run_id=run_id,
+ messages=[{"role": "user", "content": "test"}],
+ metadata={"ls_provider": "anthropic", "ls_model_name": "claude-sonnet-4-5"},
+ )
+
+ # The message ChatAnthropic.invoke returns for a cached prompt
+ message = AIMessage(
+ content="Response",
+ response_metadata={
+ "id": "msg_1",
+ "model": "claude-sonnet-4-5",
+ "stop_reason": "end_turn",
+ "usage": {
+ "input_tokens": 10,
+ "output_tokens": 7,
+ "cache_creation_input_tokens": 100,
+ "cache_read_input_tokens": 1000,
+ },
+ "model_provider": "anthropic",
+ },
+ usage_metadata={
+ "input_tokens": 1110,
+ "output_tokens": 7,
+ "total_tokens": 1117,
+ "input_token_details": {"cache_read": 1000, "cache_creation": 100},
+ },
+ )
+ response = LLMResult(generations=[[ChatGeneration(message=message)]])
+
+ cb._pop_run_and_capture_generation(run_id, None, response)
+
+ props = mock_client.capture_ai.call_args_list[0][1]["properties"]
+ assert props["$ai_input_tokens"] == 10
+ assert props["$ai_output_tokens"] == 7
+ assert props["$ai_cache_read_input_tokens"] == 1000
+ assert props["$ai_cache_creation_input_tokens"] == 100
+
+
+def test_claude_on_vertex_subtracts_cache_tokens(mock_client):
+ """ChatAnthropicVertex reports provider "anthropicvertex" and a bare Claude
+ model name. Its usage_metadata input_tokens include the cache, like
+ ChatAnthropic's, and PostHog prices claude-* models Anthropic-style."""
+ from langchain_core.outputs import LLMResult, ChatGeneration
+ from langchain_core.messages import AIMessage
+ from uuid import uuid4
+
+ cb = CallbackHandler(mock_client)
+ run_id = uuid4()
+ cb._set_llm_metadata(
+ serialized={},
+ run_id=run_id,
+ messages=[{"role": "user", "content": "test"}],
+ metadata={
+ "ls_provider": "anthropicvertex",
+ "ls_model_name": "claude-sonnet-4-5@20250929",
+ },
+ )
+ message = AIMessage(
+ content="Response",
+ usage_metadata={
+ "input_tokens": 1110,
+ "output_tokens": 7,
+ "total_tokens": 1117,
+ "input_token_details": {"cache_read": 1000, "cache_creation": 100},
+ },
+ )
+ response = LLMResult(generations=[[ChatGeneration(message=message)]])
+
+ cb._pop_run_and_capture_generation(run_id, None, response)
+
+ props = mock_client.capture_ai.call_args_list[0][1]["properties"]
+ assert props["$ai_input_tokens"] == 10
+ assert props["$ai_cache_read_input_tokens"] == 1000
+ assert props["$ai_cache_creation_input_tokens"] == 100
+
+
def test_anthropic_provider_subtracts_cache_write_tokens(mock_client):
"""Test that Anthropic provider correctly subtracts cache write tokens from input tokens."""
from langchain_core.outputs import LLMResult, ChatGeneration
@@ -2733,6 +2820,26 @@ def failing_span(_):
assert span_props["$ai_error"] == "ValueError: test error"
+def test_exception_autocapture_absent_on_client_still_sends_the_span():
+ """A client without the autocapture setting, such as AsyncPosthog, still gets the failed span."""
+ mock_client = MagicMock(spec=["capture_ai", "capture_exception", "privacy_mode"])
+ mock_client.privacy_mode = False
+
+ def failing_span(_):
+ raise ValueError("test error")
+
+ callbacks = [CallbackHandler(mock_client)]
+ with pytest.raises(ValueError):
+ RunnableLambda(failing_span).invoke({}, config={"callbacks": callbacks})
+
+ assert mock_client.capture_exception.call_count == 0
+ assert mock_client.capture_ai.call_count == 1
+ span_props = mock_client.capture_ai.call_args[1]["properties"]
+ assert span_props["$ai_is_error"] is True
+ assert span_props["$ai_error"] == "ValueError: test error"
+ assert "$exception_event_id" not in span_props
+
+
@pytest.mark.parametrize(
"autocapture, client_privacy_mode, handler_privacy_mode, expected_error",
[
diff --git a/posthog/test/ai/test_stream_midstream_error.py b/posthog/test/ai/test_stream_midstream_error.py
index 2355ba205..fec3fbbf8 100644
--- a/posthog/test/ai/test_stream_midstream_error.py
+++ b/posthog/test/ai/test_stream_midstream_error.py
@@ -267,3 +267,266 @@ async def stream():
props = _props(mock_client)
assert props["$ai_is_error"] is True
assert props["$ai_http_status"] == 0
+
+
+class _ConnectError(RuntimeError):
+ status_code = 401
+
+
+def test_openai_chat_stream_connect_error(mock_client):
+ from posthog.ai.openai import OpenAI
+
+ with patch("openai.resources.chat.completions.Completions.create") as create:
+ create.side_effect = _ConnectError("bad key")
+ client = OpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.chat.completions.create(
+ model="gpt-4",
+ messages=[{"role": "user", "content": "hi"}],
+ stream=True,
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+@pytest.mark.asyncio
+async def test_openai_chat_stream_connect_error_async(mock_client):
+ from posthog.ai.openai import AsyncOpenAI
+
+ async def create(**kwargs):
+ raise _ConnectError("bad key")
+
+ with patch(
+ "openai.resources.chat.completions.AsyncCompletions.create", side_effect=create
+ ):
+ client = AsyncOpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.chat.completions.create(
+ model="gpt-4",
+ messages=[{"role": "user", "content": "hi"}],
+ stream=True,
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+def test_openai_responses_stream_connect_error(mock_client):
+ from posthog.ai.openai import OpenAI
+
+ with patch("openai.resources.responses.Responses.create") as create:
+ create.side_effect = _ConnectError("bad key")
+ client = OpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.responses.create(model="gpt-4", input="hi", stream=True)
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+@pytest.mark.asyncio
+async def test_openai_responses_stream_connect_error_async(mock_client):
+ from posthog.ai.openai import AsyncOpenAI
+
+ async def create(**kwargs):
+ raise _ConnectError("bad key")
+
+ with patch("openai.resources.responses.AsyncResponses.create", side_effect=create):
+ client = AsyncOpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.responses.create(model="gpt-4", input="hi", stream=True)
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+def test_anthropic_stream_connect_error(mock_client):
+ from posthog.ai.anthropic import Anthropic
+
+ with patch("anthropic.resources.messages.Messages.create") as create:
+ create.side_effect = _ConnectError("bad key")
+ client = Anthropic(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.messages.create(
+ model="claude-3-opus-20240229",
+ messages=[{"role": "user", "content": "hi"}],
+ max_tokens=5,
+ stream=True,
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+@pytest.mark.asyncio
+async def test_anthropic_stream_connect_error_async(mock_client):
+ from posthog.ai.anthropic import AsyncAnthropic
+
+ async def create(**kwargs):
+ raise _ConnectError("bad key")
+
+ with patch("anthropic.resources.messages.AsyncMessages.create", side_effect=create):
+ client = AsyncAnthropic(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.messages.create(
+ model="claude-3-opus-20240229",
+ messages=[{"role": "user", "content": "hi"}],
+ max_tokens=5,
+ stream=True,
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+def test_gemini_stream_connect_error(mock_client):
+ pytest.importorskip("google.genai")
+ from google import genai as google_genai
+
+ from posthog.ai.gemini import Client
+
+ with patch.object(google_genai, "Client") as cls:
+ inst = MagicMock()
+ cls.return_value = inst
+ inst.models.generate_content_stream.side_effect = _ConnectError("bad key")
+ client = Client(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.models.generate_content_stream(
+ model="gemini-2.0-flash", contents=["hi"]
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+@pytest.mark.asyncio
+async def test_gemini_stream_connect_error_async(mock_client):
+ pytest.importorskip("google.genai")
+ from google import genai as google_genai
+
+ from posthog.ai.gemini import AsyncClient
+
+ with patch.object(google_genai, "Client") as cls:
+ inst = MagicMock()
+ cls.return_value = inst
+ inst.aio.models.generate_content_stream = AsyncMock(
+ side_effect=_ConnectError("bad key")
+ )
+ client = AsyncClient(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.models.generate_content_stream(
+ model="gemini-2.0-flash", contents=["hi"]
+ )
+
+ props = _props(mock_client)
+ assert props["$ai_is_error"] is True
+ assert props["$ai_http_status"] == 401
+
+
+@pytest.mark.parametrize(
+ ("cls_name", "code"), [("ClientError", 429), ("ServerError", 503)]
+)
+def test_capture_streaming_event_records_google_genai_error_status(
+ mock_client, cls_name, code
+):
+ errors = pytest.importorskip("google.genai.errors")
+ error = getattr(errors, cls_name)(
+ code, {"error": {"code": code, "message": "nope", "status": "ERROR"}}
+ )
+ capture_streaming_event(mock_client, _event_data(error=error))
+ props = _props(mock_client)
+ assert props["$ai_http_status"] == code
+ assert props["$ai_is_error"] is True
+
+
+def test_anthropic_stream_connect_error_survives_unformattable_input(mock_client):
+ from posthog.ai.anthropic import Anthropic
+
+ with patch("anthropic.resources.messages.Messages.create") as create:
+ create.side_effect = _ConnectError("bad request")
+ client = Anthropic(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.messages.create(
+ model="claude-3-opus-20240229",
+ messages=[None],
+ max_tokens=5,
+ stream=True,
+ )
+
+
+@pytest.mark.asyncio
+async def test_anthropic_stream_connect_error_survives_unformattable_input_async(
+ mock_client,
+):
+ from posthog.ai.anthropic import AsyncAnthropic
+
+ async def create(**kwargs):
+ raise _ConnectError("bad request")
+
+ with patch("anthropic.resources.messages.AsyncMessages.create", side_effect=create):
+ client = AsyncAnthropic(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.messages.create(
+ model="claude-3-opus-20240229",
+ messages=[None],
+ max_tokens=5,
+ stream=True,
+ )
+
+
+def test_openai_chat_stream_connect_error_survives_unformattable_input(mock_client):
+ from posthog.ai.openai import OpenAI
+
+ with patch("openai.resources.chat.completions.Completions.create") as create:
+ create.side_effect = _ConnectError("bad request")
+ client = OpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ client.chat.completions.create(model="gpt-4", messages=123, stream=True)
+
+
+@pytest.mark.asyncio
+async def test_openai_chat_stream_connect_error_survives_unformattable_input_async(
+ mock_client,
+):
+ from posthog.ai.openai import AsyncOpenAI
+
+ async def create(**kwargs):
+ raise _ConnectError("bad request")
+
+ with patch(
+ "openai.resources.chat.completions.AsyncCompletions.create", side_effect=create
+ ):
+ client = AsyncOpenAI(api_key="k", posthog_client=mock_client)
+ with pytest.raises(_ConnectError):
+ await client.chat.completions.create(
+ model="gpt-4", messages=123, stream=True
+ )
+
+
+def test_anthropic_connect_error_fallback_does_not_log_error_text(mock_client, caplog):
+ from posthog.ai.anthropic import Anthropic
+
+ with patch("anthropic.resources.messages.Messages.create") as create:
+ create.side_effect = _ConnectError("rejected PRIVATE_CANARY")
+ client = Anthropic(api_key="k", posthog_client=mock_client)
+ with caplog.at_level("DEBUG", logger="posthog"):
+ with pytest.raises(_ConnectError):
+ client.messages.create(
+ model="claude-3-opus-20240229",
+ messages=[None],
+ max_tokens=5,
+ stream=True,
+ posthog_privacy_mode=True,
+ )
+
+ assert "Failed to capture streaming connect error" in caplog.text
+ assert "PRIVATE_CANARY" not in caplog.text
+ assert all(r.exc_info is None for r in caplog.records)
diff --git a/posthog/test/fixtures/feature_flag_rules_v2/SOURCE.json b/posthog/test/fixtures/feature_flag_rules_v2/SOURCE.json
index df7f1c7e0..8274761b1 100644
--- a/posthog/test/fixtures/feature_flag_rules_v2/SOURCE.json
+++ b/posthog/test/fixtures/feature_flag_rules_v2/SOURCE.json
@@ -1,14 +1,14 @@
{
"description": "Copied unchanged from the released feature flag rules v2 contract in PostHog/posthog-sdk-test-harness. Do not edit these files; copy a newer release instead.",
"repository": "https://github.com/PostHog/posthog-sdk-test-harness",
- "release": "1.22.0",
- "revision": "17d861f8e230fe943934d70e3eebf5cff6bf3aa4",
+ "release": "1.30.0",
+ "revision": "6414114501396d96aadf2412fdd8054a03076782",
"contract_directory": "contracts/feature_flag_rules_v2",
- "contract_version": "7.0.0",
+ "contract_version": "10.0.0",
"files": {
"readers.json": {
"source_path": "fixtures/wire/readers.json",
- "sha256": "fd8edd89f827b732c4659ce7246eab534b0106b96a465a4a2d98cfa0a17d7827"
+ "sha256": "e75abb9bf6656989a147dda4c6e5232e7b544b657d7d540164dce65688641501"
},
"responses.json": {
"source_path": "fixtures/wire/responses.json",
@@ -21,6 +21,14 @@
"v2_value_evaluation.json": {
"source_path": "corpus/v2_value_evaluation.json",
"sha256": "aaddd05e47fc5a4ae07ea42ada5a659798f4b5fc8d0c0827f6a68e4daf68c128"
+ },
+ "feature_flag_called_context.schema.json": {
+ "source_path": "schemas/feature_flag_called_context.schema.json",
+ "sha256": "8a475f5ab56ba4dba76501c4a4e23f26b62c2c2f8037f23d21d0ea7650bd2cf8"
+ },
+ "experiment_exposure_properties.schema.json": {
+ "source_path": "schemas/experiment_exposure_properties.schema.json",
+ "sha256": "4b1af8fc98b6f6cb49f974970eb289ca85a78a978e1e74fc4d417eee9adee449"
}
}
}
diff --git a/posthog/test/fixtures/feature_flag_rules_v2/experiment_exposure_properties.schema.json b/posthog/test/fixtures/feature_flag_rules_v2/experiment_exposure_properties.schema.json
new file mode 100644
index 000000000..ee8604e38
--- /dev/null
+++ b/posthog/test/fixtures/feature_flag_rules_v2/experiment_exposure_properties.schema.json
@@ -0,0 +1,50 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "$id": "https://posthog.com/contracts/feature_flag_rules_v2/experiment_exposure_properties.schema.json",
+ "title": "SDK-sent $experiment_exposure properties",
+ "type": "object",
+ "additionalProperties": false,
+ "required": [
+ "$feature_flag",
+ "$feature_flag_response",
+ "$feature_flag_variant_key",
+ "$feature_flag_rule_id",
+ "locally_evaluated"
+ ],
+ "properties": {
+ "$feature_flag": {
+ "type": "string",
+ "minLength": 1
+ },
+ "$feature_flag_response": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "minLength": 1
+ }
+ ]
+ },
+ "$feature_flag_variant_key": {
+ "type": "string"
+ },
+ "$feature_flag_rule_id": {
+ "type": "string",
+ "format": "uuid"
+ },
+ "locally_evaluated": {
+ "type": "boolean"
+ },
+ "$feature_flag_forced_variant": {
+ "const": true
+ }
+ },
+ "description": "Closed projection of the properties of an SDK-sent exposure. The SDK sends it only for a config version 2 experiment split, so it carries no config version, rule type, reason code or source marker; the rule ID marks it as SDK-sent. Experiment ID and forced-variant context are forbidden. Capture identity and existing optional transport properties are outside this projection. Scan the entire event recursively for assignment seeds.",
+ "not": {
+ "required": [
+ "$feature_flag_forced_variant"
+ ]
+ }
+}
diff --git a/posthog/test/fixtures/feature_flag_rules_v2/feature_flag_called_context.schema.json b/posthog/test/fixtures/feature_flag_rules_v2/feature_flag_called_context.schema.json
new file mode 100644
index 000000000..1829dde76
--- /dev/null
+++ b/posthog/test/fixtures/feature_flag_rules_v2/feature_flag_called_context.schema.json
@@ -0,0 +1,692 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "$id": "https://posthog.com/contracts/feature_flag_rules_v2/feature_flag_called_context.schema.json",
+ "title": "$feature_flag_called context properties",
+ "type": "object",
+ "additionalProperties": false,
+ "required": [
+ "$feature_flag",
+ "$feature_flag_response"
+ ],
+ "properties": {
+ "$feature_flag": {
+ "type": "string",
+ "minLength": 1
+ },
+ "$feature_flag_response": {
+ "oneOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "string",
+ "minLength": 1
+ }
+ ]
+ },
+ "$feature_flag_config_version": {
+ "enum": [
+ 1,
+ 2
+ ]
+ },
+ "$feature_flag_variant_key": {
+ "type": "string"
+ },
+ "$feature_flag_rule_id": {
+ "type": "string",
+ "format": "uuid"
+ },
+ "$feature_flag_rule_type": {
+ "enum": [
+ "targeted_release",
+ "percentage_rollout",
+ "experiment"
+ ]
+ },
+ "$feature_flag_experiment_id": {
+ "type": "integer"
+ },
+ "$feature_flag_reason_code": {
+ "type": "string",
+ "minLength": 1
+ },
+ "$feature_flag_reason": {},
+ "$feature_flag_forced_variant": {
+ "const": true
+ }
+ },
+ "description": "Closed projection of the flag-access context properties. Other existing capture fields are outside this projection. Complete v2 producer context follows the terminal outcome. A tolerant reader drops the whole attribution of a record that breaks its reason's rows (a rule ID without its rule type or the reverse, a rule type the reason does not allow, or a malformed split): for every reason that names a rule, a call may keep the config version and reason code and omit all rule, variant and experiment attribution, while a partly populated or mismatched tuple is rejected. A config version 2 call whose reason code is missing or not registered keeps the raw code, if any, and carries no attribution; a registered code only matches its own reason's branches. A config version 2 call never carries $feature_flag_reason, the reason description that only version 1 calls carry.",
+ "allOf": [
+ {
+ "if": {
+ "required": [
+ "$feature_flag_config_version"
+ ],
+ "properties": {
+ "$feature_flag_config_version": {
+ "const": 2
+ }
+ }
+ },
+ "then": {
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_forced_variant"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_reason"
+ ]
+ }
+ ]
+ },
+ "oneOf": [
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "targeting_match"
+ },
+ "$feature_flag_rule_type": {
+ "const": "targeted_release"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "targeting_match"
+ },
+ "$feature_flag_rule_type": {
+ "const": "percentage_rollout"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "experiment_split"
+ },
+ "$feature_flag_rule_type": {
+ "const": "experiment"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id",
+ "$feature_flag_variant_key"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "rollout_miss"
+ },
+ "$feature_flag_rule_type": {
+ "const": "percentage_rollout"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "rollout_miss"
+ },
+ "$feature_flag_rule_type": {
+ "const": "experiment"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "experiment_paused"
+ },
+ "$feature_flag_rule_type": {
+ "const": "experiment"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "holdout"
+ },
+ "$feature_flag_rule_type": {
+ "const": "experiment"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_type",
+ "$feature_flag_rule_id"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "no_rule_match"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "missing_group_key"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "dependency_error"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "error"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "targeting_match"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "experiment_split"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "rollout_miss"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "experiment_paused"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "holdout"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "properties": {
+ "$feature_flag_reason_code": {
+ "not": {
+ "enum": [
+ "targeting_match",
+ "experiment_split",
+ "rollout_miss",
+ "experiment_paused",
+ "holdout",
+ "no_rule_match",
+ "missing_group_key",
+ "dependency_error",
+ "error",
+ "flag_disabled"
+ ]
+ }
+ }
+ },
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "description": "A local-only outcome with no matrix row: the server never returns flag_disabled, and the call carries no rule or experiment attribution.",
+ "properties": {
+ "$feature_flag_reason_code": {
+ "const": "flag_disabled"
+ }
+ },
+ "required": [
+ "$feature_flag_reason_code"
+ ],
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_experiment_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_variant_key"
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "else": {
+ "not": {
+ "anyOf": [
+ {
+ "required": [
+ "$feature_flag_rule_id"
+ ]
+ },
+ {
+ "required": [
+ "$feature_flag_rule_type"
+ ]
+ }
+ ]
+ }
+ }
+ }
+ ]
+}
diff --git a/posthog/test/fixtures/feature_flag_rules_v2/readers.json b/posthog/test/fixtures/feature_flag_rules_v2/readers.json
index 7ed8c252b..add97e172 100644
--- a/posthog/test/fixtures/feature_flag_rules_v2/readers.json
+++ b/posthog/test/fixtures/feature_flag_rules_v2/readers.json
@@ -992,7 +992,10 @@
"value": "compact",
"config_version": 1,
"experiment_exposure": false,
- "error_code": null
+ "error_code": null,
+ "legacy_payload": {
+ "columns": 2
+ }
},
"producer_expected": "valid"
},
@@ -1018,7 +1021,8 @@
"value": true,
"config_version": 1,
"experiment_exposure": false,
- "error_code": "GENERAL"
+ "error_code": "GENERAL",
+ "legacy_payload": null
},
"producer_expected": "valid"
},
diff --git a/posthog/test/fixtures/released_flags_7_82_1.json b/posthog/test/fixtures/released_flags_7_82_1.json
index 627f5336e..2856b2f18 100644
--- a/posthog/test/fixtures/released_flags_7_82_1.json
+++ b/posthog/test/fixtures/released_flags_7_82_1.json
@@ -990,6 +990,9 @@
"$feature_flag_evaluated_at": 1800000000000,
"$feature_flag_has_experiment": false,
"$feature_flag_id": 700,
+ "$feature_flag_payload": {
+ "columns": 2
+ },
"$feature_flag_reason": "Matched condition set 1",
"$feature_flag_request_id": "60000000-0000-4000-8000-000000000000",
"$feature_flag_response": false,
@@ -1005,6 +1008,9 @@
"$feature_flag_evaluated_at": 1800000000000,
"$feature_flag_has_experiment": false,
"$feature_flag_id": 700,
+ "$feature_flag_payload": {
+ "columns": 2
+ },
"$feature_flag_reason": "Matched condition set 1",
"$feature_flag_request_id": "60000000-0000-4000-8000-000000000000",
"$feature_flag_response": false,
@@ -1020,6 +1026,9 @@
"$feature_flag_evaluated_at": 1800000000000,
"$feature_flag_has_experiment": false,
"$feature_flag_id": 700,
+ "$feature_flag_payload": {
+ "columns": 2
+ },
"$feature_flag_reason": "Matched condition set 1",
"$feature_flag_request_id": "60000000-0000-4000-8000-000000000000",
"$feature_flag_response": false,
@@ -1232,6 +1241,9 @@
"$feature_flag_evaluated_at": 1800000000000,
"$feature_flag_has_experiment": false,
"$feature_flag_id": 700,
+ "$feature_flag_payload": {
+ "columns": 2
+ },
"$feature_flag_reason": "Matched condition set 1",
"$feature_flag_request_id": "60000000-0000-4000-8000-000000000000",
"$feature_flag_response": false,
@@ -1366,7 +1378,9 @@
"get_feature_flag_payload:bool-off": null,
"get_feature_flag_payload:bool-on": null,
"get_feature_flag_payload:missing": null,
- "get_feature_flag_payload:server-failed": null,
+ "get_feature_flag_payload:server-failed": {
+ "columns": 2
+ },
"get_feature_flag_payload:sparse": null,
"get_feature_flag_payload:v1-bool-payload": {
"cta": "Try it",
@@ -1402,7 +1416,9 @@
"get_feature_flag_result:server-failed": [
false,
null,
- null,
+ {
+ "columns": 2
+ },
"Matched condition set 1"
],
"get_feature_flag_result:sparse": [
@@ -1559,7 +1575,7 @@
"description": null,
"has_experiment": false,
"id": 700,
- "payload": null,
+ "payload": "{\"columns\": 2}",
"version": 3
},
"reason": {
@@ -1743,7 +1759,9 @@
"snapshot.get_flag_payload:bool-off": null,
"snapshot.get_flag_payload:bool-on": null,
"snapshot.get_flag_payload:missing": null,
- "snapshot.get_flag_payload:server-failed": null,
+ "snapshot.get_flag_payload:server-failed": {
+ "columns": 2
+ },
"snapshot.get_flag_payload:sparse": null,
"snapshot.get_flag_payload:v1-bool-payload": {
"cta": "Try it",
diff --git a/posthog/test/integrations/test_celery_integration.py b/posthog/test/integrations/test_celery_integration.py
index ae558e586..d025a7d6f 100644
--- a/posthog/test/integrations/test_celery_integration.py
+++ b/posthog/test/integrations/test_celery_integration.py
@@ -290,6 +290,53 @@ def test_before_task_publish_nested_headers_round_trips_to_worker(self):
# close out the task lifecycle so the test doesn't leave context hanging around
integration._on_task_success(sender=task)
+ @parameterized.expand(
+ [
+ # name, publishing task (name, id, retries), running task (name, id, retries)
+ ("child_task", ("app.parent", "parent-1", 0), ("app.child", "child-1", 0)),
+ ("retry", ("app.flaky", "flaky-1", 0), ("app.flaky", "flaky-1", 1)),
+ (
+ "chord_callback",
+ ("app.header", "header-1", 0),
+ ("app.callback", "callback-1", 0),
+ ),
+ ]
+ )
+ def test_task_published_from_a_task_keeps_its_own_celery_tags(
+ self, _name, publisher, worker
+ ):
+ integration = PosthogCeleryIntegration(client=Mock())
+
+ def run_task(name, task_id, retries, headers):
+ request = SimpleNamespace(
+ headers=headers, delivery_info={}, hostname="worker-1", retries=retries
+ )
+ task = SimpleNamespace(name=name, request=request)
+ integration._on_task_prerun(sender=task, task_id=task_id)
+ return task
+
+ publisher_task = run_task(
+ *publisher,
+ {
+ CONTEXT_DISTINCT_ID_HEADER: "user-1",
+ CONTEXT_TAGS_HEADER: '{"request_id": "abc"}',
+ },
+ )
+ headers = {}
+ integration._on_before_task_publish(sender=worker[0], headers=headers)
+ integration._on_task_success(sender=publisher_task)
+
+ worker_task = run_task(*worker, headers["headers"])
+ tags = contexts.get_tags()
+ integration._on_task_success(sender=worker_task)
+
+ worker_name, worker_id, worker_retries = worker
+ self.assertEqual(tags["celery_task_name"], worker_name)
+ self.assertEqual(tags["celery_task_id"], worker_id)
+ self.assertEqual(tags["celery_retry_count"], worker_retries)
+ # Other context still propagates from the publishing task.
+ self.assertEqual(tags["request_id"], "abc")
+
def test_before_task_publish_respects_propagate_context_flag(self):
integration = PosthogCeleryIntegration(propagate_context=False)
headers = {}
diff --git a/posthog/test/mcp/test_fastmcp.py b/posthog/test/mcp/test_fastmcp.py
index 0bcc88c1d..632850d60 100644
--- a/posthog/test/mcp/test_fastmcp.py
+++ b/posthog/test/mcp/test_fastmcp.py
@@ -82,7 +82,7 @@ async def test_list_tools_injects_model_into_real_and_virtual_tools():
for name in ("add", "boom", "get_more_tools"):
assert "llm_model" in tools[name].inputSchema["properties"]
- assert "llm_model" in tools[name].inputSchema["required"]
+ assert "llm_model" not in tools[name].inputSchema.get("required", [])
async def test_virtual_tool_uses_conversation_id():
diff --git a/posthog/test/mcp/test_fastmcp_v2.py b/posthog/test/mcp/test_fastmcp_v2.py
index d8f18b86b..cb1a44817 100644
--- a/posthog/test/mcp/test_fastmcp_v2.py
+++ b/posthog/test/mcp/test_fastmcp_v2.py
@@ -220,7 +220,10 @@ def fresh():
event = _events(client, "$mcp_tool_call")[0]["properties"]
assert event["$mcp_llm_model"] == "gpt-5"
assert event["$mcp_llm_model_source"] == "client_metadata"
- assert event["$mcp_input_keys"] == ["a", "b"]
+ # FastMCP 2.x can only list through request middleware, so the advertised
+ # schema is unknown there and the undeclared names stay redacted.
+ expected_keys = ["a", "b"] if hasattr(FastMCP, "list_tools") else ["[redacted]"]
+ assert event["$mcp_input_keys"] == expected_keys
_OWN_MODEL = {"llm_model": {"type": "string"}}
@@ -699,3 +702,27 @@ async def flaky_get_tool(name, *args, **kwargs):
assert "real tool ran" in str(out.root.content[0].text)
assert _events(client, "$mcp_missing_capability") == []
assert any("delegating the call to your server" in m for m in messages)
+
+
+@pytest.mark.skipif(
+ hasattr(FastMCP, "list_tools"), reason="FastMCP 2.x has no public list_tools"
+)
+async def test_schema_lookup_on_fastmcp_2_runs_no_request_middleware_and_trusts_no_schema():
+ from fastmcp.server.middleware import Middleware
+
+ from posthog.mcp._instrument_lowlevel import _listed_input_schema
+
+ listings = []
+
+ class CountListings(Middleware):
+ async def on_list_tools(self, context, call_next):
+ listings.append(context)
+ return await call_next(context)
+
+ server = make_server()
+ server.add_middleware(CountListings())
+
+ schema = await _listed_input_schema(server, "add", None)
+
+ assert schema is None
+ assert listings == []
diff --git a/posthog/test/mcp/test_feedback.py b/posthog/test/mcp/test_feedback.py
index 87274dcca..5110a0d60 100644
--- a/posthog/test/mcp/test_feedback.py
+++ b/posthog/test/mcp/test_feedback.py
@@ -88,7 +88,7 @@ async def _list_tools_lowlevel(server):
def test_descriptor_defaults():
descriptor = get_feedback_tool_descriptor()
assert descriptor["name"] == SEND_FEEDBACK_TOOL_NAME
- assert "missing capability" in descriptor["description"]
+ assert "a capability you needed that no tool provides" in descriptor["description"]
assert descriptor["inputSchema"]["required"] == ["feedback_type", "summary"]
assert set(descriptor["inputSchema"]["properties"]) == {
"feedback_type",
@@ -100,13 +100,6 @@ def test_descriptor_defaults():
"sentiment",
"task_completed",
}
- assert descriptor["annotations"] == {
- "title": "Send feedback",
- "readOnlyHint": True,
- "openWorldHint": True,
- "idempotentHint": True,
- "destructiveHint": False,
- }
def test_descriptor_merges_extras_and_custom_name():
@@ -244,9 +237,9 @@ def test_properties_bound_free_text_and_tool_name():
{"feedback_type": "issue", "summary": "s" * 5000, "tool_name": "t" * 500}
)
props = build_feedback_event_properties(report)
- assert len(props["$mcp_feedback_summary"]) == 2048 + 3
+ assert len(props["$mcp_feedback_summary"]) == 2048
assert props["$mcp_feedback_summary"].endswith("...")
- assert len(props["$mcp_feedback_tool"]) == 256 + 3
+ assert len(props["$mcp_feedback_tool"]) == 256
def test_properties_capture_declared_extras_only():
@@ -540,6 +533,48 @@ async def test_fastmcp_coexists_with_report_missing():
assert _events(client, "$mcp_tool_call") == []
+def _descriptions(node):
+ if isinstance(node, dict):
+ for key, value in node.items():
+ if key == "description" and isinstance(value, str):
+ yield value
+ yield from _descriptions(value)
+ elif isinstance(node, list):
+ for item in node:
+ yield from _descriptions(item)
+
+
+@pytest.mark.parametrize(
+ "phrase",
+ [
+ "parallel tool calls",
+ "system prompt",
+ "even if existing tools",
+ "Most important",
+ "even if you can work around it",
+ "send it even if",
+ ],
+)
+async def test_advertised_descriptions_carry_no_behavioral_instructions(phrase):
+ server = make_fastmcp()
+ instrument(
+ server,
+ FakeClient(),
+ MCPAnalyticsOptions(
+ report_missing=True, collect_feedback=True, capture_model=True
+ ),
+ )
+
+ list_handler = server._mcp_server.request_handlers[mcp_types.ListToolsRequest]
+ result = await list_handler(mcp_types.ListToolsRequest(method="tools/list"))
+ tools = result.root.tools
+ assert {"add", "get_more_tools", "send_feedback"} <= {t.name for t in tools}
+ descriptions = list(_descriptions([t.model_dump() for t in tools]))
+
+ assert descriptions
+ assert not [d for d in descriptions if phrase.lower() in d.lower()]
+
+
# --- on_feedback -----------------------------------------------------------------
diff --git a/posthog/test/mcp/test_model_parameters.py b/posthog/test/mcp/test_model_parameters.py
index 0891f0e95..1c2620f8c 100644
--- a/posthog/test/mcp/test_model_parameters.py
+++ b/posthog/test/mcp/test_model_parameters.py
@@ -31,7 +31,7 @@ def test_add_model_parameter_to_schema(schema):
"type": "string",
"description": DEFAULT_MODEL_PARAMETER_DESCRIPTION,
}
- assert "llm_model" in result["required"]
+ assert "llm_model" not in result.get("required", [])
assert result.get("additionalProperties") == (schema or {}).get(
"additionalProperties"
)
diff --git a/posthog/test/mcp/test_pipeline.py b/posthog/test/mcp/test_pipeline.py
index cc00b9201..f317cc0f4 100644
--- a/posthog/test/mcp/test_pipeline.py
+++ b/posthog/test/mcp/test_pipeline.py
@@ -839,7 +839,7 @@ def test_sanitize_event_passes_through_non_string_intent():
def test_normalize_caps_long_strings():
out = normalize("x" * 40000)
assert out.endswith("...")
- assert len(out) == 32_768 + 3
+ assert len(out) == 32_768
def test_normalize_detects_cycles():
diff --git a/posthog/test/mcp/test_posthog_mcp.py b/posthog/test/mcp/test_posthog_mcp.py
index 720a5a56f..7677fdb20 100644
--- a/posthog/test/mcp/test_posthog_mcp.py
+++ b/posthog/test/mcp/test_posthog_mcp.py
@@ -269,6 +269,26 @@ def test_prepare_tool_list_injects_context_into_tool_objects(sdk_tool: bool) ->
assert "context" not in schema["properties"]
+# The spec's text, pinned on purpose: every SDK sends this exact string, and
+# importing the constant would make this test agree with any change to it.
+_CROSS_SDK_CONTEXT_DESCRIPTION = (
+ "A few words on why you are calling this tool, for the server developer's "
+ 'analytics. Describe people and things by role, such as "a customer". Do not '
+ "quote the user or include names, emails, or other personal details."
+)
+
+
+def test_prepare_tool_list_advertises_the_cross_sdk_context_description():
+ client, _ = make_client()
+ tools = [{"name": "search", "inputSchema": {"type": "object", "properties": {}}}]
+
+ prepared = client.prepare_tool_list(tools)
+
+ assert prepared[0]["inputSchema"]["properties"]["context"]["description"] == (
+ _CROSS_SDK_CONTEXT_DESCRIPTION
+ )
+
+
def test_prepare_tool_list_can_be_disabled():
client, _ = make_client()
tools = [{"name": "search", "inputSchema": {"type": "object", "properties": {}}}]
@@ -292,7 +312,7 @@ async def test_prepare_and_capture_model(options: dict[str, bool]) -> None:
prepared_tools = client.prepare_tool_list(tools)
schema = prepared_tools[0]["inputSchema"]
assert ("llm_model" in schema["properties"]) == enabled
- assert ("llm_model" in schema.get("required", [])) == enabled
+ assert "llm_model" not in schema.get("required", [])
call = client.prepare_tool_call(
"search",
@@ -746,3 +766,17 @@ async def test_capture_tool_call_records_prepared_conversation_and_session():
props = _events(captured, "$mcp_tool_call")[0]["properties"]
assert props["$mcp_conversation_id"] == prepared.conversation_id
assert props["$session_id"] == prepared.session_id
+
+
+def test_capture_without_a_session_gets_a_fresh_one_per_call():
+ client, captured = make_client()
+
+ client.capture_tool_call("t")
+ client.capture_tool_call("t")
+ client.flush()
+
+ first, second = captured
+ session = first["properties"]["$session_id"]
+ assert session.startswith("ses_")
+ assert first["distinct_id"] == session
+ assert second["properties"]["$session_id"] != session
diff --git a/posthog/test/mcp/test_truncation.py b/posthog/test/mcp/test_truncation.py
index a0752c6c4..a3d47be49 100644
--- a/posthog/test/mcp/test_truncation.py
+++ b/posthog/test/mcp/test_truncation.py
@@ -20,7 +20,7 @@
def test_normalize_caps_long_strings():
out = normalize("x" * (MAX_STRING_LENGTH + 100))
- assert out.endswith("...") and len(out) == MAX_STRING_LENGTH + 3
+ assert out.endswith("...") and len(out) == MAX_STRING_LENGTH
def test_normalize_keeps_bool_distinct_from_int():
@@ -102,9 +102,9 @@ def test_truncate_event_caps_metadata_fields():
"llm_model": "m" * 500,
}
)
- assert len(out["user_intent"]) == 2048 + 3
- assert len(out["resource_name"]) == 256 + 3
- assert len(out["llm_model"]) == 256 + 3
+ assert len(out["user_intent"]) == 2048
+ assert len(out["resource_name"]) == 256
+ assert len(out["llm_model"]) == 256
def test_truncate_event_caps_exception_value_and_frames():
@@ -119,7 +119,7 @@ def test_truncate_event_caps_exception_value_and_frames():
}
)
exc = out["error"]["$exception_list"][0]
- assert len(exc["value"]) == 2048 + 3
+ assert len(exc["value"]) == 2048
assert exc["stacktrace"]["frames"] == frames[:25] + frames[-25:]
@@ -127,7 +127,7 @@ def test_truncate_event_caps_response_text_block():
out = truncate_event(
{"response": {"content": [{"type": "text", "text": "t" * 40000}]}}
)
- assert len(out["response"]["content"][0]["text"]) == 32_768 + 3
+ assert len(out["response"]["content"][0]["text"]) == 32_768
# --- size-targeted budget ----------------------------------------------------
diff --git a/posthog/test/mcp/test_units.py b/posthog/test/mcp/test_units.py
index 49316a1fb..f5a3546c3 100644
--- a/posthog/test/mcp/test_units.py
+++ b/posthog/test/mcp/test_units.py
@@ -235,7 +235,7 @@ def test_add_conversation_id_adds_property():
assert out["properties"]["conversation_id"]["type"] == "string"
# Without this clause, ChatGPT drops the handle on each new user message and every message becomes its own session.
assert (
- "rest of the conversation, including after later user messages"
+ "including after later user messages"
in out["properties"]["conversation_id"]["description"]
)
diff --git a/posthog/test/mcp/test_unknown_tool.py b/posthog/test/mcp/test_unknown_tool.py
new file mode 100644
index 000000000..8d1396d26
--- /dev/null
+++ b/posthog/test/mcp/test_unknown_tool.py
@@ -0,0 +1,369 @@
+"""``$mcp_unknown_tool``: a call naming a tool the server never registered is
+not a tool call. Runs under both MCP SDK majors over an in-process client, so
+the response compared against an uninstrumented twin is the one an agent gets."""
+
+import importlib
+import importlib.util
+import json
+from contextlib import asynccontextmanager
+
+import mcp.types as mcp_types
+import pytest
+
+from posthog.mcp import instrument
+from posthog.mcp.types import MCPAnalyticsOptions
+from posthog.test.mcp._helpers import (
+ MCP_MAJOR,
+ FakeClient,
+ events_named,
+ flush_background,
+)
+
+_needs_standalone = pytest.mark.skipif(
+ importlib.util.find_spec("fastmcp") is None, reason="standalone fastmcp"
+)
+
+
+def _fastmcp_can_disable() -> bool:
+ try:
+ from fastmcp import FastMCP
+ except ImportError:
+ return False
+ return hasattr(FastMCP, "disable")
+
+
+_needs_server_disable = pytest.mark.skipif(
+ not _fastmcp_can_disable(), reason="FastMCP.disable and providers, fastmcp 3+"
+)
+
+
+def _high_level():
+ if MCP_MAJOR >= 2:
+ from mcp.server.mcpserver import MCPServer as HighLevel
+ else:
+ from mcp.server.fastmcp import FastMCP as HighLevel
+ server = HighLevel("unknown-tool")
+
+ @server.tool()
+ def search_docs(query: str) -> str:
+ return f"found {query}"
+
+ return server
+
+
+def _standalone(*middleware):
+ """``middleware`` names stock fastmcp middleware as ``"."``
+ under ``fastmcp.server.middleware``."""
+ from fastmcp import FastMCP
+
+ server = FastMCP("unknown-tool")
+
+ @server.tool
+ def search_docs(query: str) -> str:
+ return f"found {query}"
+
+ for path in middleware:
+ module, name = path.rsplit(".", 1)
+ stock = importlib.import_module(f"fastmcp.server.middleware.{module}")
+ server.add_middleware(getattr(stock, name)())
+ return server
+
+
+def _standalone_with_disabled_tool():
+ server = _standalone()
+
+ @server.tool
+ def retired(query: str) -> str:
+ return query
+
+ server.disable(names={"retired"})
+ return server
+
+
+def _standalone_with_application_middleware():
+ from fastmcp.server.middleware.logging import LoggingMiddleware
+
+ class AuditMiddleware(LoggingMiddleware):
+ async def on_call_tool(self, context, call_next):
+ return await call_next(context)
+
+ server = _standalone()
+ server.add_middleware(AuditMiddleware())
+ return server
+
+
+def _mounted():
+ """A parent serving a sub-server's tools under the ``ns`` namespace, one
+ of them disabled on the sub-server."""
+ from fastmcp import FastMCP
+
+ sub = FastMCP("sub")
+
+ @sub.tool
+ def retired(query: str) -> str:
+ return query
+
+ sub.disable(names={"retired"})
+ parent = _standalone()
+ parent.mount(sub, namespace="ns")
+ return parent
+
+
+def _with_mounted_server():
+ """A parent serving a sub-server's tools under the ``ns`` prefix, on every
+ fastmcp major (2.x spells the argument ``prefix``, 3.x ``namespace``)."""
+ from fastmcp import FastMCP
+
+ sub = FastMCP("sub")
+
+ @sub.tool
+ def lookup(query: str) -> str:
+ return query
+
+ parent = _standalone()
+ try:
+ parent.mount(sub, namespace="ns")
+ except TypeError:
+ parent.mount(sub, prefix="ns")
+ return parent
+
+
+def _raw(listed):
+ """A raw low-level server whose own dispatcher rejects names it does not
+ know and advertises ``listed`` on tools/list."""
+ from mcp.server.lowlevel import Server
+
+ schema = {"type": "object", "properties": {"query": {"type": "string"}}}
+ listing = mcp_types.ListToolsResult(
+ tools=[
+ mcp_types.Tool(
+ name=name,
+ **{"input_schema" if MCP_MAJOR >= 2 else "inputSchema": schema},
+ )
+ for name in listed
+ ]
+ )
+
+ def reply(name):
+ if name not in listed:
+ raise ValueError(f"Unknown tool: {name}")
+ return [mcp_types.TextContent(type="text", text="ok")]
+
+ if MCP_MAJOR >= 2:
+
+ async def on_call_tool(ctx, params):
+ return mcp_types.CallToolResult(content=reply(params.name))
+
+ async def on_list_tools(ctx, params):
+ return listing
+
+ return Server(
+ "unknown-tool", on_call_tool=on_call_tool, on_list_tools=on_list_tools
+ )
+
+ server = Server("unknown-tool")
+
+ @server.call_tool()
+ async def call_tool(name, arguments):
+ return reply(name)
+
+ async def list_tools(req):
+ return mcp_types.ServerResult(listing)
+
+ server.request_handlers[mcp_types.ListToolsRequest] = list_tools
+ return server
+
+
+@asynccontextmanager
+async def _connected(server):
+ if type(server).__module__.startswith("fastmcp"):
+ from fastmcp import Client
+
+ async with Client(server) as client:
+ yield lambda name, args: client.call_tool(name, args, raise_on_error=False)
+ elif MCP_MAJOR >= 2:
+ from mcp import Client
+
+ async with Client(server) as client:
+ yield client.call_tool
+ else:
+ from mcp.shared.memory import create_connected_server_and_client_session
+
+ async with create_connected_server_and_client_session(server) as session:
+ yield session.call_tool
+
+
+async def _response(server, name, arguments):
+ async with _connected(server) as call:
+ try:
+ result = await call(name, arguments)
+ except Exception as error: # noqa: BLE001 - the error is the response
+ return type(error).__name__, str(error)
+ is_error = result.is_error if hasattr(result, "is_error") else result.isError
+ return is_error, [getattr(block, "text", None) for block in result.content]
+
+
+@pytest.mark.parametrize(
+ "build",
+ [
+ pytest.param(_high_level, id="high-level"),
+ pytest.param(_standalone, id="standalone-fastmcp", marks=_needs_standalone),
+ *(
+ pytest.param(
+ lambda path=path: _standalone(path),
+ id=f"standalone-fastmcp-with-{path.split('.')[0]}-middleware",
+ marks=_needs_standalone,
+ )
+ for path in (
+ "logging.LoggingMiddleware",
+ "timing.TimingMiddleware",
+ "error_handling.ErrorHandlingMiddleware",
+ )
+ ),
+ ],
+)
+async def test_a_call_to_a_tool_that_does_not_exist_is_recorded_as_unknown(build):
+ expected = await _response(build(), "no_such_tool", {})
+ client = FakeClient()
+ server = build()
+ instrument(server, client, MCPAnalyticsOptions(enable_conversation_id=False))
+
+ assert await _response(server, "no_such_tool", {}) == expected
+ await flush_background()
+
+ [unknown] = events_named(client, "$mcp_unknown_tool")
+ assert unknown["properties"]["$mcp_tool_name"] == "no_such_tool"
+ assert unknown["properties"]["$session_id"]
+ assert events_named(client, "$mcp_tool_call") == []
+ assert events_named(client, "$exception") == []
+
+
+@pytest.mark.parametrize(
+ "build, name, arguments",
+ [
+ pytest.param(_high_level, "search_docs", {}, id="invalid-arguments"),
+ pytest.param(
+ _standalone_with_disabled_tool,
+ "retired",
+ {"query": "q"},
+ id="disabled-standalone-tool",
+ marks=_needs_server_disable,
+ ),
+ pytest.param(
+ _mounted,
+ "ns_retired",
+ {"query": "q"},
+ id="disabled-tool-on-mounted-server",
+ marks=_needs_server_disable,
+ ),
+ pytest.param(
+ _mounted,
+ "ns_no_such_tool",
+ {},
+ id="server-with-mounted-provider",
+ marks=_needs_server_disable,
+ ),
+ pytest.param(
+ _with_mounted_server,
+ "ns_no_such_tool",
+ {},
+ id="server-with-mounted-server",
+ marks=_needs_standalone,
+ ),
+ pytest.param(
+ _standalone_with_application_middleware,
+ "no_such_tool",
+ {},
+ id="standalone-with-application-middleware",
+ marks=_needs_standalone,
+ ),
+ pytest.param(
+ lambda: _raw(["search_docs"]),
+ "no_such_tool",
+ {},
+ id="raw-low-level-unknown-name",
+ ),
+ ],
+)
+async def test_a_call_the_sdk_cannot_rule_out_is_a_failed_tool_call(
+ build, name, arguments
+):
+ expected = await _response(build(), name, arguments)
+ client = FakeClient()
+ server = build()
+ instrument(server, client, MCPAnalyticsOptions(enable_conversation_id=False))
+
+ assert await _response(server, name, arguments) == expected
+ await flush_background()
+
+ [call] = events_named(client, "$mcp_tool_call")
+ assert call["properties"]["$mcp_tool_name"] == name
+ assert call["properties"]["$mcp_is_error"] is True
+ assert events_named(client, "$mcp_unknown_tool") == []
+
+
+_SHAPES = [
+ pytest.param(_high_level, id="high-level"),
+ pytest.param(_standalone, id="standalone-fastmcp", marks=_needs_standalone),
+]
+
+
+@pytest.mark.parametrize(
+ "build", [*_SHAPES, pytest.param(lambda: _raw(["search_docs"]), id="raw-low-level")]
+)
+async def test_a_call_naming_no_tool_emits_nothing(build):
+ expected = await _response(build(), "", {})
+ client = FakeClient()
+ server = build()
+ instrument(server, client, MCPAnalyticsOptions(enable_conversation_id=False))
+
+ assert await _response(server, "", {}) == expected
+ await flush_background()
+
+ assert [e["event"] for e in client.events if e["event"] != "$mcp_initialize"] == []
+
+
+@pytest.mark.parametrize("build", _SHAPES)
+async def test_an_unknown_tool_name_is_cut_to_256_characters(build):
+ client = FakeClient()
+ server = build()
+ instrument(server, client, MCPAnalyticsOptions(enable_conversation_id=False))
+
+ await _response(server, "x" * 5000, {})
+ await flush_background()
+
+ [unknown] = events_named(client, "$mcp_unknown_tool")
+ name = unknown["properties"]["$mcp_tool_name"]
+ assert len(name) == 256
+ assert name.startswith("x" * 200)
+
+
+@pytest.mark.parametrize(
+ "build, delivers_handle",
+ [
+ pytest.param(
+ _standalone, True, id="standalone-error-result", marks=_needs_standalone
+ ),
+ pytest.param(_high_level, False, id="high-level-raise"),
+ ],
+)
+async def test_an_unknown_tool_result_carries_the_conversation_handle_it_delivers(
+ build, delivers_handle
+):
+ client = FakeClient()
+ server = build()
+ instrument(server, client)
+
+ _, texts = await _response(server, "no_such_tool", {})
+ await flush_background()
+
+ handles = [
+ json.loads(text)["conversation_id"]
+ for text in texts
+ if text and text.startswith('{"conversation_id"')
+ ]
+ [unknown] = events_named(client, "$mcp_unknown_tool")
+ assert len(handles) == int(delivers_handle)
+ assert unknown["properties"].get("$mcp_conversation_id") == next(
+ iter(handles), None
+ )
diff --git a/posthog/test/mcp/test_v2_wire_dual_era.py b/posthog/test/mcp/test_v2_wire_dual_era.py
index 58fbf4e9a..df5f23235 100644
--- a/posthog/test/mcp/test_v2_wire_dual_era.py
+++ b/posthog/test/mcp/test_v2_wire_dual_era.py
@@ -146,7 +146,7 @@ async def test_modern_tools_list_advertises_injected_params():
assert "context" in tools["add"]["inputSchema"]["properties"]
assert "conversation_id" in tools["add"]["inputSchema"]["properties"]
assert "llm_model" in tools["add"]["inputSchema"]["properties"]
- assert "llm_model" in tools["add"]["inputSchema"]["required"]
+ assert "llm_model" not in tools["add"]["inputSchema"]["required"]
listed = _events(client, "$mcp_tools_list")
assert listed and set(listed[0]["properties"]["$mcp_listed_tool_names"]) == {
diff --git a/posthog/test/mcp/test_virtual_tools.py b/posthog/test/mcp/test_virtual_tools.py
index c02ecc7bf..4e45ed31f 100644
--- a/posthog/test/mcp/test_virtual_tools.py
+++ b/posthog/test/mcp/test_virtual_tools.py
@@ -89,6 +89,54 @@ async def test_both_virtual_tools_are_appended_to_the_first_page_only():
assert _names(await _list_page(server, cursor="1")) == ["echo"]
+# --- annotations ---------------------------------------------------------------
+
+# The spec's annotations JSON, pinned on purpose: importing VIRTUAL_TOOL_HINTS
+# would make this test agree with any change to it.
+_RECORDS_DATA = {
+ "readOnlyHint": False,
+ "destructiveHint": False,
+ "idempotentHint": False,
+ "openWorldHint": False,
+}
+
+
+@pytest.mark.parametrize(
+ "options, advertised_name",
+ [
+ (MCPAnalyticsOptions(report_missing=True), "get_more_tools"),
+ (MCPAnalyticsOptions(collect_feedback=True), "send_feedback"),
+ (
+ MCPAnalyticsOptions(
+ report_missing=True, missing_capability_tool_name="request_tool"
+ ),
+ "request_tool",
+ ),
+ (
+ MCPAnalyticsOptions(
+ collect_feedback=CollectFeedbackOptions(
+ tool_name="rate_server", description="Tell us how it went."
+ )
+ ),
+ "rate_server",
+ ),
+ ],
+)
+async def test_virtual_tools_declare_that_they_record_data(options, advertised_name):
+ server = FastMCP("annotations")
+
+ @server.tool()
+ def add(a: int, b: int) -> int:
+ return a + b
+
+ instrument(server, FakeClient(), options)
+ handler = server._mcp_server.request_handlers[mcp_types.ListToolsRequest]
+ result = await handler(mcp_types.ListToolsRequest(method="tools/list"))
+ tool = {t.name: t for t in result.root.tools}[advertised_name]
+
+ assert tool.annotations.model_dump(exclude_none=True) == (_RECORDS_DATA)
+
+
# --- name collisions -----------------------------------------------------------
diff --git a/posthog/test/released_flags_scenarios.py b/posthog/test/released_flags_scenarios.py
index 35b3736e5..1bdbb9e22 100644
--- a/posthog/test/released_flags_scenarios.py
+++ b/posthog/test/released_flags_scenarios.py
@@ -76,7 +76,8 @@ def _flag(key: str, value: Any, **fields: Any) -> Dict[str, Any]:
_flag("v2-number", 12.5, config_version=2),
_flag("v2-object", {"layout": "compact", "n": [1, True]}, config_version=2),
_flag("sparse", "compact", metadata={}, has_experiment=None, reason=None),
- _flag("server-failed", "compact", failed=True),
+ # A failed record that still carries a payload.
+ _flag("server-failed", "compact", failed=True, payload='{"columns": 2}'),
]
@@ -171,7 +172,9 @@ def flags(*args: Any, **kwargs: Any) -> Any:
# Read the built event in before_send: v1 layers flag properties inside _enqueue.
def record(message: Dict[str, Any]) -> Optional[Dict[str, Any]]:
events.append([message["event"], _flag_event_properties(message)])
- return None
+ # Keep the event, so capture accepts it and returns its UUID as the real
+ # queue does; flag events dedupe only events that were accepted.
+ return message
try:
with (
diff --git a/posthog/test/test_bucketed_rate_limiter.py b/posthog/test/test_bucketed_rate_limiter.py
index 93ec96dc8..95e46184a 100644
--- a/posthog/test/test_bucketed_rate_limiter.py
+++ b/posthog/test/test_bucketed_rate_limiter.py
@@ -199,6 +199,38 @@ def test_clamps_out_of_range_options():
assert limiter._refill_interval == 86400.0
+@pytest.mark.parametrize(
+ "option, attribute, fallback",
+ [
+ ("bucket_size", "_bucket_size", 100),
+ ("refill_rate", "_refill_rate", 10),
+ ("refill_interval_seconds", "_refill_interval", 86400.0),
+ ],
+)
+def test_nan_options_use_invalid_number_fallback(option, attribute, fallback, caplog):
+ limiter = make_limiter(FakeClock(), **{option: float("nan")})
+
+ assert getattr(limiter, attribute) == fallback
+ assert f"{option} must be a number" in caplog.text
+
+
+@pytest.mark.parametrize(
+ "value, expected",
+ [
+ (0, 0),
+ (10**1000, 100),
+ (float("inf"), 100),
+ (float("-inf"), 0),
+ (True, 100),
+ (False, 100),
+ ],
+)
+def test_bucket_size_preserves_existing_clamping(value, expected):
+ limiter = make_limiter(FakeClock(), bucket_size=value)
+
+ assert limiter._bucket_size == expected
+
+
def test_thread_safety_allows_exactly_bucket_size_minus_one():
limiter = make_limiter(FakeClock(), bucket_size=50)
allowed = []
diff --git a/posthog/test/test_client.py b/posthog/test/test_client.py
index 3af7dd6d1..5381af3db 100644
--- a/posthog/test/test_client.py
+++ b/posthog/test/test_client.py
@@ -2777,6 +2777,15 @@ def test_shutdown_clears_feature_flag_called_dedupe_cache(self):
"rediss://user:secret@cache.example.com:6380/1?ttl=120",
"rediss://user:secret@cache.example.com:6380/1",
),
+ ("redis://[::1]:6379/0?ttl=120", "redis://[::1]:6379/0"),
+ (
+ "rediss://[2001:db8::1]:6380/1?ttl=120",
+ "rediss://[2001:db8::1]:6380/1",
+ ),
+ (
+ "redis://user:p%40ss@[::1]:6379/0?ttl=120",
+ "redis://user:p%40ss@[::1]:6379/0",
+ ),
]
)
def test_flag_fallback_cache_url_accepts_redis_schemes(
diff --git a/posthog/test/test_contexts.py b/posthog/test/test_contexts.py
index 73a1ab466..7efc7e0fc 100644
--- a/posthog/test/test_contexts.py
+++ b/posthog/test/test_contexts.py
@@ -5,6 +5,7 @@
from unittest.mock import MagicMock, patch
import posthog
+from posthog.async_client import AsyncPosthog
from posthog.client import Client
from posthog.contexts import (
get_context_options,
@@ -229,6 +230,21 @@ def test_new_context_defaults_to_custom_client_exception_autocapture_disabled(se
client.capture_exception.assert_not_called()
+ def test_new_context_with_async_client_defaults_to_no_exception_capture(self):
+ client = AsyncPosthog("phc_test", disabled=True)
+ client.capture_exception = MagicMock()
+
+ with self.assertRaises(RuntimeError):
+ with new_context(client=client):
+ raise RuntimeError("Context exception")
+ client.capture_exception.assert_not_called()
+
+ test_exception = RuntimeError("Context exception")
+ with self.assertRaises(RuntimeError):
+ with new_context(client=client, capture_exceptions=True):
+ raise test_exception
+ client.capture_exception.assert_called_once_with(test_exception)
+
def test_identify_context(self):
with new_context(fresh=True):
# Initially no distinct ID
diff --git a/posthog/test/test_emails.py b/posthog/test/test_emails.py
index c0aeac2e8..eaf1c0949 100644
--- a/posthog/test/test_emails.py
+++ b/posthog/test/test_emails.py
@@ -176,6 +176,7 @@ def test_client_email_options_set_the_host_timeout_and_retries():
app_host="https://posthog.example.com/",
email_request_timeout_seconds=3,
email_request_max_retries=0,
+ migrated_from="resend",
)
unavailable = response(503, {"code": "delivery_unavailable"})
@@ -188,6 +189,35 @@ def test_client_email_options_set_the_host_timeout_and_retries():
request.assert_called_once()
assert request.call_args.args[1].startswith("https://posthog.example.com/api/")
assert request.call_args.kwargs["timeout"] == 3
+ sent = request.call_args.kwargs["auth"](
+ requests.Request("POST", "https://posthog.example.com/").prepare()
+ )
+ assert sent.headers["X-PostHog-Migrated-From"] == "resend"
+
+
+def test_names_the_provider_the_client_moved_from_on_every_request():
+ emails, adapter = emails_with([accepted(), status_reply()], migrated_from="resend")
+
+ send(emails)
+ emails.get(MESSAGE_ID)
+
+ assert [
+ request.headers["X-PostHog-Migrated-From"] for request in adapter.requests
+ ] == [
+ "resend",
+ "resend",
+ ]
+
+
+@parameterized.expand([("space", "re send"), ("not_text", 1), ("empty", "")])
+def test_rejects_a_provider_name_that_is_not_a_header_value(_name, migrated_from):
+ with pytest.raises(ValueError):
+ Posthog(
+ "phc_test",
+ secret_key=SECRET_KEY,
+ sync_mode=True,
+ migrated_from=migrated_from,
+ )
@parameterized.expand(
@@ -282,6 +312,18 @@ def test_waits_for_retry_after_and_gives_up_on_a_longer_one(no_sleep):
("client_option", {"max_retries": 0}, {}, 1),
("per_send_override", {}, {"max_retries": 0}, 1),
("per_send_override_above_client", {"max_retries": 0}, {"max_retries": 1}, 2),
+ (
+ "code_send_override",
+ {},
+ {
+ "template_id": None,
+ "template_key": "password-reset",
+ "subject": "Reset",
+ "html": "Reset
",
+ "max_retries": 0,
+ },
+ 1,
+ ),
]
)
def test_max_retries_zero_leaves_retries_to_the_caller(
@@ -290,9 +332,12 @@ def test_max_retries_zero_leaves_retries_to_the_caller(
emails, adapter = emails_with(
[rejected(503, "delivery_unavailable")] * 3, **client_options
)
+ args = {"to": "user@example.com", "template_id": TEMPLATE_ID, **send_options}
with pytest.raises(EmailError):
- send(emails, **send_options)
+ emails.send(
+ **{name: value for name, value in args.items() if value is not None}
+ )
assert len(adapter.requests) == requests_made
@@ -572,3 +617,185 @@ def handler(request: httpx.Request) -> httpx.Response:
assert [(request.method, str(request.url)) for request in seen] == [
("GET", STATUS_URL)
] * 2
+
+
+HTML = "Reset it here.
"
+
+
+def send_code(emails: Emails, **overrides: Any):
+ return emails.send(
+ **{
+ "to": "user@example.com",
+ "template_key": "password-reset",
+ "subject": "Reset your password",
+ **overrides,
+ }
+ )
+
+
+@parameterized.expand(
+ [
+ ("html_only", {"html": HTML}, {"html": HTML}),
+ ("text_only", {"text": "Reset it here."}, {"text": "Reset it here."}),
+ (
+ "every_field",
+ {
+ "html": HTML,
+ "text": "Reset it here.",
+ "from_": "Acme ",
+ "reply_to": "help@example.com",
+ "capture_engagement": False,
+ "distinct_id": "user_123",
+ },
+ {
+ "html": HTML,
+ "text": "Reset it here.",
+ "from": "Acme ",
+ "reply_to": ["help@example.com"],
+ "capture_engagement": False,
+ "distinct_id": "user_123",
+ },
+ ),
+ (
+ "several_reply_to",
+ {"html": HTML, "reply_to": ["a@example.com", "b@example.com"]},
+ {"html": HTML, "reply_to": ["a@example.com", "b@example.com"]},
+ ),
+ (
+ "empty_reply_to_left_out",
+ {"html": HTML, "reply_to": []},
+ {"html": HTML},
+ ),
+ (
+ "none_as_left_out",
+ {
+ "html": HTML,
+ "text": None,
+ "from_": None,
+ "reply_to": None,
+ "capture_engagement": None,
+ "distinct_id": None,
+ },
+ {"html": HTML},
+ ),
+ ]
+)
+def test_rendered_content_is_posted_as_is(_name, overrides, extra_body):
+ emails, adapter = emails_with([accepted("msg_1")])
+
+ result = send_code(emails, idempotency_key="reset:user_123", **overrides)
+
+ assert result.id == "msg_1"
+ [request] = adapter.requests
+ assert (request.method, request.url) == ("POST", SEND_URL)
+ assert request.headers["Idempotency-Key"] == "reset:user_123"
+ assert json.loads(request.body) == {
+ "to": "user@example.com",
+ "template_key": "password-reset",
+ "subject": "Reset your password",
+ "capture_engagement": True,
+ **extra_body,
+ }
+
+
+@pytest.mark.asyncio
+async def test_async_client_posts_rendered_content_and_names_the_provider():
+ seen: list[httpx.Request] = []
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ seen.append(request)
+ return httpx.Response(202, json={"message_id": "msg_1", "replayed": True})
+
+ client = AsyncPosthog("phc_test", secret_key=SECRET_KEY, migrated_from="resend")
+ client.emails._client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
+
+ result = await client.emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=HTML,
+ text="Reset it here.",
+ from_="Acme ",
+ reply_to="help@example.com",
+ capture_engagement=False,
+ distinct_id="user_123",
+ idempotency_key="reset:user_123",
+ )
+ await client.shutdown()
+
+ assert (result.id, result.replayed) == ("msg_1", True)
+ [request] = seen
+ assert (request.method, str(request.url)) == ("POST", SEND_URL)
+ assert request.headers["Authorization"] == f"Bearer {SECRET_KEY}"
+ assert request.headers["Idempotency-Key"] == "reset:user_123"
+ assert request.headers["X-PostHog-Migrated-From"] == "resend"
+ assert json.loads(request.content) == {
+ "to": "user@example.com",
+ "template_key": "password-reset",
+ "subject": "Reset your password",
+ "html": HTML,
+ "text": "Reset it here.",
+ "from": "Acme ",
+ "reply_to": ["help@example.com"],
+ "capture_engagement": False,
+ "distinct_id": "user_123",
+ }
+
+
+@parameterized.expand(
+ [
+ ("both_forms", {"template_id": TEMPLATE_ID, "html": HTML}, TypeError),
+ ("no_form", {"template_key": None}, TypeError),
+ ("no_content", {}, TypeError),
+ ("no_subject", {"subject": None, "html": HTML}, TypeError),
+ ("subject_not_text", {"subject": 1, "html": HTML}, TypeError),
+ ("from_not_text", {"html": HTML, "from_": 1}, TypeError),
+ ("from_keyword", {"html": HTML, "from": "a@example.com"}, TypeError),
+ (
+ "key_with_space",
+ {"template_key": "reset password", "html": HTML},
+ ValueError,
+ ),
+ (
+ "key_with_trailing_newline",
+ {"template_key": "welcome\n", "html": HTML},
+ ValueError,
+ ),
+ ("key_too_long", {"template_key": "k" * 401, "html": HTML}, ValueError),
+ ("empty_html", {"html": ""}, ValueError),
+ ("empty_html_and_text", {"html": "", "text": ""}, ValueError),
+ ("blank_reply_to", {"html": HTML, "reply_to": " "}, ValueError),
+ ("reply_to_not_text", {"html": HTML, "reply_to": 123}, TypeError),
+ (
+ "template_data_on_code_form",
+ {"html": HTML, "template_data": {"first_name": "Jane"}},
+ TypeError,
+ ),
+ ("cc_on_code_form", {"html": HTML, "cc": "a@example.com"}, TypeError),
+ (
+ "capture_engagement_on_template_form",
+ {
+ "template_id": TEMPLATE_ID,
+ "template_key": None,
+ "subject": None,
+ "capture_engagement": False,
+ },
+ TypeError,
+ ),
+ ]
+)
+def test_rejects_a_code_send_that_mixes_or_misses_fields(_name, overrides, error):
+ emails, adapter = emails_with([])
+ args = {
+ "to": "user@example.com",
+ "template_key": "password-reset",
+ "subject": "Reset your password",
+ **overrides,
+ }
+
+ with pytest.raises(error):
+ emails.send(
+ **{name: value for name, value in args.items() if value is not None}
+ )
+
+ assert adapter.requests == []
diff --git a/posthog/test/test_evaluate_flags.py b/posthog/test/test_evaluate_flags.py
index 89bc54b62..6bca25e67 100644
--- a/posthog/test/test_evaluate_flags.py
+++ b/posthog/test/test_evaluate_flags.py
@@ -1,3 +1,4 @@
+import json
import logging
import unittest
import warnings
@@ -1254,6 +1255,178 @@ def test_removed_flag_is_forgotten_and_warns_again_when_it_returns(self):
len(self._warnings(logs, "checkout", "experience_continuity")), 2
)
+ def _refresh_from(self, client, source, *flags):
+ definitions = json.loads(json.dumps(self._definitions(*flags)))
+ if source == "api":
+ self._refresh(
+ client,
+ GetResponse(data=definitions, etag="etag-1", not_modified=False),
+ )
+ else:
+ cache_provider = mock.Mock()
+ cache_provider.should_fetch_flag_definitions.return_value = False
+ cache_provider.get_flag_definitions.return_value = definitions
+ with (
+ mock.patch.object(
+ client, "_flag_definition_cache_provider", cache_provider
+ ),
+ mock.patch("posthog.client.get") as get,
+ ):
+ client._load_feature_flags()
+ get.assert_not_called()
+
+ @staticmethod
+ def _never_resolvable_flag(key, reason, **kwargs):
+ flag = (
+ _always_on_flag(key, ensure_experience_continuity=True)
+ if reason == "experience_continuity"
+ else _flag_with(key, _STATIC_COHORT)
+ )
+ return {**flag, "version": 7, **kwargs}
+
+ @parameterized.expand(
+ [
+ (source, reason, runtime_name, runtime_fields)
+ for source in ("api", "cache")
+ for reason in ("experience_continuity", "unsupported_definition")
+ for runtime_name, runtime_fields in (
+ ("client", {"evaluation_runtime": "client"}),
+ ("server", {"evaluation_runtime": "server"}),
+ ("all", {"evaluation_runtime": "all"}),
+ ("null", {"evaluation_runtime": None}),
+ ("absent", {}),
+ )
+ ]
+ )
+ @mock.patch("posthog.client.flags")
+ def test_warning_runtime_json_semantics_and_deduplication(
+ self, source, reason, runtime_name, runtime_fields, patch_flags
+ ):
+ client = self._client()
+ checkout = self._never_resolvable_flag("checkout", reason, **runtime_fields)
+ with self.assertLogs("posthog", level=logging.DEBUG) as logs:
+ self._refresh_from(client, source, checkout)
+ self._refresh_from(client, source, checkout)
+ if source == "api":
+ self._refresh(
+ client,
+ GetResponse(data=None, etag="etag-1", not_modified=True),
+ )
+
+ self.assertEqual(
+ len(self._warnings(logs, "checkout", reason)),
+ 0 if runtime_name == "client" else 1,
+ )
+ self.assertEqual(client.feature_flags, [checkout])
+ self.assertEqual(
+ set(client._warned_unresolvable_flags),
+ set() if runtime_name == "client" else {"checkout"},
+ )
+ patch_flags.assert_not_called()
+
+ @parameterized.expand([("api",), ("cache",)])
+ @mock.patch("posthog.client.flags")
+ def test_mixed_runtime_warning_counts_and_names(self, source, patch_flags):
+ client = self._client()
+ definitions = [
+ self._never_resolvable_flag(f"{reason}-{runtime_name}", reason, **fields)
+ for reason in ("experience_continuity", "unsupported_definition")
+ for runtime_name, fields in (
+ ("client", {"evaluation_runtime": "client"}),
+ ("server", {"evaluation_runtime": "server"}),
+ ("all", {"evaluation_runtime": "all"}),
+ ("null", {"evaluation_runtime": None}),
+ ("absent", {}),
+ )
+ ]
+ with self.assertLogs("posthog", level=logging.WARNING) as logs:
+ self._refresh_from(client, source, *definitions)
+ self._refresh_from(client, source, *definitions)
+
+ self.assertEqual(len(logs.records), 2)
+ for reason in ("experience_continuity", "unsupported_definition"):
+ messages = self._warnings(logs, reason, reason)
+ self.assertEqual(len(messages), 1)
+ message = messages[0].getMessage()
+ self.assertIn("4 flag(s)", message)
+ self.assertNotIn(f"{reason}-client", message)
+ for runtime_name in ("server", "all", "null", "absent"):
+ self.assertIn(f"{reason}-{runtime_name}", message)
+ self.assertEqual(client.feature_flags, definitions)
+ patch_flags.assert_not_called()
+
+ @parameterized.expand(
+ [
+ (source, reason, runtime_name, runtime_fields)
+ for source in ("api", "cache")
+ for reason in ("experience_continuity", "unsupported_definition")
+ for runtime_name, runtime_fields in (
+ ("server", {"evaluation_runtime": "server"}),
+ ("all", {"evaluation_runtime": "all"}),
+ ("null", {"evaluation_runtime": None}),
+ ("absent", {}),
+ )
+ ]
+ )
+ @mock.patch("posthog.client.flags")
+ def test_client_runtime_forgets_history_before_nonclient_return(
+ self, source, reason, runtime_name, runtime_fields, patch_flags
+ ):
+ client = self._client()
+ server = self._never_resolvable_flag(
+ "checkout", reason, evaluation_runtime="server"
+ )
+ client_only = {**server, "evaluation_runtime": "client"}
+ returning = self._never_resolvable_flag("checkout", reason, **runtime_fields)
+ with self.assertLogs("posthog", level=logging.DEBUG) as logs:
+ self._refresh_from(client, source, server)
+ self.assertEqual(len(self._warnings(logs, "checkout", reason)), 1)
+ for expected_count in (2, 3):
+ self._refresh_from(client, source, client_only)
+ self._refresh_from(client, source, client_only)
+ self.assertEqual(client._warned_unresolvable_flags, {})
+ self.assertEqual(
+ len(self._warnings(logs, "checkout", reason)), expected_count - 1
+ )
+ self._refresh_from(client, source, returning)
+ self._refresh_from(client, source, returning)
+ self.assertEqual(
+ len(self._warnings(logs, "checkout", reason)), expected_count
+ )
+ self.assertEqual(client.feature_flags, [returning])
+ patch_flags.assert_not_called()
+
+ @parameterized.expand([("api",), ("cache",)])
+ @mock.patch("posthog.client.flags")
+ def test_client_runtime_preserves_local_value_and_unresolved_reasons(
+ self, source, patch_flags
+ ):
+ client = self._client()
+ definitions = [
+ _always_on_flag("client-flag", evaluation_runtime="client"),
+ self._never_resolvable_flag(
+ "continuity", "experience_continuity", evaluation_runtime="client"
+ ),
+ self._never_resolvable_flag(
+ "unsupported", "unsupported_definition", evaluation_runtime="client"
+ ),
+ ]
+ with self.assertNoLogs("posthog", level=logging.WARNING):
+ self._refresh_from(client, source, *definitions)
+ snapshot = client.evaluate_flags("user-123", only_evaluate_locally=True)
+
+ self.assertEqual(snapshot.keys, ["client-flag"])
+ self.assertIs(snapshot.get_flag("client-flag"), True)
+ self.assertEqual(
+ dict(snapshot.unresolved_flags),
+ {
+ "continuity": UnresolvedFlagReason.EXPERIENCE_CONTINUITY,
+ "unsupported": UnresolvedFlagReason.UNSUPPORTED_DEFINITION,
+ },
+ )
+ self.assertEqual(client.feature_flags, definitions)
+ patch_flags.assert_not_called()
+
def test_classifies_and_logs_outside_the_publication_lock(self):
client = self._client()
lock = client._flag_definition_publication_lock
diff --git a/posthog/test/test_exception_capture.py b/posthog/test/test_exception_capture.py
index f5d0f1a30..d8d2f0cd9 100644
--- a/posthog/test/test_exception_capture.py
+++ b/posthog/test/test_exception_capture.py
@@ -1,9 +1,12 @@
+import copy
+import importlib.util
+import pickle
import subprocess
import sys
import threading
from textwrap import dedent
from types import SimpleNamespace
-from unittest.mock import MagicMock
+from unittest.mock import MagicMock, patch
import pytest
@@ -89,6 +92,46 @@ def test_client_passes_rate_limiter_configuration_through():
client.shutdown()
+@pytest.mark.parametrize(
+ "option, attempts, expected_uploads",
+ [
+ ("exception_autocapture_refill_interval_seconds", 6, 2),
+ ("exception_autocapture_bucket_size", 105, 99),
+ ],
+)
+def test_nan_limiter_configuration_keeps_exception_hook_working(
+ monkeypatch, caplog, option, attempts, expected_uploads
+):
+ from posthog import Posthog
+
+ previous_hook = MagicMock()
+ upload = MagicMock()
+ monkeypatch.setattr(sys, "excepthook", previous_hook)
+ monkeypatch.setattr("posthog.client._send_v1_batch", upload)
+ options = {
+ "exception_autocapture_bucket_size": 3,
+ "exception_autocapture_refill_interval_seconds": 60,
+ option: float("nan"),
+ }
+ client = Posthog(
+ "phc_test",
+ sync_mode=True,
+ enable_exception_autocapture=True,
+ enable_exception_autocapture_rate_limiting=True,
+ **options,
+ )
+ try:
+ for _ in range(attempts):
+ error = ValueError("boom")
+ sys.excepthook(type(error), error, None)
+
+ assert upload.call_count == expected_uploads
+ assert previous_hook.call_count == attempts
+ assert "Failed to capture exception" not in caplog.text
+ finally:
+ client.shutdown()
+
+
def test_rate_limits_per_exception_type():
from posthog.exception_capture import ExceptionCapture
@@ -523,3 +566,177 @@ def test_last_inspected_group_member_retains_its_cause_chain():
]
assert exceptions[-1]["mechanism"]["source"] == "cause"
assert exceptions[-1]["mechanism"]["parent_id"] == 2
+
+
+_APP_MODULE_SOURCE = dedent(
+ """
+ def entry_point(capture, error):
+ return handler(capture, error)
+
+ def handler(capture, error):
+ return capture(error)
+ """
+)
+
+
+def _call_from_app_module(capture, error):
+ # Run the capture call from frames that belong to an application module,
+ # not to the posthog package, the way a real caller would.
+ namespace = {"__name__": "app"}
+ exec(compile(_APP_MODULE_SOURCE, "app.py", "exec"), namespace)
+ return namespace["entry_point"](capture, error)
+
+
+def _exceptions_for_never_raised(error):
+ from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple
+
+ return exceptions_from_error_tuple(
+ _call_from_app_module(exc_info_from_error, error)
+ )
+
+
+def test_never_raised_exception_stack_is_outermost_first():
+ exception = _exceptions_for_never_raised(ValueError("never raised"))[0]
+
+ functions = [frame["function"] for frame in exception["stacktrace"]["frames"]]
+ assert functions.index("entry_point") < functions.index("handler")
+ assert functions[-1] == "handler"
+
+
+def test_never_raised_exception_stack_omits_sdk_frames():
+ exception = _exceptions_for_never_raised(ValueError("never raised"))[0]
+
+ functions = [frame["function"] for frame in exception["stacktrace"]["frames"]]
+ assert "construct_artificial_traceback" not in functions
+ assert "exc_info_from_error" not in functions
+
+
+def test_never_raised_exception_stack_is_marked_synthetic():
+ exception = _exceptions_for_never_raised(ValueError("never raised"))[0]
+
+ assert exception["mechanism"]["synthetic"] is True
+
+
+def test_raised_exception_passed_by_object_is_not_synthetic():
+ from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple
+
+ try:
+ raise ValueError("raised")
+ except ValueError as error:
+ exceptions = exceptions_from_error_tuple(exc_info_from_error(error))
+
+ assert exceptions[0]["mechanism"]["synthetic"] is False
+
+
+def test_client_capture_of_never_raised_exception_sends_synthetic_stack():
+ from posthog.client import Client
+
+ client = Client("phc_test", sync_mode=True)
+ try:
+ with patch.object(client, "capture", return_value="event-id") as capture:
+ _call_from_app_module(
+ lambda error: client.capture_exception(error, distinct_id="user"),
+ ValueError("never raised"),
+ )
+
+ exception = capture.call_args.kwargs["properties"]["$exception_list"][0]
+ functions = [frame["function"] for frame in exception["stacktrace"]["frames"]]
+ assert exception["mechanism"]["synthetic"] is True
+ assert functions.index("entry_point") < functions.index("handler")
+ assert "capture_exception" not in functions
+ finally:
+ client.shutdown()
+
+
+def test_never_raised_exception_stays_pickleable_after_capture():
+ from posthog.exception_utils import exc_info_from_error
+
+ error = ValueError("never raised")
+ _call_from_app_module(exc_info_from_error, error)
+
+ restored = pickle.loads(pickle.dumps(error))
+
+ assert isinstance(restored, ValueError)
+ assert restored.args == ("never raised",)
+
+
+def test_never_raised_exception_is_not_synthetic_once_raised():
+ from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple
+
+ error = ValueError("never raised")
+ _call_from_app_module(exc_info_from_error, error)
+
+ try:
+ raise error
+ except ValueError as raised:
+ exceptions = exceptions_from_error_tuple(exc_info_from_error(raised))
+
+ assert exceptions[0]["mechanism"]["synthetic"] is False
+
+
+def _pickle_round_trip(error):
+ return pickle.loads(pickle.dumps(error))
+
+
+@pytest.mark.parametrize("duplicate", [_pickle_round_trip, copy.copy, copy.deepcopy])
+def test_copy_of_captured_exception_is_not_synthetic_once_raised(duplicate):
+ from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple
+
+ # Capture inline, so no application frame keeps the exception alive and the
+ # synthesized traceback is freed as soon as the original goes away. Its
+ # address is then free for the traceback of the raise below.
+ for _ in range(50):
+ error = ValueError("never raised")
+ exc_info_from_error(error)
+ duplicated = duplicate(error)
+ del error
+
+ try:
+ raise duplicated
+ except ValueError as raised:
+ exceptions = exceptions_from_error_tuple(exc_info_from_error(raised))
+
+ assert exceptions[0]["mechanism"]["synthetic"] is False
+
+
+def test_captured_exception_can_be_unpickled_without_the_sdk():
+ from posthog.exception_utils import exc_info_from_error
+
+ error = ValueError("never raised")
+ _call_from_app_module(exc_info_from_error, error)
+
+ result = subprocess.run(
+ [
+ sys.executable,
+ "-I",
+ "-S",
+ "-c",
+ "import pickle, sys; print(pickle.loads(sys.stdin.buffer.read()))",
+ ],
+ input=pickle.dumps(error),
+ capture_output=True,
+ )
+
+ assert result.returncode == 0, result.stderr
+ assert result.stdout.strip() == b"never raised"
+
+
+def test_never_raised_exception_stack_omits_sdk_frames_in_renamed_package():
+ import posthog.exception_utils as exception_utils
+
+ # The posthoganalytics mirror ships this module under another package name.
+ spec = importlib.util.spec_from_file_location(
+ "posthoganalytics.exception_utils", exception_utils.__file__
+ )
+ mirror = importlib.util.module_from_spec(spec)
+ with patch.dict(sys.modules, {spec.name: mirror}):
+ spec.loader.exec_module(mirror)
+ exception = mirror.exceptions_from_error_tuple(
+ _call_from_app_module(
+ mirror.exc_info_from_error, ValueError("never raised")
+ )
+ )[0]
+
+ functions = [frame["function"] for frame in exception["stacktrace"]["frames"]]
+ assert functions[-1] == "handler"
+ assert exception["mechanism"]["synthetic"] is True
diff --git a/posthog/test/test_experiment_exposure.py b/posthog/test/test_experiment_exposure.py
new file mode 100644
index 000000000..6d583c40c
--- /dev/null
+++ b/posthog/test/test_experiment_exposure.py
@@ -0,0 +1,1857 @@
+"""``$experiment_exposure`` and the attribution of ``$feature_flag_called``.
+
+A remotely evaluated config version 2 record that assigns an experiment variant sends
+``$experiment_exposure`` next to its ``$feature_flag_called``, and every config version
+2 record adds its rule attribution to ``$feature_flag_called``. The reader fixtures and
+event schemas are copied unchanged from a ``PostHog/posthog-sdk-test-harness`` contract;
+``fixtures/feature_flag_rules_v2/SOURCE.json`` records which.
+"""
+
+from __future__ import annotations
+
+import copy
+import json
+import threading
+import warnings
+from dataclasses import dataclass
+from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional
+from unittest import mock
+
+import jsonschema
+import pytest
+
+from posthog import AsyncPosthog
+from posthog import client as posthog_client
+from posthog.client import (
+ _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES,
+ _MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES,
+ MAX_DICT_SIZE,
+ Client,
+)
+from posthog.test.test_flags_v4_response import FIXTURES, READERS, _build
+from posthog.test.test_utils import FAKE_TEST_API_KEY
+from posthog.types import FeatureFlagResult
+from posthog.utils import SizeLimitedDict
+
+FLAG = "pricing-page"
+DISTINCT_ID = "visitor-42"
+RULE = "7f3c2a10-8d4e-4b6a-9c21-5e0f1a2b3c4d"
+OTHER_RULE = "2b9d4e61-0c7a-4f35-8e12-6a4b3c2d1e0f"
+REQUEST_ID = "5d1e2f30-4a5b-4c6d-8e7f-90a1b2c3d4e5"
+OTHER_REQUEST_ID = "6e2f3a41-5b6c-4d7e-9f80-a1b2c3d4e5f6"
+EVALUATED_AT = 1_800_000_000_000
+
+EXPOSURE = "$experiment_exposure"
+FLAG_CALLED = "$feature_flag_called"
+ATTRIBUTION_PROPERTIES = (
+ "$feature_flag_config_version",
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_id",
+ "$feature_flag_rule_type",
+ "$feature_flag_variant_key",
+)
+
+
+# $experiment_exposure leaves these out. The config version, rule type and reason code
+# stay on the $feature_flag_called of the same read. The schema projection drops
+# undeclared properties, so their absence is asserted separately.
+EXPOSURE_LEAVES_OUT = (
+ "$feature_flag_config_version",
+ "$feature_flag_rule_type",
+ "$feature_flag_reason_code",
+ "$experiment_exposure_source",
+)
+
+
+def _schema(name: str) -> jsonschema.Draft202012Validator:
+ schema = json.loads((FIXTURES / name).read_text(encoding="utf-8"))
+ return jsonschema.Draft202012Validator(schema)
+
+
+FLAG_CALLED_SCHEMA = _schema("feature_flag_called_context.schema.json")
+EXPOSURE_SCHEMA = _schema("experiment_exposure_properties.schema.json")
+
+
+def _projection(
+ validator: jsonschema.Draft202012Validator, properties: Mapping[str, Any]
+) -> Dict[str, Any]:
+ """The properties a closed contract projection covers."""
+ names = validator.schema["properties"]
+ return {key: value for key, value in properties.items() if key in names}
+
+
+# --- Responses ----------------------------------------------------------------
+
+
+def _record(
+ code: str,
+ value: Any = True,
+ *,
+ key: str = FLAG,
+ rule_type: Optional[str] = None,
+ rule_id: Optional[str] = None,
+ variant_key: Optional[str] = None,
+ config_version: int = 2,
+ has_experiment: bool = False,
+ description: Optional[str] = None,
+ failed: bool = False,
+) -> Dict[str, Any]:
+ metadata: Dict[str, Any] = {
+ "id": 77,
+ "version": 3,
+ "config_version": config_version,
+ "description": None,
+ "payload": None,
+ "has_experiment": has_experiment,
+ }
+ for field, field_value in (
+ ("rule_type", rule_type),
+ ("rule_id", rule_id),
+ ("variant_key", variant_key),
+ ):
+ if field_value is not None:
+ metadata[field] = field_value
+ reason: Dict[str, Any] = {
+ "code": code,
+ "condition_index": 0 if rule_id else None,
+ }
+ if description is not None:
+ reason["description"] = description
+ record = {"key": key, "value": value, "reason": reason, "metadata": metadata}
+ if failed:
+ record["failed"] = True
+ return record
+
+
+def _split(
+ value: Any = "annual",
+ variant_key: str = "annual-first",
+ rule_id: str = RULE,
+ **overrides: Any,
+) -> Dict[str, Any]:
+ fields: Dict[str, Any] = {
+ "rule_type": "experiment",
+ "rule_id": rule_id,
+ "variant_key": variant_key,
+ "has_experiment": True,
+ **overrides,
+ }
+ return _record("experiment_split", value, **fields)
+
+
+def _response(
+ *records: Dict[str, Any],
+ request_id: str = REQUEST_ID,
+ evaluated_at: int = EVALUATED_AT,
+ **envelope: Any,
+) -> Dict[str, Any]:
+ return {
+ "flags": {record["key"]: record for record in records},
+ "errorsWhileComputingFlags": False,
+ "requestId": request_id,
+ "evaluatedAt": evaluated_at,
+ **envelope,
+ }
+
+
+# --- Recording events -----------------------------------------------------------
+
+
+@dataclass
+class _Event:
+ name: str
+ distinct_id: Any
+ properties: Dict[str, Any]
+ groups: Any
+ property_allowlist: Any
+ uuid: Optional[str]
+
+
+def _record_events(client: Any) -> tuple[Any, List[_Event]]:
+ """Patch ``client.capture`` to record each call, then capture as usual."""
+ events: List[_Event] = []
+ capture = client.capture
+
+ def record(event: str, **kwargs: Any) -> Optional[str]:
+ uuid = capture(event, **kwargs)
+ events.append(
+ _Event(
+ name=event,
+ distinct_id=kwargs.get("distinct_id"),
+ properties=copy.deepcopy(kwargs.get("properties") or {}),
+ groups=kwargs.get("groups"),
+ property_allowlist=kwargs.get("_property_allowlist"),
+ uuid=uuid,
+ )
+ )
+ return uuid
+
+ return mock.patch.object(client, "capture", side_effect=record), events
+
+
+def _named(events: List[_Event], name: str, key: str = FLAG) -> List[_Event]:
+ return [
+ event
+ for event in events
+ if event.name == name and event.properties.get("$feature_flag") == key
+ ]
+
+
+def _attribution(properties: Mapping[str, Any]) -> Dict[str, Any]:
+ return {
+ name: properties[name] for name in ATTRIBUTION_PROPERTIES if name in properties
+ }
+
+
+# --- Reading through each path ------------------------------------------------------
+
+# Every sync read that sends flag events. Each takes the client, the key, the
+# distinct ID and the groups.
+SYNC_READS: Dict[str, Callable[..., Any]] = {
+ "get_feature_flag": lambda client, key, distinct_id, groups: (
+ client.get_feature_flag(key, distinct_id, groups=groups)
+ ),
+ "feature_enabled": lambda client, key, distinct_id, groups: (
+ client.feature_enabled(key, distinct_id, groups=groups)
+ ),
+ "get_feature_flag_result": lambda client, key, distinct_id, groups: (
+ client.get_feature_flag_result(key, distinct_id, groups=groups)
+ ),
+ "snapshot.get_flag": lambda client, key, distinct_id, groups: (
+ client.evaluate_flags(distinct_id, groups=groups).get_flag(key)
+ ),
+ "snapshot.is_enabled": lambda client, key, distinct_id, groups: (
+ client.evaluate_flags(distinct_id, groups=groups).is_enabled(key)
+ ),
+}
+SINGLE_FLAG_READS = ["get_feature_flag", "feature_enabled", "get_feature_flag_result"]
+SNAPSHOT_READS = ["snapshot.get_flag", "snapshot.is_enabled"]
+
+
+@pytest.fixture
+def client() -> Iterator[Client]:
+ client = Client(FAKE_TEST_API_KEY, send=False)
+ yield client
+ client.shutdown()
+
+
+def _serving(*responses: Dict[str, Any]) -> Any:
+ """Patch ``/flags`` to answer with each response in turn, the last one after that."""
+ remaining = list(responses)
+
+ def answer(*args: Any, **kwargs: Any) -> Dict[str, Any]:
+ response = remaining.pop(0) if len(remaining) > 1 else remaining[0]
+ return copy.deepcopy(response)
+
+ return mock.patch("posthog.client.flags", side_effect=answer)
+
+
+def _read(
+ client: Client,
+ path: str,
+ key: str = FLAG,
+ distinct_id: Any = DISTINCT_ID,
+ groups: Optional[Dict[str, Any]] = None,
+) -> Any:
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ return SYNC_READS[path](client, key, distinct_id, groups or {})
+
+
+def _read_events(
+ path: str,
+ *responses: Dict[str, Any],
+ reads: int = 1,
+ client: Optional[Client] = None,
+ **read_kwargs: Any,
+) -> List[_Event]:
+ """Read ``FLAG`` ``reads`` times through ``path``, one response per read."""
+ own_client = client is None
+ client = client or Client(FAKE_TEST_API_KEY, send=False)
+ recording, events = _record_events(client)
+ try:
+ with _serving(*responses), recording:
+ for _ in range(reads):
+ _read(client, path, **read_kwargs)
+ finally:
+ if own_client:
+ client.shutdown()
+ return events
+
+
+async def _read_async_events(
+ responses: List[Dict[str, Any]],
+ reads: List[Callable[[Any], Any]],
+) -> List[_Event]:
+ """Run the reads on one async client, answering each evaluation with the next
+ response, and the last one after that."""
+ remaining = list(responses)
+
+ def answer(*args: Any, **kwargs: Any) -> Dict[str, Any]:
+ response = remaining.pop(0) if len(remaining) > 1 else remaining[0]
+ return copy.deepcopy(response)
+
+ with mock.patch(
+ "posthog.async_client._async_flags", new=mock.AsyncMock(side_effect=answer)
+ ):
+ client = AsyncPosthog("project-key", send=False)
+ recording, events = _record_events(client)
+ with recording:
+ for read in reads:
+ await read(client)
+ await client.shutdown()
+ return events
+
+
+# --- The contract's reader cases --------------------------------------------------------
+
+READER_CASES = [case for case in READERS["cases"] if case["expected"] == "reader"]
+
+
+def _check_reader_events(case: Dict[str, Any], events: List[_Event]) -> None:
+ reader = case["reader"]
+ expectations = {reader["requested_key"]: reader}
+ expectations.update(case.get("sibling_expectations", {}))
+ for key, expected in expectations.items():
+ exposures = _named(events, EXPOSURE, key)
+ assert len(exposures) == (1 if expected["experiment_exposure"] else 0), key
+ [called] = _named(events, FLAG_CALLED, key)
+ config_version = expected.get("config_version")
+ if expected.get("error_code") == "PARSE_ERROR":
+ config_version = None
+ assert called.properties.get("$feature_flag_config_version") == (
+ 2 if config_version == 2 else None
+ ), key
+ if called.properties["$feature_flag_response"] is not None:
+ FLAG_CALLED_SCHEMA.validate(
+ _projection(FLAG_CALLED_SCHEMA, called.properties)
+ )
+ for exposure in exposures:
+ EXPOSURE_SCHEMA.validate(_projection(EXPOSURE_SCHEMA, exposure.properties))
+ assert not set(EXPOSURE_LEAVES_OUT) & set(exposure.properties), key
+ assert (
+ exposure.properties["$feature_flag_response"]
+ == (called.properties["$feature_flag_response"])
+ )
+ assert exposure.uuid is not None and exposure.uuid != called.uuid
+ for event in [called, *exposures]:
+ # A flag may be named anything, so `$feature/` is left out.
+ for name in event.properties:
+ if not name.startswith("$feature/"):
+ for part in ("experiment_id", "holdout", "seed"):
+ assert part not in name, name
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+@pytest.mark.parametrize("case", READER_CASES, ids=lambda case: case["id"])
+def test_reader_cases_send_an_exposure_exactly_when_the_contract_expects(case, path):
+ response = _build(READERS, case)
+ client = Client(FAKE_TEST_API_KEY, send=False)
+ recording, events = _record_events(client)
+ try:
+ with _serving(response), recording:
+ _read(client, path, case["reader"]["requested_key"])
+ for sibling in case.get("sibling_expectations", {}):
+ _read(client, path, sibling)
+ finally:
+ client.shutdown()
+
+ _check_reader_events(case, events)
+
+
+@pytest.mark.parametrize("method", ["get_flag", "is_enabled"])
+@pytest.mark.parametrize("case", READER_CASES, ids=lambda case: case["id"])
+async def test_async_reader_cases_send_an_exposure_exactly_when_the_contract_expects(
+ case, method
+):
+ keys = [case["reader"]["requested_key"], *case.get("sibling_expectations", {})]
+
+ async def read(client: Any) -> None:
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ for key in keys:
+ getattr(snapshot, method)(key)
+
+ events = await _read_async_events([_build(READERS, case)], [read])
+
+ _check_reader_events(case, events)
+
+
+# --- Attribution on $feature_flag_called --------------------------------------------------
+
+_RULE_ID = "10000000-0000-4000-8000-000000000001"
+ATTRIBUTION_CASES = [
+ # (reader template or case id, attribution on $feature_flag_called)
+ (
+ "experiment_split",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "experiment_split",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "experiment",
+ "$feature_flag_variant_key": "arm_a",
+ },
+ ),
+ (
+ "targeting_match_targeted_release",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "targeting_match",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "targeted_release",
+ },
+ ),
+ (
+ "targeting_match_percentage_rollout",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "targeting_match",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "percentage_rollout",
+ },
+ ),
+ (
+ "rollout_miss_percentage_rollout",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "rollout_miss",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "percentage_rollout",
+ },
+ ),
+ (
+ "rollout_miss_experiment",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "rollout_miss",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "experiment",
+ },
+ ),
+ (
+ "experiment_paused",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "experiment_paused",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "experiment",
+ },
+ ),
+ (
+ "holdout",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "holdout",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "experiment",
+ },
+ ),
+ # A holdout assigns no variant, even when its record names one.
+ (
+ "readers.holdout_variant_key",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "holdout",
+ "$feature_flag_rule_id": _RULE_ID,
+ "$feature_flag_rule_type": "experiment",
+ },
+ ),
+ (
+ "no_rule_match",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "no_rule_match",
+ },
+ ),
+ (
+ "missing_group_key",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "missing_group_key",
+ },
+ ),
+ (
+ "dependency_error",
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "dependency_error",
+ },
+ ),
+ (
+ "error",
+ {"$feature_flag_config_version": 2, "$feature_flag_reason_code": "error"},
+ ),
+ # A malformed split keeps its config version and reason, and loses the whole rule
+ # tuple.
+ *(
+ (
+ case_id,
+ {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "experiment_split",
+ },
+ )
+ for case_id in (
+ "readers.partial_split_missing_rule_type",
+ "readers.partial_split_missing_rule_id",
+ "readers.partial_split_missing_variant_key",
+ "readers.wrong_rule_type_literal",
+ "readers.partial_split_string_value",
+ )
+ ),
+ # Config version 1, from either kind of server, is unchanged.
+ ("v1", {}),
+ ("old_server", {}),
+ ("readers.partial_split_missing_config_version", {}),
+]
+
+
+def _attribution_response(source: str) -> Dict[str, Any]:
+ if source.startswith("readers."):
+ [case] = [case for case in READERS["cases"] if case["id"] == source]
+ return _build(READERS, case)
+ return _build(READERS, {"template": source})
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize(
+ "source, expected", ATTRIBUTION_CASES, ids=[c[0] for c in ATTRIBUTION_CASES]
+)
+def test_flag_called_attribution_follows_the_record(source, expected, path):
+ events = _read_events(path, _attribution_response(source), key="garden-layout")
+
+ [called] = _named(events, FLAG_CALLED, "garden-layout")
+ assert _attribution(called.properties) == expected
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+ exposures = _named(events, EXPOSURE, "garden-layout")
+ assert len(exposures) == (1 if "$feature_flag_variant_key" in expected else 0)
+
+
+# A record whose reason names no rule, or that failed, reports no rule even when it
+# carries one. Neither sends an exposure. The last element says whether the record is
+# a valid server outcome, which the contract's event schema then accepts.
+STRAY_RULE_CASES = [
+ ("no_rule_match", {}, True),
+ ("missing_group_key", {}, True),
+ ("flag_disabled", {}, True),
+ ("dependency_error", {"failed": True, "value": None}, True),
+ ("error", {"failed": True, "value": None}, True),
+ # A failed record reports no rule, whatever its reason code.
+ (
+ "experiment_split",
+ {"failed": True, "value": None, "variant_key": "annual-first"},
+ True,
+ ),
+ ("holdout", {"failed": True, "value": None}, False),
+ # A reason code this SDK does not know.
+ ("future_reason", {}, False),
+]
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize(
+ "code, fields, valid_outcome",
+ STRAY_RULE_CASES,
+ ids=[f"{c}-{sorted(f)}" for c, f, _ in STRAY_RULE_CASES],
+)
+def test_rule_fields_are_sent_only_for_reasons_that_name_a_rule(
+ code, fields, valid_outcome, path
+):
+ fields = {"value": False, **fields}
+ record = _record(
+ code, rule_type="experiment", rule_id=RULE, has_experiment=True, **fields
+ )
+
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": code,
+ }
+ assert _named(events, EXPOSURE) == []
+ if valid_outcome:
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+@pytest.mark.parametrize("method", ["get_flag", "is_enabled"])
+async def test_async_a_failed_split_sends_no_exposure(method):
+ # The record keeps its complete split metadata, but it failed.
+ record = _split(value=None, failed=True)
+
+ async def read(client: Any) -> None:
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ getattr(snapshot, method)(FLAG)
+
+ events = await _read_async_events([_response(record)], [read])
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "experiment_split",
+ }
+ assert _named(events, EXPOSURE) == []
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize(
+ "code, rule_type",
+ [
+ ("targeting_match", "targeted_release"),
+ ("targeting_match", "percentage_rollout"),
+ ("rollout_miss", "percentage_rollout"),
+ ("rollout_miss", "experiment"),
+ ("experiment_paused", "experiment"),
+ ("holdout", "experiment"),
+ ],
+)
+def test_rule_matches_misses_pauses_and_holdouts_name_their_rule(code, rule_type, path):
+ record = _record(code, False, rule_type=rule_type, rule_id=RULE)
+
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": code,
+ "$feature_flag_rule_id": RULE,
+ "$feature_flag_rule_type": rule_type,
+ }
+ assert _named(events, EXPOSURE) == []
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+# The rule ID and rule type are sent together, with a rule type the reason allows, or
+# not at all. A call that drops a broken pair keeps its config version and reason code.
+BROKEN_RULE_PAIR_CASES = [
+ # Half pairs.
+ ("targeting_match", {"rule_id": RULE}),
+ ("rollout_miss", {"rule_id": RULE}),
+ ("experiment_paused", {"rule_id": RULE}),
+ ("holdout", {"rule_id": RULE}),
+ ("targeting_match", {"rule_type": "targeted_release"}),
+ ("rollout_miss", {"rule_type": "percentage_rollout"}),
+ ("experiment_paused", {"rule_type": "experiment"}),
+ ("holdout", {"rule_type": "experiment"}),
+ # Rule types the reason code does not allow.
+ ("targeting_match", {"rule_id": RULE, "rule_type": "experiment"}),
+ ("rollout_miss", {"rule_id": RULE, "rule_type": "targeted_release"}),
+ ("experiment_paused", {"rule_id": RULE, "rule_type": "percentage_rollout"}),
+ ("holdout", {"rule_id": RULE, "rule_type": "targeted_release"}),
+ # A rule type this SDK does not know.
+ ("targeting_match", {"rule_id": RULE, "rule_type": "future_rule_type"}),
+]
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize(
+ "code, fields",
+ BROKEN_RULE_PAIR_CASES,
+ ids=[f"{c}-{sorted(f.items())}" for c, f in BROKEN_RULE_PAIR_CASES],
+)
+def test_a_half_or_disallowed_rule_pair_is_not_sent(code, fields, path):
+ record = _record(code, False, **fields)
+
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": code,
+ }
+ assert _named(events, EXPOSURE) == []
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_a_targeting_match_that_names_an_experiment_rule_sends_no_exposure(path):
+ # Even with a variant key and a linked experiment, a targeting match assigns no
+ # arm, so it reports no rule and sends no exposure.
+ record = _record(
+ "targeting_match",
+ "annual",
+ rule_type="experiment",
+ rule_id=RULE,
+ variant_key="annual-first",
+ has_experiment=True,
+ )
+
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "targeting_match",
+ }
+ assert _named(events, EXPOSURE) == []
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+def test_an_older_server_record_reports_no_attribution():
+ # A record without a typed value comes from a server before /flags?v=4. Its
+ # metadata is not read as config version 2, whatever it says.
+ response = _response(
+ {
+ "key": FLAG,
+ "enabled": True,
+ "variant": "annual",
+ "reason": {"code": "condition_match", "condition_index": 0},
+ "metadata": {
+ "id": 77,
+ "version": 3,
+ "config_version": 2,
+ "rule_type": "experiment",
+ "rule_id": RULE,
+ "variant_key": "annual-first",
+ },
+ }
+ )
+ for path in SYNC_READS:
+ events = _read_events(path, response)
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {}
+ assert _named(events, EXPOSURE) == []
+
+
+# --- $feature_flag_reason ------------------------------------------------------------------
+
+REASON_DESCRIPTION = "Matched rule 1"
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+@pytest.mark.parametrize(
+ "record",
+ [
+ _record(
+ "targeting_match",
+ rule_type="targeted_release",
+ rule_id=RULE,
+ description=REASON_DESCRIPTION,
+ ),
+ _record("no_rule_match", False, description=REASON_DESCRIPTION),
+ _record("error", None, failed=True, description=REASON_DESCRIPTION),
+ _split(description=REASON_DESCRIPTION),
+ ],
+ ids=["targeting_match", "no_rule_match", "failed", "experiment_split"],
+)
+def test_a_config_version_2_call_reports_its_reason_by_code_only(record, path):
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert called.properties["$feature_flag_reason_code"] == record["reason"]["code"]
+ assert "$feature_flag_reason" not in called.properties
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+@pytest.mark.parametrize(
+ "record",
+ [
+ _record(
+ "condition_match",
+ "annual",
+ config_version=1,
+ description=REASON_DESCRIPTION,
+ ),
+ # A record from a server before /flags?v=4, which has no config version.
+ {
+ "key": FLAG,
+ "enabled": True,
+ "variant": "annual",
+ "reason": {
+ "code": "condition_match",
+ "condition_index": 0,
+ "description": REASON_DESCRIPTION,
+ },
+ "metadata": {"id": 77, "version": 3},
+ },
+ ],
+ ids=["config_version_1", "older_server"],
+)
+def test_a_call_without_config_version_2_keeps_its_reason_description(record, path):
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert called.properties["$feature_flag_reason"] == REASON_DESCRIPTION
+ assert _attribution(called.properties) == {}
+
+
+@pytest.mark.parametrize(
+ "config_version, code, reason",
+ [(1, "condition_match", REASON_DESCRIPTION), (2, "targeting_match", None)],
+)
+def test_minimal_calls_keep_the_reason_description_only_without_config_version_2(
+ config_version, code, reason
+):
+ messages: List[Dict[str, Any]] = []
+
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(message)
+ return message
+
+ client = Client(FAKE_TEST_API_KEY, send=False, before_send=before_send)
+ record = _record(
+ code, config_version=config_version, description=REASON_DESCRIPTION
+ )
+ try:
+ with _serving(_response(record, minimalFlagCalledEvents=True)):
+ client.evaluate_flags(DISTINCT_ID).get_flag(FLAG)
+ client.get_feature_flag_result(FLAG, "visitor-43")
+ finally:
+ client.shutdown()
+
+ allowlist = (
+ _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
+ if config_version == 1
+ else _MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES
+ )
+ assert [message["event"] for message in messages] == [FLAG_CALLED, FLAG_CALLED]
+ for message in messages:
+ assert set(message["properties"]) <= allowlist
+ assert message["properties"].get("$feature_flag_reason") == reason
+
+
+def test_minimal_config_version_1_calls_drop_super_properties_named_like_attribution():
+ attribution_names = (
+ _MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES - _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
+ )
+ messages: List[Dict[str, Any]] = []
+
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(message)
+ return message
+
+ client = Client(
+ FAKE_TEST_API_KEY,
+ send=False,
+ before_send=before_send,
+ super_properties={name: "set-by-the-app" for name in attribution_names},
+ )
+ record = _record(
+ "condition_match", config_version=1, description=REASON_DESCRIPTION
+ )
+ try:
+ with _serving(_response(record, minimalFlagCalledEvents=True)):
+ client.get_feature_flag_result(FLAG, DISTINCT_ID)
+ finally:
+ client.shutdown()
+
+ [message] = messages
+ assert not attribution_names & set(message["properties"])
+
+
+# --- The exact events of a split ---------------------------------------------------------
+
+
+# The attribution of a split's $feature_flag_called.
+EXPECTED_ATTRIBUTION = {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "experiment_split",
+ "$feature_flag_rule_id": RULE,
+ "$feature_flag_rule_type": "experiment",
+ "$feature_flag_variant_key": "annual-first",
+}
+EXPECTED_EXPOSURE = {
+ "$feature_flag": FLAG,
+ "$feature_flag_response": "annual",
+ "$feature_flag_variant_key": "annual-first",
+ "$feature_flag_rule_id": RULE,
+ "locally_evaluated": False,
+ "$feature_flag_id": 77,
+ "$feature_flag_version": 3,
+ "$feature_flag_request_id": REQUEST_ID,
+ "$feature_flag_evaluated_at": EVALUATED_AT,
+}
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_a_split_sends_both_events_with_exact_properties(path):
+ response = _response(_split(description="Assigned variant 'annual-first'"))
+
+ events = _read_events(path, response, groups={"company": "company-7"})
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE]
+ called, exposure = events
+ assert called.properties == {
+ "$feature_flag": FLAG,
+ "$feature_flag_response": "annual",
+ "locally_evaluated": False,
+ f"$feature/{FLAG}": "annual",
+ "$feature_flag_request_id": REQUEST_ID,
+ "$feature_flag_evaluated_at": EVALUATED_AT,
+ # The reason code replaces the record's reason description.
+ "$feature_flag_version": 3,
+ "$feature_flag_id": 77,
+ "$feature_flag_has_experiment": True,
+ **EXPECTED_ATTRIBUTION,
+ }
+ assert exposure.properties == EXPECTED_EXPOSURE
+ assert exposure.distinct_id == called.distinct_id == DISTINCT_ID
+ assert exposure.groups == called.groups == {"company": "company-7"}
+ assert exposure.property_allowlist is None
+
+
+async def test_async_split_sends_both_events_with_exact_properties():
+ async def read(client: Any) -> None:
+ snapshot = await client.evaluate_flags(
+ DISTINCT_ID, groups={"company": 7}, disable_geoip=True
+ )
+ snapshot.get_flag(FLAG)
+
+ response = _response(_split(description="Assigned variant 'annual-first'"))
+ events = await _read_async_events([response], [read])
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE]
+ called, exposure = events
+ assert exposure.properties == EXPECTED_EXPOSURE
+ assert _attribution(called.properties) == EXPECTED_ATTRIBUTION
+ assert "$feature_flag_reason" not in called.properties
+ # The async client sends group keys as strings.
+ assert exposure.groups == called.groups == {"company": "7"}
+ assert exposure.distinct_id == called.distinct_id == DISTINCT_ID
+
+
+def test_the_pair_shares_capture_identity_but_not_its_uuid():
+ messages: List[Dict[str, Any]] = []
+
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(message)
+ return message
+
+ client = Client(FAKE_TEST_API_KEY, send=False, before_send=before_send)
+ try:
+ with _serving(_response(_split())):
+ snapshot = client.evaluate_flags(
+ DISTINCT_ID, groups={"company": "company-7"}, disable_geoip=True
+ )
+ assert snapshot.get_flag(FLAG) == "annual"
+ finally:
+ client.shutdown()
+
+ called, exposure = messages
+ assert (called["event"], exposure["event"]) == (FLAG_CALLED, EXPOSURE)
+ assert called["uuid"] and exposure["uuid"] and called["uuid"] != exposure["uuid"]
+ assert exposure["distinct_id"] == called["distinct_id"] == DISTINCT_ID
+ for name in ("$groups", "$lib", "$lib_version", "$geoip_disable"):
+ assert exposure["properties"][name] == called["properties"][name], name
+ assert exposure["properties"]["$groups"] == {"company": "company-7"}
+
+
+@pytest.mark.parametrize("path", SNAPSHOT_READS)
+def test_an_assignment_is_reported_whatever_the_read_returns(path):
+ # An experiment arm whose value is false still assigned the visitor to that arm.
+ response = _response(_split(value=False, variant_key="no-banner"))
+
+ events = _read_events(path, response)
+
+ [exposure] = _named(events, EXPOSURE)
+ assert exposure.properties["$feature_flag_response"] is False
+ assert exposure.properties["$feature_flag_variant_key"] == "no-banner"
+
+
+# --- What sends no exposure ------------------------------------------------------------
+
+
+@pytest.mark.parametrize("path", SINGLE_FLAG_READS)
+def test_opting_out_of_flag_events_suppresses_both(client, path):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording, warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ getattr(client, path)(FLAG, DISTINCT_ID, send_feature_flag_events=False)
+
+ assert events == []
+
+
+def test_a_payload_read_sends_no_flag_events(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording, warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ client.get_feature_flag_payload(FLAG, DISTINCT_ID)
+ snapshot = client.evaluate_flags(DISTINCT_ID)
+ snapshot.get_flag_payload(FLAG)
+
+ assert events == []
+
+
+def test_a_payload_read_that_sends_flag_events_also_sends_the_exposure(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording, warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ client.get_feature_flag_payload(
+ FLAG, DISTINCT_ID, send_feature_flag_events=True
+ )
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE]
+
+
+MATCH_VALUE_CASES = [
+ ("another value", _split(value="annual"), "monthly"),
+ ("the record's own value", _split(value="annual"), "annual"),
+ # Object and number arms both read as True, so equal values prove nothing about
+ # where a value came from.
+ ("an object arm", _split(value={"layout": "grid"}), True),
+ ("a number arm", _split(value=12.5), True),
+]
+
+
+@pytest.mark.parametrize("later_read", list(SYNC_READS))
+@pytest.mark.parametrize(
+ "record, match_value",
+ [case[1:] for case in MATCH_VALUE_CASES],
+ ids=[case[0] for case in MATCH_VALUE_CASES],
+)
+def test_a_payload_lookup_for_a_match_value_sends_no_exposure(
+ client, record, match_value, later_read
+):
+ # The lookup reports the caller's match_value, not the record's value, so it
+ # sends no exposure, whatever the value. A later read of the record does.
+ recording, events = _record_events(client)
+ with _serving(_response(record)), recording, warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ client.get_feature_flag_payload(
+ FLAG, DISTINCT_ID, match_value=match_value, send_feature_flag_events=True
+ )
+ [called] = events
+ assert called.name == FLAG_CALLED
+ assert called.properties["$feature_flag_response"] == match_value
+ # The record did not supply that value, so the call does not carry the
+ # record's attribution.
+ assert _attribution(called.properties) == {}
+
+ _read(client, later_read)
+
+ [exposure] = _named(events, EXPOSURE)
+ assert exposure.properties["$feature_flag_variant_key"] == "annual-first"
+
+
+def test_a_stale_cached_value_sends_no_exposure(client):
+ # The record arrived, but caching it failed, so the read reports the stale cached
+ # value instead. That value did not come from the record, even though it is equal.
+ cache = mock.Mock()
+ cache._set_cached_remote_flag.side_effect = RuntimeError("cache unavailable")
+ cache.get_stale_cached_flag.return_value = FeatureFlagResult(
+ key=FLAG, enabled=True, variant="annual", payload=None, reason=None
+ )
+ client.flag_cache = cache
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ result = client.get_feature_flag_result(FLAG, DISTINCT_ID)
+
+ assert result is not None and result.get_value() == "annual"
+ cache.get_stale_cached_flag.assert_called_once()
+ [called] = events
+ assert called.name == FLAG_CALLED
+ # The stale value is not attributed to the record's rule or variant.
+ assert _attribution(called.properties) == {}
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_a_locally_evaluated_flag_is_unchanged(path):
+ client = Client(FAKE_TEST_API_KEY, send=False, secret_key="secret-key")
+ client.feature_flags = [
+ {
+ "id": 9,
+ "name": "Pricing page",
+ "key": FLAG,
+ "active": True,
+ "filters": {
+ "groups": [{"properties": [], "rollout_percentage": 100}],
+ "multivariate": {
+ "variants": [{"key": "annual", "rollout_percentage": 100}]
+ },
+ },
+ }
+ ]
+ recording, events = _record_events(client)
+ try:
+ with _serving(_response(_split())) as remote, recording:
+ _read(client, path)
+ finally:
+ client.shutdown()
+
+ assert remote.call_count == 0
+ [called] = events
+ assert called.name == FLAG_CALLED
+ assert called.properties["locally_evaluated"] is True
+ assert _attribution(called.properties) == {}
+
+
+def test_an_empty_snapshot_sends_nothing(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ snapshot = client.evaluate_flags()
+ snapshot.get_flag(FLAG)
+ snapshot.is_enabled(FLAG)
+
+ assert events == []
+
+
+def test_a_failed_exposure_capture_does_not_change_the_read():
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ if message["event"] == EXPOSURE:
+ raise ValueError("rejected")
+ return message
+
+ client = Client(FAKE_TEST_API_KEY, send=False, before_send=before_send)
+ try:
+ with _serving(_response(_split())), warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ assert client.get_feature_flag(FLAG, DISTINCT_ID) == "annual"
+ assert client.evaluate_flags(DISTINCT_ID).get_flag(FLAG) == "annual"
+ finally:
+ client.shutdown()
+
+
+# --- Dedupe ------------------------------------------------------------------------
+
+
+@pytest.mark.parametrize(
+ "first, second",
+ [
+ ("get_feature_flag", "get_feature_flag"),
+ ("snapshot.get_flag", "snapshot.is_enabled"),
+ ("feature_enabled", "snapshot.get_flag"),
+ ("snapshot.get_flag", "get_feature_flag_result"),
+ ],
+)
+def test_a_repeated_read_sends_nothing_new(client, first, second):
+ # The second evaluation has a new request ID and time, which neither event's
+ # dedupe reads.
+ later = _response(
+ _split(), request_id=OTHER_REQUEST_ID, evaluated_at=EVALUATED_AT + 1
+ )
+ recording, events = _record_events(client)
+ with _serving(_response(_split()), later), recording:
+ _read(client, first)
+ _read(client, second)
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE]
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_equal_valued_arms_are_each_reported(path):
+ # An A/A experiment: both arms return the same value.
+ events = _read_events(
+ path,
+ _response(_split(value=True, variant_key="control")),
+ _response(_split(value=True, variant_key="test")),
+ reads=2,
+ )
+
+ exposures = _named(events, EXPOSURE)
+ assert [e.properties["$feature_flag_variant_key"] for e in exposures] == [
+ "control",
+ "test",
+ ]
+ assert len(_named(events, FLAG_CALLED)) == 2
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_a_later_experiment_on_the_flag_is_reported_again(path):
+ events = _read_events(
+ path,
+ _response(_split(rule_id=RULE)),
+ _response(_split(rule_id=OTHER_RULE)),
+ reads=2,
+ )
+
+ exposures = _named(events, EXPOSURE)
+ assert [e.properties["$feature_flag_rule_id"] for e in exposures] == [
+ RULE,
+ OTHER_RULE,
+ ]
+ assert len(_named(events, FLAG_CALLED)) == 2
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_the_exposure_dedupe_leaves_out_the_value(path):
+ # The arm's value changed, but the visitor is still in the same arm.
+ events = _read_events(
+ path,
+ _response(_split(value="annual")),
+ _response(_split(value="annual-v2")),
+ reads=2,
+ )
+
+ assert len(_named(events, FLAG_CALLED)) == 2
+ assert len(_named(events, EXPOSURE)) == 1
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_a_holdout_and_a_split_of_one_rule_are_both_reported(path):
+ holdout = _record(
+ "holdout", False, rule_type="experiment", rule_id=RULE, has_experiment=True
+ )
+ events = _read_events(
+ path, _response(holdout), _response(_split(value=False)), reads=2
+ )
+
+ called = _named(events, FLAG_CALLED)
+ assert [e.properties["$feature_flag_reason_code"] for e in called] == [
+ "holdout",
+ "experiment_split",
+ ]
+ assert len(_named(events, EXPOSURE)) == 1
+
+
+def test_groups_are_part_of_the_exposure_identity(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ _read(client, "snapshot.get_flag", groups={"company": "a", "team": "b"})
+ _read(client, "get_feature_flag", groups={"team": "b", "company": "a"})
+ _read(client, "snapshot.get_flag", groups={"company": "c"})
+
+ exposures = _named(events, EXPOSURE)
+ assert [e.groups for e in exposures] == [
+ {"company": "a", "team": "b"},
+ {"company": "c"},
+ ]
+
+
+def test_the_exposure_dedupe_normalizes_the_distinct_id(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ _read(client, "get_feature_flag_result", distinct_id=42)
+ _read(client, "snapshot.get_flag", distinct_id="42")
+
+ assert len(_named(events, EXPOSURE)) == 1
+
+
+def test_a_reported_call_never_suppresses_its_exposure(client):
+ # The two events dedupe apart. When only the exposure key is gone, as after an
+ # eviction, the next read sends the exposure again, although its call is a
+ # duplicate.
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ _read(client, "get_feature_flag")
+ client._experiment_exposures_reported.clear()
+ _read(client, "get_feature_flag")
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE, EXPOSURE]
+
+
+async def test_async_a_reported_call_never_suppresses_its_exposure():
+ async def read(client: Any) -> None:
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ snapshot.get_flag(FLAG)
+ client._experiment_exposures_reported.clear()
+ snapshot.get_flag(FLAG)
+
+ events = await _read_async_events([_response(_split())], [read])
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE, EXPOSURE]
+
+
+def test_a_read_whose_value_the_record_did_not_supply_is_reported_as_before(client):
+ # Such a read sends the config version 1 call and no exposure, and takes neither
+ # config version 2 dedupe key: a later read of the record sends both its events.
+ with _serving(_response(_split(description="Assigned variant annual-first"))):
+ details = client.evaluate_flags(DISTINCT_ID)._flags[FLAG].details
+ recording, events = _record_events(client)
+ with recording:
+ for value_from_details in (False, True):
+ client._capture_feature_flag_called_if_needed(
+ distinct_id=DISTINCT_ID,
+ key=FLAG,
+ response="annual",
+ properties={
+ "$feature_flag": FLAG,
+ "$feature_flag_response": "annual",
+ "$feature_flag_reason": "Assigned variant annual-first",
+ },
+ details=details,
+ value_from_details=value_from_details,
+ )
+
+ assert [event.name for event in events] == [FLAG_CALLED, FLAG_CALLED, EXPOSURE]
+ as_before, attributed = _named(events, FLAG_CALLED)
+ assert _attribution(as_before.properties) == {}
+ assert as_before.properties["$feature_flag_reason"] == (
+ "Assigned variant annual-first"
+ )
+ assert _attribution(attributed.properties) == EXPECTED_ATTRIBUTION
+ assert "$feature_flag_reason" not in attributed.properties
+
+
+async def test_async_snapshots_dedupe_both_events():
+ async def read(client: Any) -> None:
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ snapshot.get_flag(FLAG)
+ snapshot.is_enabled(FLAG)
+ snapshot.only([FLAG]).get_flag(FLAG)
+
+ events = await _read_async_events(
+ [
+ _response(_split(variant_key="control", value=True)),
+ _response(_split(variant_key="control", value=True)),
+ _response(_split(variant_key="test", value=True)),
+ ],
+ [read, read, read],
+ )
+
+ assert [e.properties["$feature_flag_variant_key"] for e in events] == [
+ "control",
+ "control",
+ "test",
+ "test",
+ ]
+ assert [e.name for e in events] == [FLAG_CALLED, EXPOSURE] * 2
+
+
+def test_the_v1_dedupe_key_is_unchanged(client):
+ with _serving(_build(READERS, {"template": "v1"})):
+ _read(client, "get_feature_flag", "garden-layout")
+
+ assert client.distinct_ids_feature_flags_reported[DISTINCT_ID] == {
+ ("garden-layout", "compact", ())
+ }
+ assert len(client._experiment_exposures_reported) == 0
+
+
+def test_shutdown_clears_the_exposure_dedupe():
+ client = Client(FAKE_TEST_API_KEY, send=False)
+ with _serving(_response(_split())):
+ _read(client, "snapshot.get_flag")
+ assert len(client._experiment_exposures_reported) == 1
+
+ client.shutdown()
+
+ assert len(client._experiment_exposures_reported) == 0
+
+
+async def test_async_shutdown_clears_the_exposure_dedupe():
+ with mock.patch(
+ "posthog.async_client._async_flags",
+ new=mock.AsyncMock(return_value=_response(_split())),
+ ):
+ client = AsyncPosthog("project-key", send=False)
+ (await client.evaluate_flags(DISTINCT_ID)).get_flag(FLAG)
+ assert len(client._experiment_exposures_reported) == 1
+ await client.shutdown()
+
+ assert len(client._experiment_exposures_reported) == 0
+
+
+# --- Minimal events -------------------------------------------------------------------
+
+
+def test_minimal_flag_called_events_keep_the_attribution():
+ messages: List[Dict[str, Any]] = []
+
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(message)
+ return message
+
+ client = Client(
+ FAKE_TEST_API_KEY,
+ send=False,
+ before_send=before_send,
+ super_properties={"plan": "team"},
+ )
+ # A split of an experiment rule no experiment links to: the flag reports no
+ # experiment, so its $feature_flag_called is minimal.
+ response = _response(_split(has_experiment=False), minimalFlagCalledEvents=True)
+ try:
+ with _serving(response):
+ client.evaluate_flags(DISTINCT_ID).get_flag(FLAG)
+ finally:
+ client.shutdown()
+
+ called, exposure = messages
+ assert set(called["properties"]) <= _MINIMAL_V2_FLAG_CALLED_EVENT_PROPERTIES
+ assert "plan" not in called["properties"]
+ assert _attribution(called["properties"]) == EXPECTED_ATTRIBUTION
+ # The exposure is a full event.
+ assert exposure["event"] == EXPOSURE
+ assert exposure["properties"]["plan"] == "team"
+ assert _attribution(exposure["properties"]) == _attribution(EXPECTED_EXPOSURE)
+
+
+# --- Reason codes, rule IDs and variant keys ---------------------------------------------
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize("code", ["future_reason", None], ids=["unknown", "missing"])
+def test_an_unknown_or_missing_reason_code_still_reports_config_version_2(code, path):
+ record = _split()
+ if code is None:
+ del record["reason"]
+ else:
+ record["reason"]["code"] = code
+
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ expected: Dict[str, Any] = {"$feature_flag_config_version": 2}
+ if code is not None:
+ expected["$feature_flag_reason_code"] = code
+ assert _attribution(called.properties) == expected
+ assert "$feature_flag_reason" not in called.properties
+ assert _named(events, EXPOSURE) == []
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+NOT_A_UUID = ["rule-1", "", "7F3C2A108D4E4B6A9C215E0F1A2B3C4D", "{" + RULE + "}"]
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag_result", "snapshot.get_flag"])
+@pytest.mark.parametrize("rule_id", NOT_A_UUID)
+def test_a_rule_id_that_is_not_a_uuid_counts_as_missing(rule_id, path):
+ for record in (
+ _split(rule_id=rule_id),
+ _record("targeting_match", rule_type="targeted_release", rule_id=rule_id),
+ ):
+ events = _read_events(path, _response(record))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert _attribution(called.properties) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": record["reason"]["code"],
+ }
+ assert _named(events, EXPOSURE) == []
+ FLAG_CALLED_SCHEMA.validate(_projection(FLAG_CALLED_SCHEMA, called.properties))
+
+
+def test_an_upper_case_uuid_rule_id_is_kept():
+ events = _read_events(
+ "get_feature_flag_result", _response(_split(rule_id=RULE.upper()))
+ )
+
+ [exposure] = _named(events, EXPOSURE)
+ assert exposure.properties["$feature_flag_rule_id"] == RULE.upper()
+
+
+@pytest.mark.parametrize("path", list(SYNC_READS))
+def test_an_empty_variant_key_is_a_complete_split(path):
+ events = _read_events(path, _response(_split(variant_key="")))
+
+ [called] = _named(events, FLAG_CALLED)
+ assert called.properties["$feature_flag_variant_key"] == ""
+ [exposure] = _named(events, EXPOSURE)
+ assert exposure.properties["$feature_flag_variant_key"] == ""
+ EXPOSURE_SCHEMA.validate(_projection(EXPOSURE_SCHEMA, exposure.properties))
+
+
+# --- Capture failures ----------------------------------------------------------------------
+
+
+def _dropping(event: str) -> Callable[[Dict[str, Any]], Optional[Dict[str, Any]]]:
+ """A before_send hook that drops the first ``event`` and keeps everything else."""
+ dropped: List[str] = []
+
+ def before_send(message: Dict[str, Any]) -> Optional[Dict[str, Any]]:
+ if message["event"] == event and not dropped:
+ dropped.append(event)
+ return None
+ return message
+
+ return before_send
+
+
+def _failing_once(client: Client, event: str, failure: str) -> Any:
+ """Patch ``client.capture`` to fail for the first ``event``, then capture as usual.
+
+ ``failure`` is ``"raise"`` for a raising capture, or ``"unqueued"`` for a capture
+ that returns ``None`` without ``before_send`` dropping the event, as a full or
+ closed queue, opt-out or a disabled client does.
+ """
+ capture = client.capture
+ failed: List[str] = []
+
+ def maybe_fail(name: str, **kwargs: Any) -> Optional[str]:
+ if name == event and not failed:
+ failed.append(name)
+ if failure == "raise":
+ raise RuntimeError("capture failed")
+ return None
+ return capture(name, **kwargs)
+
+ return mock.patch.object(client, "capture", side_effect=maybe_fail)
+
+
+def _sent(client: Client, path: str, reads: int = 2) -> List[str]:
+ """The events that reached the queue over ``reads`` reads of a complete split."""
+ sent: List[str] = []
+ enqueue = client._enqueue
+
+ def record(msg: Dict[str, Any], *args: Any, **kwargs: Any) -> Optional[str]:
+ uuid = enqueue(msg, *args, **kwargs)
+ if uuid is not None:
+ sent.append(msg["event"])
+ return uuid
+
+ with (
+ _serving(_response(_split())),
+ mock.patch.object(client, "_enqueue", side_effect=record),
+ ):
+ for _ in range(reads):
+ assert _read(client, path) == "annual"
+ return sent
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag", "snapshot.get_flag"])
+@pytest.mark.parametrize("event", [FLAG_CALLED, EXPOSURE])
+def test_an_event_dropped_by_before_send_keeps_its_dedupe_key(event, path):
+ client = Client(FAKE_TEST_API_KEY, send=False, before_send=_dropping(event))
+ try:
+ sent = _sent(client, path)
+ finally:
+ client.shutdown()
+
+ # The application dropped the event, so the second read does not send it again.
+ # The other event of the first read is still sent, once.
+ assert sent == [EXPOSURE if event == FLAG_CALLED else FLAG_CALLED]
+
+
+async def test_async_an_event_dropped_by_before_send_keeps_its_dedupe_key():
+ seen: List[str] = []
+ batches: List[Any] = []
+
+ def before_send(message: Dict[str, Any]) -> Optional[Dict[str, Any]]:
+ seen.append(message["event"])
+ return None if message["event"] == EXPOSURE else message
+
+ async def batch_post(*args: Any, **kwargs: Any) -> None:
+ batches.append(args[2] if len(args) > 2 else kwargs["batch"])
+
+ with (
+ mock.patch(
+ "posthog.async_client._async_flags",
+ new=mock.AsyncMock(return_value=_response(_split())),
+ ),
+ mock.patch(
+ "posthog._async_consumer.async_send_v1_batch", side_effect=batch_post
+ ),
+ ):
+ client = AsyncPosthog("project-key", before_send=before_send, flush_interval=30)
+ for _ in range(2):
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ assert snapshot.get_flag(FLAG) == "annual"
+ await client.flush(timeout_seconds=1)
+ await client.shutdown()
+
+ # before_send saw each event once: the dropped exposure kept its key, so the
+ # second read sent neither event again.
+ assert seen == [FLAG_CALLED, EXPOSURE]
+ sent = [event["event"] for batch in batches for event in batch]
+ assert sent == [FLAG_CALLED]
+
+
+@pytest.mark.parametrize("path", ["get_feature_flag", "snapshot.get_flag"])
+@pytest.mark.parametrize("event", [FLAG_CALLED, EXPOSURE])
+@pytest.mark.parametrize("failure", ["raise", "unqueued"])
+def test_a_failed_capture_keeps_no_dedupe_key(failure, event, path, client):
+ with _failing_once(client, event, failure):
+ sent = _sent(client, path)
+
+ # The other event of the first read is still sent, and the failed one is sent
+ # by the second read, once.
+ assert sorted(sent) == sorted([FLAG_CALLED, EXPOSURE])
+
+
+def test_an_unqueued_config_version_1_call_is_deduped_as_before(client):
+ record = _record("condition_match", "annual", config_version=1)
+ calls: List[str] = []
+
+ def unqueued(name: str, **kwargs: Any) -> None:
+ calls.append(name)
+ return None
+
+ with (
+ _serving(_response(record)),
+ mock.patch.object(client, "capture", side_effect=unqueued),
+ ):
+ _read(client, "get_feature_flag")
+ _read(client, "get_feature_flag")
+
+ # Config version 1 dedupe is unchanged: the attempt takes the key.
+ assert calls == [FLAG_CALLED]
+
+
+class _Rendezvous:
+ """Holds each of the first two callers until the other one arrives.
+
+ When the dedupe check and the reservation are one step, the second read waits
+ for the first one to finish both, so the wait times out instead.
+ """
+
+ def __init__(self) -> None:
+ self._barrier = threading.Barrier(2, timeout=0.25)
+ self._lock = threading.Lock()
+ self.arrivals = 0
+
+ def __call__(self) -> None:
+ with self._lock:
+ self.arrivals += 1
+ arrival = self.arrivals
+ if arrival <= 2:
+ try:
+ self._barrier.wait()
+ except threading.BrokenBarrierError:
+ pass
+
+
+class _MeetingSet(set):
+ """A dedupe set: each membership check reads the set, then meets the other read."""
+
+ def __init__(self, meet: _Rendezvous) -> None:
+ super().__init__()
+ self._meet = meet
+
+ def __contains__(self, item: Any) -> bool:
+ found = super().__contains__(item)
+ self._meet()
+ return found
+
+
+class _MeetingDict(SizeLimitedDict):
+ """A dedupe map: each lookup reads the map, then meets the other read."""
+
+ def __init__(self, meet: _Rendezvous) -> None:
+ super().__init__(MAX_DICT_SIZE, set)
+ self._meet = meet
+
+ def get(self, key: Any, default: Any = None) -> Any:
+ found = super().get(key, default)
+ self._meet()
+ return found
+
+
+@pytest.mark.parametrize("event", [FLAG_CALLED, EXPOSURE])
+@pytest.mark.parametrize("distinct_id", ["seen", "new"])
+def test_concurrent_reads_of_one_outcome_send_each_event_once(
+ client, event, distinct_id
+):
+ # Two reads of one outcome both look up the dedupe key before either goes on.
+ # Unless the check and the reservation are one step, both find no key and both
+ # send the event. "new" also races on the distinct ID's first entry.
+ meet = _Rendezvous()
+ attribute = (
+ "distinct_ids_feature_flags_reported"
+ if event == FLAG_CALLED
+ else "_experiment_exposures_reported"
+ )
+ if distinct_id == "seen":
+ getattr(client, attribute)[DISTINCT_ID] = _MeetingSet(meet)
+ else:
+ setattr(client, attribute, _MeetingDict(meet))
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ reads = [
+ threading.Thread(target=_read, args=(client, "get_feature_flag"))
+ for _ in range(2)
+ ]
+ for read in reads:
+ read.start()
+ for read in reads:
+ read.join(5)
+
+ assert meet.arrivals == 2
+ sent = [e.name for e in events if e.uuid is not None]
+ assert sorted(sent) == sorted([FLAG_CALLED, EXPOSURE])
+
+
+@pytest.mark.parametrize("delivered", [True, False], ids=["delivered", "failed"])
+def test_a_read_during_a_sync_mode_send_does_not_send_it_again(delivered):
+ # The second read runs while the first read's exposure is on the wire. It sends
+ # neither event. A send that fails releases the key, so a third read sends the
+ # exposure.
+ client = Client(FAKE_TEST_API_KEY, sync_mode=True)
+ sending = threading.Event()
+ finish = threading.Event()
+ posted: List[str] = []
+
+ def batch_post(*args: Any, **kwargs: Any) -> None:
+ [message] = args[2] if len(args) > 2 else kwargs["batch"]
+ posted.append(message["event"])
+ if message["event"] == EXPOSURE and posted.count(EXPOSURE) == 1:
+ sending.set()
+ finish.wait(5)
+ if not delivered:
+ raise RuntimeError("connection reset")
+
+ try:
+ with (
+ _serving(_response(_split())),
+ mock.patch("posthog.client._send_v1_batch", side_effect=batch_post),
+ ):
+ first = threading.Thread(target=_read, args=(client, "get_feature_flag"))
+ first.start()
+ assert sending.wait(5)
+ assert _read(client, "get_feature_flag") == "annual"
+ finish.set()
+ first.join(5)
+ assert _read(client, "get_feature_flag") == "annual"
+ finally:
+ finish.set()
+ client.shutdown()
+
+ assert posted == [FLAG_CALLED, EXPOSURE] + ([] if delivered else [EXPOSURE])
+
+
+def test_a_forked_child_replaces_the_dedupe_lock(client):
+ # A parent thread can hold the lock when the process forks. The child replaces
+ # it, so its reads do not wait for a thread the child does not have.
+ with posthog_client._flag_event_keys_lock:
+ posthog_client._reinit_flag_event_keys_lock_after_fork()
+ events = _read_events("get_feature_flag", _response(_split()), client=client)
+
+ assert [event.name for event in events] == [FLAG_CALLED, EXPOSURE]
+
+
+def test_a_flags_reload_does_not_repeat_an_exposure(client):
+ recording, events = _record_events(client)
+ with _serving(_response(_split())), recording:
+ _read(client, "get_feature_flag")
+ client._update_flag_state(
+ {"flags": [], "group_type_mapping": {}, "cohorts": {}}
+ )
+ _read(client, "get_feature_flag")
+ client.evaluate_flags(DISTINCT_ID).get_flag(FLAG)
+
+ assert len(_named(events, EXPOSURE)) == 1
+
+
+# --- Super properties ------------------------------------------------------------------------
+
+SPOOFED_SUPER_PROPERTIES = {
+ "$feature_flag_config_version": 7,
+ "$feature_flag_reason_code": "spoofed",
+ "$feature_flag_rule_type": "spoofed",
+ "$feature_flag_rule_id": OTHER_RULE,
+ "$feature_flag_variant_key": "spoofed",
+ "$feature_flag_reason": "spoofed",
+ "$feature_flag_forced_variant": True,
+ "$feature_flag_experiment_id": 301,
+ "$experiment_exposure_source": "spoofed",
+ # The flag identity of the read.
+ "$feature_flag": "spoofed",
+ "$feature_flag_response": "spoofed",
+ "locally_evaluated": True,
+}
+
+# What both events of a split read report about the read itself.
+EXPECTED_FLAG_IDENTITY = {
+ "$feature_flag": FLAG,
+ "$feature_flag_response": "annual",
+ "locally_evaluated": False,
+}
+
+
+def _flag_identity(properties: Mapping[str, Any]) -> Dict[str, Any]:
+ return {
+ name: properties[name] for name in EXPECTED_FLAG_IDENTITY if name in properties
+ }
+
+
+def _messages_with_super_properties(
+ record: Dict[str, Any], super_properties: Optional[Dict[str, Any]] = None
+) -> List[Dict[str, Any]]:
+ messages: List[Dict[str, Any]] = []
+
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(copy.deepcopy(message))
+ return message
+
+ client = Client(
+ FAKE_TEST_API_KEY,
+ send=False,
+ before_send=before_send,
+ super_properties=dict(
+ SPOOFED_SUPER_PROPERTIES if super_properties is None else super_properties
+ ),
+ )
+ try:
+ with _serving(_response(record)):
+ _read(client, "get_feature_flag")
+ finally:
+ client.shutdown()
+ return messages
+
+
+def test_super_properties_cannot_change_config_version_2_attribution():
+ messages = _messages_with_super_properties(_split())
+
+ [called] = [m for m in messages if m["event"] == FLAG_CALLED]
+ assert _attribution(called["properties"]) == EXPECTED_ATTRIBUTION
+ for name in (
+ "$feature_flag_reason",
+ "$feature_flag_forced_variant",
+ "$feature_flag_experiment_id",
+ ):
+ assert name not in called["properties"], name
+ [exposure] = [m for m in messages if m["event"] == EXPOSURE]
+ assert _attribution(exposure["properties"]) == _attribution(EXPECTED_EXPOSURE)
+ assert not set(EXPOSURE_LEAVES_OUT) & set(exposure["properties"])
+ for name in ("$feature_flag_experiment_id", "$feature_flag_forced_variant"):
+ assert name not in exposure["properties"], name
+ EXPOSURE_SCHEMA.validate(_projection(EXPOSURE_SCHEMA, exposure["properties"]))
+
+
+def test_super_properties_cannot_change_the_flag_identity_of_config_version_2_events():
+ messages = _messages_with_super_properties(_split())
+
+ # Both events report the same flag, response and evaluation source.
+ [called] = [m for m in messages if m["event"] == FLAG_CALLED]
+ assert _flag_identity(called["properties"]) == EXPECTED_FLAG_IDENTITY
+ [exposure] = [m for m in messages if m["event"] == EXPOSURE]
+ assert _flag_identity(exposure["properties"]) == EXPECTED_FLAG_IDENTITY
+
+
+def test_super_properties_cannot_add_rule_fields_a_config_version_2_call_omits():
+ messages = _messages_with_super_properties(_record("no_rule_match", False))
+
+ [called] = messages
+ assert _attribution(called["properties"]) == {
+ "$feature_flag_config_version": 2,
+ "$feature_flag_reason_code": "no_rule_match",
+ }
+
+
+def test_super_properties_still_apply_to_config_version_1_calls():
+ record = _record("condition_match", "annual", config_version=1)
+ [called] = _messages_with_super_properties(record)
+ [own] = _messages_with_super_properties(record, super_properties={})
+
+ # Nothing is pinned: super properties fill every key the event leaves unset,
+ # and the event's own values win, as on every event since 8.0.
+ filled = [
+ name for name in SPOOFED_SUPER_PROPERTIES if name not in own["properties"]
+ ]
+ assert filled
+ for name, value in SPOOFED_SUPER_PROPERTIES.items():
+ expected = own["properties"].get(name, value)
+ assert called["properties"][name] == expected, name
+
+
+async def test_async_super_properties_cannot_change_config_version_2_attribution():
+ messages: List[Dict[str, Any]] = []
+
+ # Super properties and the pinned attribution fill in before before_send.
+ def before_send(message: Dict[str, Any]) -> Dict[str, Any]:
+ messages.append(copy.deepcopy(message))
+ return message
+
+ with (
+ mock.patch(
+ "posthog.async_client._async_flags",
+ new=mock.AsyncMock(return_value=_response(_split())),
+ ),
+ mock.patch("posthog._async_consumer.async_send_v1_batch", new=mock.AsyncMock()),
+ ):
+ client = AsyncPosthog(
+ "project-key",
+ before_send=before_send,
+ super_properties=dict(SPOOFED_SUPER_PROPERTIES),
+ )
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ snapshot.get_flag(FLAG)
+ await client.flush(timeout_seconds=1)
+ await client.shutdown()
+
+ [called] = [m for m in messages if m["event"] == FLAG_CALLED]
+ assert _attribution(called["properties"]) == EXPECTED_ATTRIBUTION
+ assert _flag_identity(called["properties"]) == EXPECTED_FLAG_IDENTITY
+ assert "$feature_flag_reason" not in called["properties"]
+ [exposure] = [m for m in messages if m["event"] == EXPOSURE]
+ assert _attribution(exposure["properties"]) == _attribution(EXPECTED_EXPOSURE)
+ assert _flag_identity(exposure["properties"]) == EXPECTED_FLAG_IDENTITY
+ assert not set(EXPOSURE_LEAVES_OUT) & set(exposure["properties"])
diff --git a/posthog/test/test_feature_flags.py b/posthog/test/test_feature_flags.py
index eb89117b1..a18592db4 100644
--- a/posthog/test/test_feature_flags.py
+++ b/posthog/test/test_feature_flags.py
@@ -1192,6 +1192,78 @@ def test_experience_continuity_flag_not_evaluated_locally(self, patch_flags):
)
self.assertEqual(patch_flags.call_count, 1)
+ @parameterized.expand(
+ [
+ ("enrollment not passed", {}, 0, "flags-fallback-value", 1, False),
+ (
+ "enrolled",
+ {"$feature_enrollment/beta-feature": "true"},
+ 0,
+ True,
+ 0,
+ False,
+ ),
+ (
+ "opted out",
+ {"$feature_enrollment/beta-feature": False},
+ 100,
+ False,
+ 0,
+ False,
+ ),
+ (
+ "not a true value",
+ {"$feature_enrollment/beta-feature": 1},
+ 100,
+ False,
+ 0,
+ False,
+ ),
+ (
+ "group flag",
+ {"$feature_enrollment/beta-feature": False},
+ 100,
+ "flags-fallback-value",
+ 1,
+ True,
+ ),
+ ]
+ )
+ def test_feature_enrollment_flag(
+ self, _name, person_properties, rollout, expected, flags_calls, group
+ ):
+ client = Client(FAKE_TEST_API_KEY, secret_key="test")
+ client.feature_flags = [
+ {
+ "id": 1,
+ "key": "beta-feature",
+ "active": True,
+ "filters": {
+ "groups": [{"properties": [], "rollout_percentage": rollout}],
+ "feature_enrollment": True,
+ "aggregation_group_type_index": 0 if group else None,
+ },
+ }
+ ]
+ client.group_type_mapping = {"0": "company"}
+ with mock.patch("posthog.client.flags") as patch_flags:
+ patch_flags.return_value = {
+ "featureFlags": {"beta-feature": "flags-fallback-value"}
+ }
+ value = client.get_feature_flag(
+ "beta-feature",
+ "distinct_id",
+ person_properties=person_properties,
+ groups={"company": "acme"} if group else None,
+ group_properties={
+ "company": {"$feature_enrollment/beta-feature": "true"}
+ }
+ if group
+ else None,
+ )
+
+ self.assertEqual((value, patch_flags.call_count), (expected, flags_calls))
+
@mock.patch.object(Client, "capture")
@mock.patch("posthog.client.flags")
def test_get_all_flags_with_fallback(self, patch_flags, patch_capture):
@@ -7175,6 +7247,40 @@ def test_year_parsing_clamps_to_target_month_end(self):
"1y"
) == now - relativedelta(years=1)
+ def test_month_parsing_clamps_after_every_step(self):
+ cases = [
+ ("2025-03-31T12:00:00Z", "2m", (2025, 1, 28)),
+ ("2024-03-31T12:00:00Z", "2m", (2024, 1, 29)),
+ ("2025-05-31T12:00:00Z", "2m", (2025, 3, 30)),
+ ("2025-05-31T12:00:00Z", "4m", (2025, 1, 28)),
+ ("2025-01-31T12:00:00Z", "11m", (2024, 2, 29)),
+ ("2025-03-30T12:00:00Z", "13m", (2024, 2, 28)),
+ ]
+ for now, value, expected in cases:
+ with self.subTest(now=now, value=value), freeze_time(now):
+ assert relative_date_parse_for_feature_flag_matching(
+ value
+ ) == datetime.datetime(*expected, 12, tzinfo=datetime.timezone.utc)
+
+ def test_year_parsing_clamps_after_every_step(self):
+ cases = [
+ ("2024-02-29T12:00:00Z", "4y", (2020, 2, 28)),
+ ("2024-02-29T12:00:00Z", "2y", (2022, 2, 28)),
+ ("2024-03-31T12:00:00Z", "4y", (2020, 3, 31)),
+ ("2024-02-28T12:00:00Z", "4y", (2020, 2, 28)),
+ ]
+ for now, value, expected in cases:
+ with self.subTest(now=now, value=value), freeze_time(now):
+ assert relative_date_parse_for_feature_flag_matching(
+ value
+ ) == datetime.datetime(*expected, 12, tzinfo=datetime.timezone.utc)
+
+ def test_month_and_year_parsing_with_zero_keeps_the_date(self):
+ with freeze_time("2024-02-29T12:00:00Z"):
+ now = datetime.datetime.now(datetime.timezone.utc)
+ assert relative_date_parse_for_feature_flag_matching("0m") == now
+ assert relative_date_parse_for_feature_flag_matching("0y") == now
+
def test_year_parsing(self):
with freeze_time("2020-01-01T12:01:20.1340Z"):
assert relative_date_parse_for_feature_flag_matching(
diff --git a/posthog/test/test_flags_released_behaviour.py b/posthog/test/test_flags_released_behaviour.py
index 7ad8022f8..7f5dd12b9 100644
--- a/posthog/test/test_flags_released_behaviour.py
+++ b/posthog/test/test_flags_released_behaviour.py
@@ -30,7 +30,7 @@ def results(request: Any) -> Dict[str, Any]:
return scenarios.run_all(request.param)
-def test_every_legacy_getter_and_event_matches_7_82_1(results):
+def test_every_legacy_getter_and_event_matches_7_82_1(request, results):
expected = copy.deepcopy(RELEASED["getters"])
# A record without a flag ID or version reads them as absent (None), where 7.82.1
# read 0. Events already left out both, so only the parsed record differs.
@@ -38,6 +38,41 @@ def test_every_legacy_getter_and_event_matches_7_82_1(results):
assert (sparse["id"], sparse["version"]) == (0, 0)
sparse["id"] = sparse["version"] = None
+ # A failed record reads as disabled, so it has no payload, even when the record
+ # carries one. 7.82.1 returned that payload from the payload reads and sent it on
+ # the flag's $feature_flag_called events.
+ failed = expected["get_flags_decision"]["flags"]["server-failed"]["metadata"]
+ assert failed["payload"] == '{"columns": 2}'
+ failed["payload"] = None
+ for read in ["get_feature_flag_payload", "snapshot.get_flag_payload"]:
+ assert expected[f"{read}:server-failed"] == {"columns": 2}
+ expected[f"{read}:server-failed"] = None
+ assert expected["get_feature_flag_result:server-failed"][2] == {"columns": 2}
+ expected["get_feature_flag_result:server-failed"][2] = None
+ failed_events = [
+ properties
+ for _, properties in expected["events"]
+ if properties.get("$feature_flag") == "server-failed"
+ ]
+ assert failed_events
+ for properties in failed_events:
+ assert properties.pop("$feature_flag_payload") == {"columns": 2}
+
+ if request.node.callspec.params["results"] == "v4":
+ # A $feature_flag_called for a config version 2 record carries its config
+ # version and reason code in place of the reason text. Only the v4 shape says
+ # a record is config version 2; config version 1 events are unchanged.
+ for name, properties in expected["events"]:
+ if name == "$feature_flag_called" and properties[
+ "$feature_flag"
+ ].startswith("v2-"):
+ assert (
+ properties.pop("$feature_flag_reason")
+ == scenarios.MATCHED["description"]
+ )
+ properties["$feature_flag_config_version"] = 2
+ properties["$feature_flag_reason_code"] = scenarios.MATCHED["code"]
+
assert results["getters"] == expected
@@ -71,5 +106,14 @@ def test_fallback_cache_histories_match_7_82_1(results, name):
# An unreadable record now fails only itself, but a single-flag read of it
# still reports what 7.82.1 reported when the whole response failed: an
# unknown_error, no request details, and the cached value.
- expected = RELEASED["cache histories"][name]
+ expected = copy.deepcopy(RELEASED["cache histories"][name])
+ if name == "good, server failed, timeout":
+ # A failed record has no payload, even when the record carries one, so
+ # neither its read nor the cached result read after the timeout returns
+ # one, and their events leave it out. 7.82.1 returned it from both.
+ for result in expected["results"][1:]:
+ assert result[2] == {"theme": "dark"}
+ result[2] = None
+ for _, properties in expected["events"][1:]:
+ assert properties.pop("$feature_flag_payload") == {"theme": "dark"}
assert results["cache histories"][name] == expected
diff --git a/posthog/test/test_flags_v4_response.py b/posthog/test/test_flags_v4_response.py
index d6278b101..d86cf1d9f 100644
--- a/posthog/test/test_flags_v4_response.py
+++ b/posthog/test/test_flags_v4_response.py
@@ -1,8 +1,8 @@
-"""Reading the ``/flags?v=4`` response, checked against the released wire contract.
+"""Reading the ``/flags?v=4`` response, checked against the harness wire contract.
-The files in ``fixtures/feature_flag_rules_v2`` are copied unchanged from a released
-``PostHog/posthog-sdk-test-harness`` contract. ``SOURCE.json`` records the release and
-the digest of each file.
+The files in ``fixtures/feature_flag_rules_v2`` are copied unchanged from a
+``PostHog/posthog-sdk-test-harness`` contract. ``SOURCE.json`` records the revision,
+its release and the digest of each file.
"""
from __future__ import annotations
@@ -83,8 +83,9 @@ def _evaluate(client: Client, response: Dict[str, Any]) -> FeatureFlagEvaluation
def test_vendored_fixtures_match_the_recorded_release_digests():
source = _load("SOURCE.json")
- assert source["release"] == "1.22.0"
- assert source["contract_version"] == "7.0.0"
+ assert source["release"] == "1.30.0"
+ assert source["revision"] == "6414114501396d96aadf2412fdd8054a03076782"
+ assert source["contract_version"] == "10.0.0"
for name, entry in source["files"].items():
digest = hashlib.sha256((FIXTURES / name).read_bytes()).hexdigest()
assert digest == entry["sha256"], name
@@ -746,6 +747,109 @@ def test_a_config_version_1_payload_is_kept():
assert flags["string-flag"].metadata.payload == '{"columns": 2}'
+def _failed_with_payload(shape: str) -> Dict[str, Any]:
+ """A failed record that still carries a payload, in the given response shape."""
+ if shape == "v4":
+ # A producer-valid failed config version 1 record with a payload.
+ [case] = [c for c in READERS["cases"] if c["id"] == "readers.v1_failed"]
+ response = _build(READERS, case)
+ record = response["flags"]["garden-layout"]
+ assert record["failed"] is True
+ assert record["metadata"]["payload"] == '{"columns":2}'
+ return response
+ record = _older_record(enabled=False, variant=None, failed=True)
+ record["metadata"]["payload"] = '{"columns":2}'
+ return {"flags": {"garden-layout": record}, "requestId": "r1"}
+
+
+@pytest.mark.parametrize("shape", ["v4", "older"])
+def test_a_failed_record_has_no_payload_on_any_read(shape, client):
+ # A failed flag reads as disabled, so a payload on it would surprise the caller.
+ response = _failed_with_payload(shape)
+ [flag] = normalize_flags_response(copy.deepcopy(response))["flags"].values()
+ assert flag._failed is True
+ assert flag.metadata.payload is None
+
+ with mock.patch("posthog.client.flags", return_value=copy.deepcopy(response)):
+ result = client.get_feature_flag_result("garden-layout", DISTINCT_ID)
+ assert result is not None and result.payload is None
+ assert client.get_feature_flag_payload("garden-layout", DISTINCT_ID) is None
+ assert (
+ client.get_feature_flag_payload(
+ "garden-layout", "user-2", send_feature_flag_events=True
+ )
+ is None
+ )
+ payloads = client.get_all_flags_and_payloads(DISTINCT_ID)["featureFlagPayloads"]
+ assert "garden-layout" not in (payloads or {})
+ assert "garden-layout" not in (client.get_feature_payloads(DISTINCT_ID) or {})
+ snapshot = client.evaluate_flags(DISTINCT_ID)
+ assert snapshot.get_flag_payload("garden-layout") is None
+
+
+def _disabled_with_payload(shape: str, failed: Any) -> Dict[str, Any]:
+ """A disabled record that is not failed and carries a payload.
+
+ ``failed`` is the value of the record's ``failed`` field, or ``_ABSENT`` to
+ leave the field out.
+ """
+ if shape == "v4":
+ [case] = [c for c in READERS["cases"] if c["id"] == "readers.v1_at_v4"]
+ response = _build(READERS, case)
+ record = response["flags"]["garden-layout"]
+ record["value"] = False
+ record["reason"] = {"code": "no_condition_match", "condition_index": None}
+ del record["metadata"]["variant_key"]
+ assert record["metadata"]["payload"] == '{"columns":2}'
+ else:
+ record = _older_record(enabled=False, variant=None)
+ record["metadata"]["payload"] = '{"columns":2}'
+ response = {"flags": {"garden-layout": record}, "requestId": "r1"}
+ if failed is _ABSENT:
+ record.pop("failed", None)
+ else:
+ record["failed"] = failed
+ return response
+
+
+_ABSENT = object()
+
+
+# A null ``failed`` is a null optional field, which both parsers ignore, so it is a
+# valid control in both shapes.
+@pytest.mark.parametrize(
+ "failed", [False, None, _ABSENT], ids=["false", "null", "absent"]
+)
+@pytest.mark.parametrize("shape", ["v4", "older"])
+def test_a_disabled_record_that_is_not_failed_keeps_its_payload(shape, failed, client):
+ # The control for the test above: only a failed record loses its payload.
+ response = _disabled_with_payload(shape, failed)
+ [flag] = normalize_flags_response(copy.deepcopy(response))["flags"].values()
+ assert flag._failed is False
+ assert flag.metadata.payload == '{"columns":2}'
+
+ with mock.patch("posthog.client.flags", return_value=copy.deepcopy(response)):
+ result = client.get_feature_flag_result("garden-layout", DISTINCT_ID)
+ assert result is not None and result.payload == {"columns": 2}
+ assert client.get_feature_flag_payload("garden-layout", DISTINCT_ID) == {
+ "columns": 2
+ }
+ snapshot = client.evaluate_flags(DISTINCT_ID)
+ assert snapshot.get_flag_payload("garden-layout") == {"columns": 2}
+
+
+async def test_a_failed_record_has_no_payload_on_the_async_client():
+ with mock.patch(
+ "posthog.async_client._async_flags",
+ new=mock.AsyncMock(return_value=_failed_with_payload("v4")),
+ ):
+ client = AsyncPosthog("project-key", send=False)
+ snapshot = await client.evaluate_flags(DISTINCT_ID)
+ await client.shutdown()
+
+ assert snapshot.get_flag_payload("garden-layout") is None
+
+
def test_feature_flag_value_defaults_to_the_legacy_value():
assert FeatureFlag.from_value_and_payload("a", "control", None)._value == "control"
assert FeatureFlag.from_value_and_payload("a", True, None)._value is True
@@ -1009,11 +1113,27 @@ def _parity_response(shape: str) -> Dict[str, Any]:
}
+# A config version 2 record adds these to its flag events, and leaves out
+# $feature_flag_reason. A v2-shaped response has no config version 2 records, so they
+# are left out of the comparison of the v2-* flags and checked in
+# test_experiment_exposure.py.
+_CONFIG_VERSION_2_EVENT_PROPERTIES = {
+ "$feature_flag_config_version",
+ "$feature_flag_reason_code",
+ "$feature_flag_rule_id",
+ "$feature_flag_rule_type",
+ "$feature_flag_variant_key",
+}
+
+
def _flag_event_properties(message: Dict[str, Any]) -> Dict[str, Any]:
+ left_out = set(_CONFIG_VERSION_2_EVENT_PROPERTIES)
+ if str(message["properties"].get("$feature_flag", "")).startswith("v2-"):
+ left_out.add("$feature_flag_reason")
return {
key: value
for key, value in message["properties"].items()
- if key.startswith("$feature")
+ if (key.startswith("$feature") and key not in left_out)
or key in ("$active_feature_flags", "locally_evaluated")
}
@@ -1030,7 +1150,9 @@ def response(*args: Any, **kwargs: Any) -> Dict[str, Any]:
# Read the built event in before_send: v1 layers flag properties inside _enqueue.
def record(message: Dict[str, Any]) -> Optional[Dict[str, Any]]:
events.append((message["event"], _flag_event_properties(message)))
- return None
+ # Keep the event, so capture accepts it and returns its UUID as the real
+ # queue does; flag events dedupe only events that were accepted.
+ return message
try:
with (
diff --git a/posthog/test/test_metrics_autocapture.py b/posthog/test/test_metrics_autocapture.py
index e69310b49..57221289d 100644
--- a/posthog/test/test_metrics_autocapture.py
+++ b/posthog/test/test_metrics_autocapture.py
@@ -941,7 +941,12 @@ def test_does_not_propagate_context_to_other_services(
for request in app_server.received:
headers = {key.lower() for key in request["headers"]}
assert not headers & {"traceparent", "tracestate", "baggage"}
- assert len(_points(reader, "http.client.request.duration")) == 2
+ points = [
+ point
+ for point in _points(reader, "http.client.request.duration")
+ if point.attributes.get("server.port") == app_server.port
+ ]
+ assert len(points) == 2
handle.shutdown()
requests_instrumentation = sys.modules["opentelemetry.instrumentation.requests"]
diff --git a/posthog/test/test_reference_markdown.py b/posthog/test/test_reference_markdown.py
new file mode 100644
index 000000000..bba347504
--- /dev/null
+++ b/posthog/test/test_reference_markdown.py
@@ -0,0 +1,67 @@
+"""Checks the Markdown reference generator's signatures, which griffe2md's own template got wrong."""
+
+import importlib.util
+from pathlib import Path
+
+import pytest
+
+griffe = pytest.importorskip("griffe")
+pytest.importorskip("griffe2md")
+
+ROOT = Path(__file__).resolve().parents[2]
+_spec = importlib.util.spec_from_file_location(
+ "generate_markdown", ROOT / "bin/docs_scripts/generate_markdown.py"
+)
+generator = importlib.util.module_from_spec(_spec)
+_spec.loader.exec_module(generator)
+
+
+@pytest.fixture(scope="module")
+def pkg():
+ return griffe.load(
+ "posthog",
+ search_paths=[str(ROOT)],
+ docstring_parser="google",
+ docstring_options={"returns_multiple_items": False},
+ resolve_aliases=False,
+ )
+
+
+def declaration(pkg, path: str) -> str:
+ """The first line of the entry's code block."""
+ md = generator.entry(pkg[path], path)
+ return md.split("```python\n", 1)[1].split("\n", 1)[0]
+
+
+def test_unannotated_parameters_get_no_annotation(pkg):
+ line = declaration(pkg, "client.Client.__init__")
+ assert "debug=False" in line
+ assert "debug: str" not in line
+ assert "_use_ai_lane" not in line, "private parameters stay out of the signature"
+
+
+def test_coroutines_are_marked_async(pkg):
+ assert declaration(pkg, "async_client.AsyncClient.flush").startswith("async ")
+ assert not declaration(pkg, "async_client.AsyncClient.capture").startswith("async ")
+
+
+def test_keyword_only_marker_is_kept(pkg):
+ assert ", *, groups" in declaration(pkg, "client.Client.evaluate_flags")
+
+
+def test_constructor_is_called_by_its_class_name(pkg):
+ assert declaration(pkg, "client.Client.__init__").startswith("Client(")
+
+
+def test_a_wrapped_returns_description_is_one_row(pkg):
+ md = generator.entry(
+ pkg["client.Client.get_feature_flag_payload"], "Client.get_feature_flag_payload"
+ )
+ assert md.count("`Optional[object]` |") == 1
+
+
+def test_summaries_keep_the_whole_first_paragraph(pkg):
+ cls = pkg["feature_flag_evaluations.FeatureFlagEvaluations"]
+ generator.clean(cls)
+ md = generator.entry(cls, "FeatureFlagEvaluations")
+ assert "on the first access per (distinct_id, flag, value) tuple" in md
diff --git a/posthog/test/test_request.py b/posthog/test/test_request.py
index 1f3d41f9b..c93db997a 100644
--- a/posthog/test/test_request.py
+++ b/posthog/test/test_request.py
@@ -1,4 +1,5 @@
import json
+import socket
import unittest
from datetime import date, datetime, timedelta
from unittest import mock
@@ -591,6 +592,60 @@ def test_flags_retries_transport_errors_once_by_default(
self.assertEqual(mock_session.post.call_count, 2)
mock_sleep.assert_called_once_with(0.3)
+ @mock.patch("posthog.request.time.sleep")
+ def test_flags_does_not_retry_refused_connection(self, mock_sleep):
+ # Bind and close a socket so the port refuses connections.
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ sock.bind(("127.0.0.1", 0))
+ port = sock.getsockname()[1]
+
+ with mock.patch("posthog.request.post", wraps=request_module.post) as mock_post:
+ with self.assertRaises(requests.exceptions.ConnectionError):
+ flags(
+ "test-key",
+ f"http://127.0.0.1:{port}",
+ max_retries=2,
+ distinct_id="user123",
+ )
+
+ self.assertEqual(mock_post.call_count, 1)
+ mock_sleep.assert_not_called()
+
+ @mock.patch("posthog.request.time.sleep")
+ @mock.patch("posthog.request._get_flags_session")
+ def test_flags_retries_when_handling_an_unrelated_refused_connection(
+ self, mock_get_flags_session, mock_sleep
+ ):
+ mock_response = requests.Response()
+ mock_response.status_code = 200
+ mock_response._content = json.dumps(
+ {
+ "featureFlags": {"test-flag": True},
+ "featureFlagPayloads": {},
+ "errorsWhileComputingFlags": False,
+ }
+ ).encode("utf-8")
+
+ mock_session = mock.MagicMock()
+ mock_session.post.side_effect = [
+ requests.exceptions.Timeout("timed out"),
+ mock_response,
+ ]
+ mock_get_flags_session.return_value = mock_session
+
+ # The application evaluates flags while handling its own refused
+ # connection, so the timeout inherits that error as its __context__.
+ try:
+ raise ConnectionRefusedError("database is down")
+ except ConnectionRefusedError:
+ response = flags(
+ "test-key", "https://test.posthog.com", distinct_id="user123"
+ )
+
+ self.assertEqual(response["featureFlags"], {"test-flag": True})
+ self.assertEqual(mock_session.post.call_count, 2)
+ mock_sleep.assert_called_once_with(0.3)
+
@mock.patch("posthog.request.time.sleep")
@mock.patch("posthog.request._get_flags_session")
def test_flags_retry_count_zero_disables_retries(
diff --git a/posthog/types.py b/posthog/types.py
index 85938a939..229b25a16 100644
--- a/posthog/types.py
+++ b/posthog/types.py
@@ -84,6 +84,11 @@ class FeatureFlagEvaluationRuntime(str, Enum):
``ALL`` means the flag suits both client-side and server-side evaluation, so
it matches either runtime. Inheriting from ``str`` keeps the members directly
comparable to their ``"all"`` / ``"client"`` / ``"server"`` values.
+
+ Values:
+ ALL: The flag suits both client-side and server-side evaluation.
+ CLIENT: The flag is meant for client-side evaluation.
+ SERVER: The flag is meant for server-side evaluation.
"""
ALL = "all"
@@ -278,6 +283,7 @@ def __post_init__(self) -> None:
)
def get_value(self) -> FlagValue:
+ """Return the variant for a multivariate flag, otherwise whether the flag is enabled."""
return self.variant or self.enabled
@classmethod
@@ -294,6 +300,7 @@ def from_json(cls, resp: Any) -> "FeatureFlag":
def from_value_and_payload(
cls, key: str, value: FlagValue, payload: Any
) -> "FeatureFlag":
+ """Build a flag from its value and payload. A string value is a variant, so the flag is enabled."""
enabled, variant = (True, value) if isinstance(value, str) else (value, None)
return cls(
key=key,
@@ -389,13 +396,15 @@ def _parse_typed_record(cls: Type[_F], key: str, resp: Any) -> _F:
if raw_metadata is None:
metadata = LegacyFlagMetadata(payload=encoded_payload)
else:
+ # A number or object value is its own payload; a payload the record also
+ # carries is ignored. A failed record reads as disabled, so it has no
+ # payload, even when the record carries one.
+ payload = encoded_payload
+ if payload is None and not failed:
+ payload = raw_metadata.get("payload")
metadata = FlagMetadata(
id=_read_int(raw_metadata.get("id"), "metadata.id"),
- # A number or object value is its own payload; a payload the record
- # also carries is ignored.
- payload=encoded_payload
- if encoded_payload is not None
- else raw_metadata.get("payload"),
+ payload=payload,
version=_read_int(raw_metadata.get("version"), "metadata.version"),
description=_read_typed(
raw_metadata.get("description", ""), "metadata.description", str
@@ -469,6 +478,10 @@ def _parse_older_record(cls: Type[_F], key: str, resp: Dict[str, Any]) -> _F:
except _MalformedRecord as error:
return _malformed_record(cls, key, str(error))
+ failed = resp.get("failed") is True
+ if failed and raw_metadata:
+ # A failed record has no payload, even when the record carries one.
+ raw_metadata = {**raw_metadata, "payload": None}
flag = cls(
key=key,
# An older server always sends ``enabled``; a record without it keeps
@@ -478,7 +491,7 @@ def _parse_older_record(cls: Type[_F], key: str, resp: Dict[str, Any]) -> _F:
reason=FlagReason.from_json(raw_reason),
metadata=FlagMetadata.from_json(raw_metadata),
)
- return _set_private_fields(flag, _failed=resp.get("failed") is True)
+ return _set_private_fields(flag, _failed=failed)
def _read_record_key(resp: Dict[str, Any]) -> None:
@@ -542,7 +555,12 @@ class FlagsResponse(TypedDict, total=False):
class FlagsAndPayloads(TypedDict, total=True):
- """Feature flag values and payloads keyed by feature flag key."""
+ """Feature flag values and payloads keyed by feature flag key.
+
+ Attributes:
+ featureFlags: Each flag's value, keyed by flag key.
+ featureFlagPayloads: Each flag's payload, keyed by flag key.
+ """
featureFlags: Optional[dict[str, FlagValue]]
featureFlagPayloads: Optional[dict[str, Any]]
diff --git a/posthog/version.py b/posthog/version.py
index 3d6336f75..b650937f8 100644
--- a/posthog/version.py
+++ b/posthog/version.py
@@ -1 +1 @@
-VERSION = "7.83.1"
+VERSION = "7.87.1"
diff --git a/pyproject.toml b/pyproject.toml
index f7b25e685..f0bd483f2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "posthog"
-version = "7.83.1"
+version = "7.87.1"
description = "Integrate PostHog into any python application."
authors = [{ name = "PostHog", email = "engineering@posthog.com" }]
maintainers = [{ name = "PostHog", email = "engineering@posthog.com" }]
@@ -63,6 +63,7 @@ metrics = [
dev = [
"django-stubs",
"griffe",
+ "griffe2md",
"lxml",
"mypy",
"mypy-baseline",
@@ -122,6 +123,9 @@ test = [
"opentelemetry-instrumentation-django>=0.60b0",
"pytest-bdd>=8.1.0",
"zstandard>=0.23.0",
+ # posthog/test/test_reference_markdown.py checks the reference generator's output.
+ "griffe",
+ "griffe2md",
# gevent 25.4.1+ replaces queue.Queue, exercising the compatibility path.
"gevent>=25.4.1; implementation_name == 'cpython'",
]
diff --git a/references/posthog-python-7.md b/references/posthog-python-7.md
new file mode 100644
index 000000000..bfa813789
--- /dev/null
+++ b/references/posthog-python-7.md
@@ -0,0 +1,4110 @@
+---
+title: "PostHog Python SDK 7.x"
+sidebar: Docs
+showTitle: true
+contentMaxWidthClass: max-w-full
+platformLogo: python
+tableOfContents:
+ - value: "Getting started"
+ url: getting-started
+ depth: 0
+ - value: "Setup"
+ url: setup
+ depth: 0
+ - value: "Capture"
+ url: capture
+ depth: 0
+ - value: "Identify"
+ url: identify
+ depth: 0
+ - value: "Traces"
+ url: traces
+ depth: 0
+ - value: "Alias"
+ url: alias
+ depth: 0
+ - value: "Capture AI"
+ url: capture-ai
+ depth: 0
+ - value: "Capture exception"
+ url: capture-exception
+ depth: 0
+ - value: "Emails"
+ url: emails
+ depth: 0
+ - value: "Flush"
+ url: flush
+ depth: 0
+ - value: "Get feature flag"
+ url: get-feature-flag
+ depth: 0
+ - value: "Get feature flag payload"
+ url: get-feature-flag-payload
+ depth: 0
+ - value: "Get feature flag result"
+ url: get-feature-flag-result
+ depth: 0
+ - value: "Get feature flags"
+ url: get-feature-flags
+ depth: 0
+ - value: "Get feature flags and payloads"
+ url: get-feature-flags-and-payloads
+ depth: 0
+ - value: "Evaluate flags"
+ url: evaluate-flags
+ depth: 0
+ - value: "Group identify"
+ url: group-identify
+ depth: 0
+ - value: "Is feature enabled"
+ url: is-feature-enabled
+ depth: 0
+ - value: "Shutdown"
+ url: shutdown
+ depth: 0
+ - value: "Flag definition loader"
+ url: flag-definition-loader
+ depth: 0
+ - value: "SDK utils"
+ url: sdk-utils
+ depth: 0
+ - value: "AsyncClient"
+ url: asyncclient
+ depth: 0
+ - value: "Module functions"
+ url: module-functions
+ depth: 0
+ - value: "Types"
+ url: types
+ depth: 0
+---
+
+## Getting started
+
+
+The Python SDK captures events, evaluates feature flags and reports errors from Python 3.10 or later.
+
+To send your first event, install the package, create a client, capture an event, and shut the client down, as the steps below show.
+
+### Install
+
+```bash
+pip install posthog
+```
+
+### Initialize
+
+Create one client for your app with your project token and host. Your project token and host are in your [project settings](https://app.posthog.com/project/settings). Keep the token in an environment variable rather than in code.
+
+```python
+from posthog import Posthog
+
+posthog = Posthog("", host="")
+```
+
+### Capture an event
+
+```python
+posthog.capture("user_signed_up", distinct_id="user_123", properties={"plan": "free"})
+```
+
+`capture` queues the event and returns right away. A background thread sends it.
+
+### Shut down
+
+Call `shutdown()` before your process exits, so queued events are sent.
+
+```python
+posthog.shutdown()
+```
+
+In an asyncio app, use `AsyncPosthog` as an async context manager instead. See [AsyncClient](#asyncclient).
+
+## Setup
+
+### `Client(...)`
+
+```python
+Client(project_api_key: str, host=None, debug=False, max_queue_size=10000, send=True, on_error=None, flush_at=100, flush_interval=5.0, gzip=False, max_retries=3, sync_mode=False, timeout: float = 15, thread=1, poll_interval=30, personal_api_key=None, disabled=False, disable_geoip=True, is_server=True, historical_migration=False, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries=1, super_properties=None, enable_exception_autocapture=False, log_captured_exceptions=False, project_root=None, privacy_mode=False, before_send=None, flag_fallback_cache_url=None, enable_local_evaluation=True, flag_definition_cache_provider: Optional[FlagDefinitionCacheProvider] = None, capture_exception_code_variables=False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: list[str] | None = None, enable_exception_autocapture_rate_limiting=False, exception_autocapture_bucket_size=ExceptionCapture.DEFAULT_BUCKET_SIZE, exception_autocapture_refill_rate=ExceptionCapture.DEFAULT_REFILL_RATE, exception_autocapture_refill_interval_seconds=ExceptionCapture.DEFAULT_REFILL_INTERVAL_SECONDS, capture_mode: Optional[Union[CaptureMode, str]] = None, capture_compression: Optional[Union[CaptureCompression, str]] = None, secret_key=None, metrics: Optional[dict] = None, enable_full_ai_capture=False, capture_trace_context=False, traces: Optional[dict] = None, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None)
+```
+
+Initialize a new PostHog client instance.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`project_api_key` | `str` | PostHog project API key/token. | *required*
+`host` | | PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as `https://us.posthog.com` are mapped to the corresponding ingestion host. | `None`
+`debug` | | Enable verbose SDK logging and re-raise errors from public API methods. | `False`
+`max_queue_size` | | Maximum number of events buffered before upload. | `10000`
+`send` | | If False, queueing succeeds but events are not sent. | `True`
+`on_error` | | Optional callback invoked by background consumers when an upload fails. Keep it short and non-blocking. Calling lifecycle methods directly is safe and deferred, but do not start another thread or task that calls `flush()`, `join()`, or `shutdown()` and then wait for it from the callback. | `None`
+`flush_at` | | Number of queued events that triggers a batch upload. | `100`
+`flush_interval` | | Maximum seconds a background consumer waits before flushing a partial batch. | `5.0`
+`gzip` | | Whether to gzip event upload payloads. | `False`
+`max_retries` | | Number of upload retries. Values below 0 are treated as 0. | `3`
+`sync_mode` | | If True, send each event synchronously instead of using background worker threads. This blocks the calling thread; in asyncio applications such as FastAPI, use `AsyncPosthog` instead. | `False`
+`timeout` | `float` | HTTP request timeout in seconds for event uploads. | `15`
+`thread` | | Number of background consumer threads. | `1`
+`poll_interval` | | Seconds between local feature flag definition refreshes. | `30`
+`secret_key` | | A Personal API Key or Project Secret API Key, used to authenticate local feature flag evaluation, remote config payloads, and decrypted flag payloads. For example, `posthog.Client(project_api_key, secret_key="phx_...")`. | `None`
+`personal_api_key` | | Deprecated alias for `secret_key`. Still honored for backwards compatibility; prefer `secret_key`, which also accepts a Project Secret API Key. | `None`
+`disabled` | | If True, disable captures and API requests. Useful in tests. | `False`
+`disable_geoip` | | Whether to disable server-side GeoIP enrichment. Defaults to True. | `True`
+`is_server` | | Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally. | `True`
+`historical_migration` | | Mark events as historical migration imports. | `False`
+`feature_flags_request_timeout_seconds` | `float` | Timeout in seconds for feature flag and remote config requests. | `3`
+`feature_flags_request_max_retries` | | Number of retries for feature flag requests after network, transport, or timeout failures. Defaults to 1. Set to 0 to disable retries. | `1`
+`app_host` | `Optional[str]` | Your PostHog app host, such as `https://posthog.example.com`. `emails` sends there. Needed only when `host` is not PostHog Cloud, for example a reverse proxy, which must not receive the secret key. | `None`
+`email_request_timeout_seconds` | `float` | Timeout in seconds for each email send request. Defaults to 15. | `15`
+`email_request_max_retries` | `int` | Number of retries for an email send after a network error, a rate limit, or an unavailable service. Defaults to 2. Set to 0 when a job runner already retries the send. | `2`
+`migrated_from` | `Optional[str]` | The email provider you moved from, such as `"resend"`. `emails` sends it with every request. | `None`
+`super_properties` | | Properties merged into every captured event. | `None`
+`enable_exception_autocapture` | | Automatically capture uncaught exceptions. | `False`
+`log_captured_exceptions` | | Also log exceptions captured by error tracking. | `False`
+`project_root` | | Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory. | `None`
+`privacy_mode` | | For AI observability, capture usage metadata without prompt inputs or outputs. | `False`
+`enable_full_ai_capture` | | Route PostHog AI wrapper events through the dedicated AI capture endpoint and capture full AI content: skips string truncation and passes media (base64/data URIs) through unredacted. `privacy_mode` always wins. Defaults to False. | `False`
+`before_send` | | Optional callback that can modify or drop events before upload. Return `None` to drop an event. | `None`
+`flag_fallback_cache_url` | | Optional feature flag fallback cache URL, such as `memory://local/?ttl=300&size=10000` or a Redis URL. | `None`
+`enable_local_evaluation` | | Whether to poll feature flag definitions for local evaluation when a personal API key is configured. | `True`
+`flag_definition_cache_provider` | `Optional[FlagDefinitionCacheProvider]` | Optional external cache provider for sharing feature flag definitions across workers. | `None`
+`capture_exception_code_variables` | | Capture local variable values on exception stack frames. | `False`
+`capture_trace_context` | | When OpenTelemetry is installed and a valid span is active at capture time, add its trace and span IDs as `$trace_id` and `$span_id` properties to events captured with `capture()` and `capture_ai()`, so they can be correlated with backend traces. Explicit `$trace_id`/`$span_id` values passed in `properties` win. Exception events (`capture_exception`) always attach these IDs regardless of this setting. Defaults to False. | `False`
+`traces` | `Optional[dict]` | Config dict for distributed tracing: `service_name`, `service_version`, `environment`, `resource_attributes`, `flush_interval` (5 s), `max_queue_size` (2048), `max_export_batch_size` (512), `max_live_spans` (10000), `max_span_age` (3600 s), `max_attributes_per_span` (128), `max_events_per_span` (128), `max_attribute_value_length` (8192). `before_span_send` is a callable, or a list run in order, that receives each finished span as a dict (`trace_id`, `span_id` and `parent_span_id` are read-only) and returns it, edited, or `None` to drop it; a hook that raises drops the span. Tracing is off until this is provided. Spans export on a background timer even with `sync_mode`; serverless handlers should call `flush()` before returning. Defaults to None. | `None`
+`code_variables_mask_patterns` | | Variable-name patterns to mask when capturing code variables. | `None`
+`code_variables_ignore_patterns` | | Variable-name patterns to omit when capturing code variables. | `None`
+`code_variables_mask_url_credentials` | | Scrub credentials embedded in URLs/DSNs (e.g. `user:pass@host`) from captured code variables, regardless of the surrounding variable name. Defaults to True. | `None`
+`code_variables_detect_secrets` | | Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True. | `None`
+`in_app_modules` | `list[str] \| None` | Module/package prefixes treated as in-app frames in captured exceptions. | `None`
+`enable_exception_autocapture_rate_limiting` | | Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default. | `False`
+`exception_autocapture_bucket_size` | | Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100). | `DEFAULT_BUCKET_SIZE`
+`exception_autocapture_refill_rate` | | Tokens restored per refill interval for each exception type's bucket. | `DEFAULT_REFILL_RATE`
+`exception_autocapture_refill_interval_seconds` | | Seconds between token refills for autocaptured exception rate limiting. | `DEFAULT_REFILL_INTERVAL_SECONDS`
+`capture_mode` | `Optional[Union[CaptureMode, str]]` | Capture wire protocol to use. Defaults to `CaptureMode.V0` (legacy `/batch/`). Set `CaptureMode.V1` (or pass the string `"v1"`) to opt into `/i/v1/analytics/events`. When omitted, the `POSTHOG_CAPTURE_MODE` env var is consulted, then `V0`. | `None`
+`capture_compression` | `Optional[Union[CaptureCompression, str]]` | Request-body compression for capture-v1 uploads (ignored in V0, which uses `gzip`). `CaptureCompression.GZIP` or `DEFLATE` (or the strings `"gzip"`/`"deflate"`). When omitted, the `POSTHOG_CAPTURE_COMPRESSION` env var is consulted, then the legacy `gzip` flag, then no compression. | `None`
+
+**Examples:**
+
+```python
+from posthog import Posthog
+
+posthog = Posthog('', host='')
+```
+
+## Capture
+
+### `Client.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to capture. | *required*
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to include with the event. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | A dictionary of group information. |
+`flags` | | A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. |
+`send_feature_flags` | | Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+# Anonymous event
+posthog.capture('some-anon-event')
+```
+```python
+# Context usage
+from posthog import identify_context, new_context
+with new_context():
+ identify_context('distinct_id_of_the_user')
+ posthog.capture('user_signed_up')
+ posthog.capture('user_logged_in')
+ posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')
+```
+```python
+# Set event properties
+posthog.capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+```python
+# Page view event
+posthog.capture('$pageview', distinct_id="distinct_id_of_the_user", properties={'$current_url': 'https://example.com'})
+```
+
+## Identify
+
+### `Client.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+# Set with distinct id
+posthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+### `Client.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile only if they haven't been set before.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set once. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Traces
+
+### `Client.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on
+the way out); or call `end()` yourself for a span that cannot wrap a
+block. Spans started inside the block nest under it automatically.
+Always returns a usable handle, even when tracing is off, so calling
+code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. A forked child starts with no active span; pass the parent span to continue a trace across a fork. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+posthog = Posthog("", traces={"service_name": "checkout-api"})
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `Client.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes
+it active; a span started manually is not. Use it to propagate the
+trace to the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+## Alias
+
+### `Client.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+Create an alias between two distinct IDs.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The previous distinct ID. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`distinct_id` | `Optional[str]` | The new distinct ID to alias to. Falls back to the context distinct ID; the call is dropped with a warning if neither is available. | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+
+**Examples:**
+
+```python
+posthog.alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Capture AI
+
+### `Client.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size
+cap, batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`:
+the event UUID, or None when the event was not admitted (disabled
+client, or dropped by `before_send`). The event is queued on an
+isolated AI lane with its own consumer pool and a higher per-event
+size cap, posting to the dedicated AI ingestion endpoint. The payload
+is sent as given — no redaction or truncation is applied here.
+
+## Capture exception
+
+### `Client.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg], **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception for error tracking.
+
+When OpenTelemetry is installed and a valid span is active, its trace and
+span IDs are added as `$trace_id` and `$span_id` event properties.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. | *required*
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of additional properties. Overriding reserved exception properties is deprecated and will stop working in the next major version. |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. Attaches those exact flag values to the captured `$exception` event. |
+`send_feature_flags` | | Deprecated. Pass `flags` from `evaluate_flags()` instead. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+try:
+ # Some code that might fail
+ pass
+except Exception as e:
+ posthog.capture_exception(e, distinct_id='user_distinct_id', properties=additional_properties)
+```
+
+## Emails
+
+### `Client.emails`
+
+```python
+emails: Emails
+```
+
+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 the `transactional_email:write`
+scope. Sends go to `app_host`, or to the PostHog Cloud app host of
+`host`. `email_request_timeout_seconds` and `email_request_max_retries`
+configure each send. A disabled or shut-down client sends nothing. See
+`posthog.emails` for setup.
+
+**Examples:**
+
+```python
+client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+)
+```
+
+## Flush
+
+### `Client.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events, ended spans and autocaptured metrics, keeping the client reusable.
+
+For a client shared across requests or serverless invocations (including
+the module-level client), call `flush()` before a short-lived invocation
+returns. Use `shutdown()` instead only for final process cleanup or when
+disposing of a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after
+a timeout or span export failure, and failed events may be dropped by the
+consumers. Calls made directly from SDK callbacks such as `on_error` are
+deferred rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently. The span exporter waits up to this many seconds for an in-flight flush, then uses a fresh drain budget once it acquires the lock. If the lock wait times out, the in-flight flush is left to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. Each span request is bounded by the client's `timeout` in seconds, and the last request is not cut short. This is therefore not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the shared client open.
+posthog.flush(timeout_seconds=10)
+```
+
+## Get feature flag
+
+### `Client.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get multivariate feature flag value for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag payload
+
+### `Client.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, *, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload for a feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`match_value` | `Optional[FlagValue]` | The specific flag value to get payload for. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Deprecated. Use get_feature_flag() instead if you need events. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This method returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag result
+
+### `Client.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely
+depending on whether local evaluation is enabled and the flag can be locally evaluated.
+This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.
+When the flag was evaluated remotely and its config version 2 record is a complete experiment
+split (an experiment rule with a rule ID and a variant key), it also captures the
+`$experiment_exposure` event, once per distinct ID, groups, flag, rule and variant.
+
+**Examples:**
+
+```python
+flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')
+if flag_result and flag_result.get_value() == 'variant-key':
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = flag_result.payload
+```
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagResult]` | Optional[FeatureFlagResult]: The feature flag result or None if disabled/not found.
+
+## Get feature flags
+
+### `Client.get_feature_variants`
+
+```python
+get_feature_variants(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Union[bool, str]]
+```
+
+Get feature flag variants for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+### `Client.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> Optional[dict[str, Union[bool, str]]]
+```
+
+Get all feature flags for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags('distinct_id_of_your_user')
+```
+
+## Get feature flags and payloads
+
+### `Client.get_feature_flags_and_payloads`
+
+```python
+get_feature_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get feature flags and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+result = posthog.get_feature_flags_and_payloads('')
+```
+
+### `Client.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get all feature flags and their payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags_and_payloads('distinct_id_of_your_user')
+```
+
+## Evaluate flags
+
+### `Client.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[List[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+Local evaluation is transparent: when the poller resolves a flag, the
+snapshot's `$feature_flag_called` events are tagged `locally_evaluated=True`
+and reason `"Evaluated locally"`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If True, never fall back to remote evaluation — flags that can't be evaluated locally are omitted from the snapshot and listed with a reason in its `unresolved_flags`. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[List[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is True. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagEvaluations` | A `FeatureFlagEvaluations` snapshot.
+
+**Examples:**
+
+```python
+flags = posthog.evaluate_flags(
+ "user_123",
+ person_properties={"plan": "enterprise"},
+)
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+## Group identify
+
+### `Client.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+Identify a group and set its properties.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | The type of group (e.g., 'company', 'team'). Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | The unique identifier for the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | A dictionary of properties to set on the group. | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[Union[str, UUID]]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user performing the action. | `None`
+
+**Examples:**
+
+```python
+posthog.group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Is feature enabled
+
+### `Client.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Check if a feature flag is enabled for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Shutdown
+
+### `Client.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and end the consumer threads. Do not use directly, call `shutdown()` instead.
+
+Failed or undrainable events may be dropped and reported through logging
+or `on_error`; returning does not guarantee server receipt. Lifecycle
+cleanup is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+posthog.join()
+```
+
+### `Client.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the client.
+
+Call this for final process cleanup or when disposing of a client that
+will not be reused. It closes capture lanes, stops background workers and
+the feature flag poller, and tears down integrations. Do not call it at the
+end of each request or serverless invocation when the client is shared;
+call `flush()` before returning instead. A shut-down client cannot be
+reused; create a new client if needed.
+
+Normally this method blocks until queued events have been attempted and
+cleanup finishes. Failed or undrainable events may be dropped and
+reported through logging or `on_error`; returning does not guarantee
+server receipt. Event draining has no timeout. Queued spans get one final
+flush with up to 30 seconds waiting for an in-flight flush, then a fresh
+30-second drain budget; the last HTTP request is not cut short. Any spans
+it cannot send are discarded with a warning, as are spans still open.
+Lifecycle cleanup is attempted once, and cleanup failures
+are logged without retry. When called directly from an SDK callback such as
+`on_error`, shutdown is deferred to avoid blocking the worker that
+invoked the callback. If the callback must coordinate a blocking
+shutdown, have it signal an
+application-owned thread and return before that thread calls shutdown.
+Do not wait inside the callback for another thread or task that calls a
+lifecycle method.
+
+**Examples:**
+
+```python
+posthog.shutdown()
+```
+
+## Flag definition loader
+
+### `Client.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flags for local evaluation.
+
+**Examples:**
+
+```python
+posthog.load_feature_flags()
+```
+
+### `Client.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Return feature flag definitions loaded for local evaluation.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The currently loaded feature flag definitions, or `None` before local evaluation has loaded definitions.
+
+## SDK utils
+
+### `Client.queue`
+
+```python
+queue: Queue
+```
+
+The analytics lane's queue (kept for backwards compatibility).
+
+### `Client.consumers`
+
+```python
+consumers: Optional[List[Consumer]]
+```
+
+Flat list of the lanes' consumers, analytics first (kept for backwards compatibility).
+
+### `Client.new_context`
+
+```python
+new_context(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+with client.new_context():
+ client.identify_context('')
+ client.capture('event_name')
+```
+
+### `Client.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the wrapped function using this client.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+### `Client.tag`
+
+```python
+tag(name: str, value: Any) -> None
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key. | *required*
+`value` | `Any` | The tag value. | *required*
+
+### `Client.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context.
+
+### `Client.identify_context`
+
+```python
+identify_context(distinct_id: str) -> None
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_session`
+
+```python
+set_context_session(session_id: str) -> None
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str) -> None
+```
+
+Set the device ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children. | *required*
+
+### `Client.feature_flags`
+
+```python
+feature_flags
+```
+
+Get the local evaluation feature flags.
+
+### `Client.get_feature_payloads`
+
+```python
+get_feature_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Optional[str]]
+```
+
+Get feature flag payloads for a user, preserving valid serialized JSON.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+payloads = posthog.get_feature_payloads('')
+```
+
+### `Client.get_flags_decision`
+
+```python
+get_flags_decision(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsResponse
+```
+
+Get feature flags decision.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+decision = posthog.get_flags_decision('user123')
+```
+
+### `Client.metrics`
+
+```python
+metrics: PostHogMetrics
+```
+
+The `posthog.metrics` API: a statsd-style pre-aggregating metrics client — alpha.
+
+Samples fold into per-series aggregates in memory and flush as one OTLP
+data point per series per window, so recording from hot paths is cheap.
+Configure via the `metrics` client option; pending metrics flush on
+`shutdown()`.
+
+**Examples:**
+
+```python
+client = Posthog("", metrics={"service_name": "billing-worker"})
+client.metrics.count("invoices.processed", 1, attributes={"plan": "pro"})
+client.metrics.gauge("queue.depth", 42)
+client.metrics.histogram("job.duration", 187, unit="ms")
+```
+
+### `Client.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The remote config feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag, or `None` if the client is disabled, no personal API key is configured, or the request fails. Encrypted payloads are decrypted by PostHog before being returned.
+
+
+Note
+
+Requires `secret_key` for authentication.
+
+
+
+### `Client.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagEvaluationRuntime]` | The flag's evaluation runtime, or `None` when local evaluation has not loaded a definition for this key. A definition that carries no runtime reports `FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+runtime = posthog.get_feature_flag_evaluation_runtime("my-flag")
+if runtime is FeatureFlagEvaluationRuntime.SERVER:
+ ...
+```
+
+### `Client.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime,
+so it is returned for `CLIENT` and for `SERVER`, and asking for
+`ALL` returns every loaded flag. Use this to decide which flags to hand
+to a browser when a backend serves flags to its own frontend.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`evaluation_runtime` | `Union[FeatureFlagEvaluationRuntime, str]` | The runtime to match, as a `FeatureFlagEvaluationRuntime` or its string value. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`list[str]` | The matching flag keys, in the order local evaluation loaded them. Empty when no definitions are loaded.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+client_keys = posthog.get_feature_flag_keys_by_evaluation_runtime(
+ FeatureFlagEvaluationRuntime.CLIENT
+)
+```
+
+### `posthog.integrations.django.PosthogContextMiddleware`
+
+```python
+PosthogContextMiddleware(get_response)
+```
+
+Middleware to automatically track Django requests.
+
+This middleware wraps all calls with a posthog context. It attempts to extract the following from the request:
+- Session ID, (extracted from `X-POSTHOG-SESSION-ID`)
+- Distinct ID, (extracted from `X-POSTHOG-DISTINCT-ID`, falling back to the authenticated request user ID)
+- Authenticated user email as `email`
+- Request URL as `$current_url`
+- Request method as `$request_method`
+- Request path as `$request_path`
+- Forwarded IP address as `$ip`
+- User agent as `$user_agent`
+
+Configure the integration with these Django settings:
+- `POSTHOG_MW_CLIENT`: client used for automatic exception capture, or the global client.
+ This does not redirect events explicitly captured through other clients.
+- `POSTHOG_MW_CAPTURE_EXCEPTIONS`: `False` enables context enrichment only;
+ `True` enables automatic exception capture; `None` inherits the effective client's
+ `enable_exception_autocapture`. When omitted, the legacy default is `True`.
+- `POSTHOG_MW_REQUEST_FILTER`: a callback receiving the request. Returning `False`
+ disables both enrichment and automatic exception capture for that request.
+- `POSTHOG_MW_EXTRA_PROPERTIES`: a callback returning additional event properties.
+- `POSTHOG_MW_CAPTURE_TRACING_HEADERS`: read PostHog identity and session headers
+ as request-scoped analytics context (default: `True`). Explicit capture IDs and
+ event properties take precedence. These values are never authentication or
+ authorization. Authenticated Django user identity remains the fallback when no
+ usable header ID is available or header capture is disabled.
+- `POSTHOG_MW_TRUST_TRACING_HEADERS`: deprecated alias for
+ `POSTHOG_MW_CAPTURE_TRACING_HEADERS`; the capture-named setting takes precedence.
+- `POSTHOG_MW_PROPERTIES_MAP`: an optional callback transforming request properties.
+
+The old `POSTHOG_MW_EXTRA_TAGS` and `POSTHOG_MW_TAG_MAP` settings remain aliases;
+the property-named settings take precedence when both are configured.
+
+Request properties are included on all events captured within the active context,
+including when automatic exception capture is disabled.
+See the context documentation for more information. The extracted distinct ID and session ID,
+if found, are used to associate all events captured in the middleware context with the same distinct ID
+and session as currently active on the frontend. See the documentation for `set_context_session`
+and `identify_context` for more details.
+
+This middleware is hybrid-capable: it supports both WSGI (sync) and ASGI (async) Django applications. The middleware
+detects at initialization whether the next middleware in the chain is async or sync, and adapts its behavior accordingly.
+This ensures compatibility with both pure sync and pure async middleware chains, as well as mixed chains in ASGI mode.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`aextract_properties` | Async version of extract_properties for use in async request handling.
+`aextract_request_user` | Async version of extract_request_user for use in async request handling.
+`aextract_tags` | Compatibility alias for `aextract_properties`.
+`extract_properties` | Extract event properties and identity from a synchronous request.
+`extract_request_user` | Extract user ID and email from request in sync context.
+`extract_tags` | Compatibility alias for `extract_properties`.
+`process_exception` | Process exceptions from views and downstream middleware.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`async_capable` | |
+`capture_exceptions` | `Optional[bool]` |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`extra_tags` | | Compatibility alias for `extra_properties`.
+`get_response` | |
+`properties_map` | |
+`request_filter` | |
+`sync_capable` | |
+`tag_map` | | Compatibility alias for `properties_map`.
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+Initialize the middleware with Django's next handler.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`get_response` | | The next middleware or view handler in Django's middleware chain. May be synchronous or asynchronous. |
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_properties`
+
+```python
+async aextract_properties(request)
+```
+
+Async version of extract_properties for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_request_user`
+
+```python
+async aextract_request_user(request)
+```
+
+Async version of extract_request_user for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_tags`
+
+```python
+async aextract_tags(request)
+```
+
+Compatibility alias for `aextract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.async_capable`
+
+```python
+async_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_exceptions`
+
+```python
+capture_exceptions: Optional[bool] = capture_exceptions if (capture_exceptions is None or isinstance(capture_exceptions, bool)) else True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers, canonical_name='POSTHOG_MW_CAPTURE_TRACING_HEADERS', deprecated_name='POSTHOG_MW_TRUST_TRACING_HEADERS')
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.client`
+
+```python
+client = cast('Optional[Client]', settings.POSTHOG_MW_CLIENT)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_properties`
+
+```python
+extra_properties = cast('Callable[[HttpRequest], Dict[str, Any]]', extra_properties) if callable(extra_properties) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_tags`
+
+```python
+extra_tags
+```
+
+Compatibility alias for `extra_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_properties`
+
+```python
+extract_properties(request)
+```
+
+Extract event properties and identity from a synchronous request.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_request_user`
+
+```python
+extract_request_user(request)
+```
+
+Extract user ID and email from request in sync context.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_tags`
+
+```python
+extract_tags(request)
+```
+
+Compatibility alias for `extract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.get_response`
+
+```python
+get_response = get_response
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.process_exception`
+
+```python
+process_exception(request, exception)
+```
+
+Process exceptions from views and downstream middleware.
+
+Django calls this WHILE still inside the context created by __call__,
+so request tags have already been extracted and set. This method just
+needs to capture the exception directly.
+
+Django converts view exceptions into responses before they propagate through
+the middleware stack, so the context manager in __call__/__acall__ never sees them.
+
+Note: Django's process_exception is always synchronous, even for async views.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.properties_map`
+
+```python
+properties_map = cast('Callable[[Dict[str, Any]], Dict[str, Any]]', properties_map) if callable(properties_map) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.request_filter`
+
+```python
+request_filter = cast('Optional[Callable[[HttpRequest], bool]]', settings.POSTHOG_MW_REQUEST_FILTER)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.sync_capable`
+
+```python
+sync_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.tag_map`
+
+```python
+tag_map
+```
+
+Compatibility alias for `properties_map`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.flask.PosthogFlaskIntegration`
+
+```python
+PosthogFlaskIntegration(app: Optional[Flask] = None, *, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[Callable[[Request], bool]] = None, extra_properties: Optional[Callable[[Request], Mapping[str, Any]]] = None, trust_tracing_headers: Optional[bool] = None, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog request context and exception tracking to a Flask app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `Optional[Flask]` | An optional Flask application. If omitted, call `init_app` later (the Flask application-factory pattern). | `None`
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions that reach Flask's unhandled exception machinery. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[Callable[[Request], bool]]` | Optional callback receiving Flask's request object. A false return value disables both context and exception capture for that request. | `None`
+`extra_properties` | `Optional[Callable[[Request], Mapping[str, Any]]]` | Optional callback returning additional event properties. This is useful for application-specific metadata such as an authenticated user's role. Values should not contain secrets or request bodies. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+The integration intentionally does not capture exceptions handled by an
+application error handler, expected HTTP exceptions, request or response
+bodies, query strings, cookies, authorization headers, or arbitrary headers.
+Call `capture_exception` explicitly from a custom error handler if a
+handled exception should be reported.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`init_app` | Register the integration with a Flask application once.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.init_app`
+
+```python
+init_app(app: Flask) -> None
+```
+
+Register the integration with a Flask application once.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.asgi.PosthogASGIMiddleware`
+
+```python
+PosthogASGIMiddleware(app: _ASGIApp, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[_RequestFilter] = None, extra_properties: Optional[_ExtraProperties] = None, trust_tracing_headers: Optional[bool] = None, *, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog context and automatic exception capture to an ASGI app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `_ASGIApp` | The downstream ASGI application. | *required*
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions escaping the downstream app. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[_RequestFilter]` | Optional sync or async callback receiving the ASGI scope. Returning `False` bypasses all instrumentation for that scope. | `None`
+`extra_properties` | `Optional[_ExtraProperties]` | Optional sync or async callback receiving the ASGI scope and returning additional event properties. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`app` | |
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.app`
+
+```python
+app = app
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.celery.PosthogCeleryIntegration`
+
+```python
+PosthogCeleryIntegration(client: Optional[Client] = None, capture_exceptions: bool = True, capture_task_lifecycle_events: bool = True, propagate_context: bool = True, task_filter: Optional[Callable[[Optional[str], dict[str, Any]], bool]] = None)
+```
+
+Celery integration that captures task lifecycle events and exceptions.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`client` | `Optional[Client]` | Optional `Client` instance. When provided, all events and exceptions are captured through this client rather than the global `posthog` module. Don't skip this if using a custom flag definition cache provider, and pass the custom `Client` instance here initialized with the custom provider so fork safety for that provider is handled correctly. | `None`
+`capture_exceptions` | `bool` | Whether to capture task exceptions via `capture_exception` (default `True`). | `True`
+`capture_task_lifecycle_events` | `bool` | Whether to emit lifecycle events of the task such as "started", "success", "failure" etc. (default `True`). | `True`
+`propagate_context` | `bool` | Whether to propagate PostHog context (distinct ID, session ID, tags) from the producer to the worker via task headers (default `True`). | `True`
+`task_filter` | `Optional[Callable[[Optional[str], dict[str, Any]], bool]]` | Optional callback `(task_name, task_properties) -> bool` expected to return `False` if a given task should not be tracked. | `None`
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`instrument` | Connect Celery signal handlers to capture task events and exceptions. Call this after initializing the PostHog client and this integration.
+`shutdown` | Disconnect all signal handlers registered by `instrument()`, flush all pending events and cleanly shutdown the integration.
+`uninstrument` | Disconnect Celery signal handlers and unregister exit cleanup.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_task_lifecycle_events` | |
+`client` | |
+`propagate_context` | |
+`task_filter` | |
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_task_lifecycle_events`
+
+```python
+capture_task_lifecycle_events = capture_task_lifecycle_events
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.instrument`
+
+```python
+instrument() -> None
+```
+
+Connect Celery signal handlers to capture task events and exceptions.
+Call this after initializing the PostHog client and this integration.
+
+If Celery runs on a single host, reinstrumenting in worker children is
+not strictly necessary because the PostHog client and this integration
+are fork-safe. If Celery workers run across multiple hosts, each worker
+process must initialize PostHog, this integration, and call
+`instrument()`. Celery provides `worker_process_init` signal to help
+with this.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.propagate_context`
+
+```python
+propagate_context = propagate_context
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Disconnect all signal handlers registered by `instrument()`, flush all pending events
+and cleanly shutdown the integration.
+
+`shutdown()` is also registered on `worker_process_shutdown` and `atexit` signals,
+but there is no guarantee those will always be called, so we strongly recommend calling
+it manually when the integration is no longer needed to avoid data loss.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.task_filter`
+
+```python
+task_filter = task_filter
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.uninstrument`
+
+```python
+uninstrument() -> None
+```
+
+Disconnect Celery signal handlers and unregister exit cleanup.
+
+Do not use directly, call `shutdown()` instead.
+
+### `posthog.request.set_socket_options`
+
+```python
+set_socket_options(socket_options: Optional[SocketOptions]) -> None
+```
+
+Configure socket options for all SDK HTTP connections.
+
+Call this during initialization, before making API requests. Pass `None`
+to reset to the default socket behavior.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`socket_options` | `Optional[SocketOptions]` | A list of `(level, option, value)` tuples accepted by urllib3/`socket.setsockopt()`, or `None` to reset defaults. | *required*
+
+
+Example
+
+from posthog import set_socket_options
+set_socket_options([(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)])
+
+
+
+### `posthog.request.enable_keep_alive`
+
+```python
+enable_keep_alive() -> None
+```
+
+Enable TCP keepalive for SDK HTTP connections.
+
+This helps prevent idle pooled connections from being dropped by network
+infrastructure. Call during initialization, before making API requests.
+
+### `posthog.request.disable_connection_reuse`
+
+```python
+disable_connection_reuse() -> None
+```
+
+Disable HTTP connection reuse for SDK requests.
+
+Each request will create a fresh connection. This can avoid issues with
+environments that terminate pooled connections, but adds per-request
+overhead. Call during initialization, before making API requests.
+
+## AsyncClient
+
+Needs the `async` extra, `posthog[async]`.
+
+### `AsyncClient(...)`
+
+```python
+AsyncClient(project_api_key: str, host: Optional[str] = None, debug: bool = False, max_queue_size: int = 10000, send: bool = True, on_error=None, flush_at: int = 100, flush_interval: float = 5.0, gzip: bool = False, max_retries: int = 3, timeout: float = 15, thread: int = 1, disabled: bool = False, disable_geoip: bool = True, is_server: bool = True, historical_migration: bool = False, super_properties: Optional[dict[str, Any]] = None, before_send=None, log_captured_exceptions: bool = False, project_root: Optional[str] = None, capture_exception_code_variables: bool = False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: Optional[list[str]] = None, capture_mode: Optional[Union[CaptureMode, str]] = None, capture_compression: Optional[Union[CaptureCompression, str]] = None, capture_trace_context: bool = False, secret_key: Optional[str] = None, personal_api_key: Optional[str] = None, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries: int = 1, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None) -> None
+```
+
+### `AsyncClient.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Queue an event without blocking for network delivery.
+
+### `AsyncClient.capture_immediate`
+
+```python
+async capture_immediate(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture one event and wait until its delivery attempt completes.
+
+### `AsyncClient.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+### `AsyncClient.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception. This method never raises, including in debug mode.
+
+### `AsyncClient.emails`
+
+```python
+emails: AsyncEmails
+```
+
+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 the `transactional_email:write`
+scope, and `posthog[async]`. Sends go to `app_host`, or to the PostHog
+Cloud app host of `host`. `email_request_timeout_seconds` and
+`email_request_max_retries` configure each send. A disabled or shut-down
+client sends nothing. See `posthog.emails` for setup.
+
+**Examples:**
+
+```python
+await client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ distinct_id="user_123",
+)
+```
+
+### `AsyncClient.flush`
+
+```python
+async flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+### `AsyncClient.evaluate_flags`
+
+```python
+async evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate flags remotely without blocking the event loop.
+
+The returned snapshot has synchronous in-memory accessors. Pass it to
+`capture(flags=...)` to attach the exact values used for branching.
+This client does not evaluate flags locally, so the snapshot's
+`unresolved_flags` is always empty.
+
+### `AsyncClient.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+### `AsyncClient.shutdown`
+
+```python
+async shutdown() -> None
+```
+
+### `AsyncClient.join`
+
+```python
+async join() -> None
+```
+
+### `AsyncClient.get_remote_config_payload`
+
+```python
+async get_remote_config_payload(key: str) -> Optional[Any]
+```
+
+Fetch and decrypt a remote-config payload without blocking the loop.
+
+## Module functions
+
+### `posthog.new_context`
+
+```python
+new_context(fresh: bool = False, capture_exceptions: Optional[bool] = None, client: Optional[Client] = None)
+```
+
+Create a new context scope that will be active for the duration of the with block.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | `bool` | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting. | `None`
+`client` | `Optional[Client]` | Optional Posthog client instance to use for this context (default: None) | `None`
+
+**Examples:**
+
+```python
+from posthog import new_context, tag, capture
+with new_context():
+ tag("request_id", "123")
+ capture("event_name", properties={"property": "value"})
+```
+
+### `posthog.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the function.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+from posthog import scoped, tag, capture
+@scoped()
+def process_payment(payment_id):
+ tag("payment_id", payment_id)
+ capture("payment_started")
+```
+
+### `posthog.set_context_session`
+
+```python
+set_context_session(session_id: str)
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_session
+set_context_session("session_123")
+```
+
+### `posthog.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str)
+```
+
+Set the device ID for the current context, associating all feature flag requests
+in this or child contexts with the given device ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_device_id
+set_context_device_id("device_123")
+```
+
+### `posthog.identify_context`
+
+```python
+identify_context(distinct_id: str)
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import identify_context
+identify_context("user_123")
+```
+
+### `posthog.set_capture_exception_code_variables_context`
+
+```python
+set_capture_exception_code_variables_context(enabled: bool)
+```
+
+Override code-variable capture for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`enabled` | `bool` | Whether exceptions captured in this context should include local variable values from stack frames. | *required*
+
+### `posthog.set_code_variables_mask_patterns_context`
+
+```python
+set_code_variables_mask_patterns_context(mask_patterns: list[str])
+```
+
+Override code-variable mask patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`mask_patterns` | `list[str]` | Variable-name patterns whose values should be replaced with `***` when code variables are captured. | *required*
+
+### `posthog.set_code_variables_ignore_patterns_context`
+
+```python
+set_code_variables_ignore_patterns_context(ignore_patterns: list[str])
+```
+
+Override code-variable ignore patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`ignore_patterns` | `list[str]` | Variable-name patterns that should be omitted entirely when code variables are captured. | *required*
+
+### `posthog.set_code_variables_mask_url_credentials_context`
+
+```python
+set_code_variables_mask_url_credentials_context(enabled: bool)
+```
+
+Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from
+captured code variables for the current context.
+
+### `posthog.set_code_variables_detect_secrets_context`
+
+```python
+set_code_variables_detect_secrets_context(enabled: bool)
+```
+
+Whether to apply entropy-based secret detection as a last-resort redaction of
+high-entropy values (API keys, tokens, strong passwords) in captured code
+variables for the current context.
+
+### `posthog.tag`
+
+```python
+tag(name: str, value: Any)
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key | *required*
+`value` | `Any` | The tag value | *required*
+
+**Examples:**
+
+```python
+from posthog import tag
+tag("user_id", "123")
+```
+
+### `posthog.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context
+
+### `posthog.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture anything a user does within your system.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to specify the event | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional arguments including: distinct_id: Unique identifier for the user properties: Dict of event properties timestamp: When the event occurred. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this event. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. groups: Dict of group types and IDs flags: A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. send_feature_flags: Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. disable_geoip: Whether to disable GeoIP lookup | `{}`
+
+
+Details
+
+Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.
+
+
+
+**Examples:**
+
+```python
+# Context and capture usage
+from posthog import new_context, identify_context, tag, capture
+# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)
+with new_context():
+ # Associate this context with some user, by distinct_id
+ identify_context('some user')
+
+ # Capture an event, associated with the context-level distinct ID ('some user')
+ capture('movie started')
+
+ # Capture an event associated with some other user (overriding the context-level distinct ID)
+ capture('movie joined', distinct_id='some-other-user')
+
+ # Capture an event with some properties
+ capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})
+
+ # Capture an event with some properties
+ capture('purchase', properties={'product_id': '123', 'category': 'romcom'})
+ # Capture an event with some associated group
+ capture('purchase', groups={'company': 'id:5'})
+
+ # Adding a tag to the current context will cause it to appear on all subsequent events
+ tag('some-tag', 'some-value')
+
+ capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict
+```
+```python
+# Set event properties
+from posthog import capture
+capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+
+### `posthog.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size cap,
+batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`: the
+event UUID, or None when the event was not admitted (disabled client, or
+dropped by `before_send`). The event is delivered on an isolated queue
+with its own consumer pool and a higher per-event size cap, posting to
+the dedicated AI ingestion endpoint. The payload is sent as given — no
+redaction or truncation is applied here.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name, normally one of the `$ai_*` event names. | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Same optional arguments as `capture()`. | `{}`
+
+**Examples:**
+
+```python
+from posthog import capture_ai
+
+uuid = capture_ai(
+ "$ai_generation",
+ distinct_id="user_123",
+ properties={"$ai_model": "gpt-5"},
+)
+```
+
+### `posthog.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).
+
+
+
+**Examples:**
+
+```python
+# Set person properties
+from posthog import set
+set(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})
+```
+
+### `posthog.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record, only if they do not yet exist.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set only once. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.
+
+
+
+**Examples:**
+
+```python
+# Set property once
+from posthog import set_once
+set_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})
+
+```
+
+### `posthog.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+Set properties on a group.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | Type of your group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | Unique identifier of the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | Properties to set on the group | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`distinct_id` | `Optional[ID_TYPES]` | Optional distinct ID of the user performing the action | `None`
+
+**Examples:**
+
+```python
+# Group identify
+from posthog import group_identify
+group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+### `posthog.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: str, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The unique ID of the user before | *required*
+`distinct_id` | `str` | The current unique id | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+
+
+Details
+
+To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+
+
+**Examples:**
+
+```python
+# Alias user
+from posthog import alias
+alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+### `posthog.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture exceptions that happen in your code.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` | `None`
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip. Overriding reserved exception properties through `properties` is deprecated and will stop working in the next major version. | `{}`
+
+
+Details
+
+Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the "traceback"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError("Some Error"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.
+
+
+
+**Examples:**
+
+```python
+# Capture exception
+from posthog import capture_exception
+try:
+ risky_operation()
+except Exception as e:
+ capture_exception(e)
+```
+
+### `posthog.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Use feature flags to enable or disable features for users.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.
+
+
+
+**Examples:**
+
+```python
+# Boolean feature flag
+from posthog import feature_enabled, get_feature_flag_payload
+is_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get feature flag variant for users. Used with experiments.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping from group type to group key | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties in format { group_type_name: { group_properties } } | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+`groups` are a mapping from group type to group key. So, if you have a group type of "organization" and a group key of "5", you would pass groups={"organization": "5"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type "organization" and the group key "5", with the properties name, and employee count, you'll send these as: group_properties={"organization": {"name": "PostHog", "employees": 11}}.
+
+
+
+**Examples:**
+
+```python
+# Multivariate feature flag
+from posthog import get_feature_flag, get_feature_flag_payload
+enabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key':
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> Optional[dict[str, FlagValue]]
+```
+
+Get all flags for a given user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate (evaluates all if None) | `None`
+
+
+Details
+
+Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.
+
+
+
+**Examples:**
+
+```python
+# All flags for user
+from posthog import get_all_flags
+get_all_flags('distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload.
+
+This method evaluates a feature flag and returns a FeatureFlagResult object containing:
+- enabled: Whether the flag is enabled
+- variant: The variant value if the flag has variants
+- payload: The payload associated with the flag (automatically deserialized from JSON)
+- key: The flag key
+- reason: Why the flag was enabled/disabled
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+Example:
+```python
+result = posthog.get_feature_flag_result('beta-feature', 'distinct_id')
+if result and result.enabled:
+ # Use the variant and payload
+ print(f"Variant: {result.variant}")
+ print(f"Payload: {result.payload}")
+```
+
+### `posthog.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload associated with a feature flag value.
+
+Deprecated for new code. Prefer `evaluate_flags()` and
+`flags.get_flag_payload(key)` so flag evaluation happens once per request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`match_value` | `Optional[FlagValue]` | Optional flag value to use when selecting a payload. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This function returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+### `posthog.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The key of the feature flag | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag. If payload is encrypted, the return value will be decrypted
+
+
+Note
+
+Requires secret_key to be set for authentication
+
+
+
+### `posthog.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> FlagsAndPayloads
+```
+
+Get all feature flag values and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate. Evaluates all flags when omitted. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FlagsAndPayloads` | A dict with `featureFlags` and `featureFlagPayloads` entries.
+
+### `posthog.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture()` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If `True`, never fall back to remote evaluation and omit flags that cannot be evaluated locally. The snapshot's `unresolved_flags` lists them with a reason. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[list[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is `True`. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Examples:**
+
+```python
+from posthog import evaluate_flags, capture
+flags = evaluate_flags("user_123", person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+### `posthog.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Returns loaded feature flags.
+
+
+Details
+
+Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.
+
+
+
+**Examples:**
+
+```python
+from posthog import feature_flag_definitions
+definitions = feature_flag_definitions()
+```
+
+### `posthog.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+
+Details
+
+Reads the `evaluation_runtime` each flag definition carries, so no extra
+request is made. Returns `None` when local evaluation has not loaded a
+definition for this key. A definition that carries no runtime reports
+`FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_evaluation_runtime
+runtime = get_feature_flag_evaluation_runtime("my-flag")
+```
+
+### `posthog.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+
+Details
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime, so
+it is returned for `CLIENT` and for `SERVER`. Use this to decide which
+flags to hand to a browser when a backend serves flags to its own
+frontend.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_keys_by_evaluation_runtime
+client_keys = get_feature_flag_keys_by_evaluation_runtime(FeatureFlagEvaluationRuntime.CLIENT)
+```
+
+### `posthog.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flag definitions from PostHog.
+
+**Examples:**
+
+```python
+from posthog import load_feature_flags
+load_feature_flags()
+```
+
+### `posthog.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events and ended spans, keeping the global client reusable.
+
+Call `flush()` before a short-lived request or serverless invocation returns
+when using the shared module-level client. Use `shutdown()` only for final
+process cleanup or a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after a
+timeout or span export failure, and failed events may be dropped by consumers.
+Calls made directly from SDK callbacks such as `on_error` are deferred
+rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently, waiting up to this many seconds for an in-flight flush before starting a fresh drain budget. A lock wait timeout leaves the in-flight flush to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. The last span request is not cut short and is bounded by the client's `timeout` in seconds, so this is not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+import posthog
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the global client open.
+posthog.flush(timeout_seconds=10)
+```
+
+### `posthog.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and stop the client's background workers. Use `shutdown()` directly in most cases.
+
+Failed or undrainable events may be dropped and reported through logging or
+`on_error`; returning does not guarantee server receipt. Lifecycle cleanup
+is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+from posthog import join
+join()
+```
+
+### `posthog.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime.datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on the
+way out); or call `end()` yourself for a span that cannot wrap a block.
+Spans started inside the block nest under it automatically. Always returns
+a usable handle, even when tracing is off, so calling code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+import posthog
+posthog.traces = {"service_name": "checkout-api"}
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `posthog.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes it
+active; a span started manually is not. Use it to propagate the trace to
+the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+### `posthog.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the global client.
+
+Call this for final process cleanup, not at the end of each request or
+serverless invocation that shares the module-level client. Use `flush()`
+before returning from those invocations instead. Shutdown closes capture
+lanes, stops background workers and the feature flag poller, and tears down
+integrations. The global client is not recreated automatically after shutdown.
+
+This normally blocks until queued events have been attempted and cleanup
+finishes. Failed or undrainable events may be dropped and reported through
+logging or `on_error`; returning does not guarantee server receipt. Event
+draining has no timeout. Queued spans get a final flush with up to 30 seconds
+waiting for an in-flight flush, then a fresh 30-second drain budget; the last
+HTTP request is not cut short. Unsent queued spans and still-open spans are
+discarded with a warning.
+Lifecycle cleanup is attempted once, and cleanup failures are logged without
+retry. Calls made directly from SDK callbacks such as `on_error` are deferred
+to avoid deadlocking the worker. If blocking completion is required, signal an application-owned
+thread, return from the callback, and call `shutdown()` from that thread.
+Do not wait inside a callback for another thread or task calling a lifecycle
+method.
+
+**Examples:**
+
+```python
+from posthog import shutdown
+shutdown()
+```
+
+### `posthog.setup`
+
+```python
+setup() -> Client
+```
+
+Create or return the global PostHog client configured by module settings.
+
+Most applications should either instantiate `Posthog` directly or set
+`posthog.api_key`/other module settings before calling top-level helpers.
+`setup()` is called automatically by global APIs such as `capture()`.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Client` | The global `Client` instance. If both `api_key` and `project_api_key` are missing or blank, the client is disabled and module-level calls become no-ops.
+
+## Types
+
+### `OptionalCaptureArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the capture method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the person associated with this event. If not set, the context distinct_id is used, if available, otherwise a UUID is generated, and the event is marked as personless. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to track with the event |
+`timestamp` | | When the event occurred (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this specific event. If not provided, one is generated. The event UUID is returned, so you can correlate it with actions in your app (like showing users an error ID if you capture an exception). If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | Group identifiers to associate with this event (format: {group_type: group_key}) |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. The exact flag values from the snapshot are attached to the event with no additional network call — prefer this over `send_feature_flags`. |
+`send_feature_flags` | | Deprecated — prefer `flags` with a `FeatureFlagEvaluations` snapshot. Whether to include currently active feature flags in the event properties. Can be a boolean or a SendFeatureFlagsOptions object. Defaults to False. Fires a hidden `/flags` request on capture and may return different values than the ones the code branched on. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this event. Defaults to False. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`flags` | `NotRequired[Optional[FeatureFlagEvaluations]]` |
+`groups` | `NotRequired[Optional[Dict[str, str]]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`send_feature_flags` | `NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalCaptureArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.flags`
+
+```python
+flags: NotRequired[Optional[FeatureFlagEvaluations]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.groups`
+
+```python
+groups: NotRequired[Optional[Dict[str, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.send_feature_flags`
+
+```python
+send_feature_flags: NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `FeatureFlagEvaluations`
+
+```python
+FeatureFlagEvaluations(host: _FeatureFlagEvaluationsHost, distinct_id: str, flags: Dict[str, _EvaluatedFlagRecord], groups: Optional[Mapping[str, Union[str, int]]] = None, disable_geoip: Optional[bool] = None, request_id: Optional[str] = None, evaluated_at: Optional[int] = None, errors_while_computing: bool = False, quota_limited: bool = False, minimal_flag_called_events: bool = False, accessed: Optional[Set[str]] = None, unresolved_flags: Optional[Mapping[str, UnresolvedFlagReason]] = None) -> None
+```
+
+A point-in-time snapshot of feature flag evaluations for a single distinct_id.
+
+Returned by `Client.evaluate_flags` — branch on `is_enabled` /
+`get_flag` and pass the same object to `Client.capture` via the
+`flags` option so the captured event carries the exact flag values the code
+branched on.
+
+```python
+flags = posthog.evaluate_flags(distinct_id, person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id=distinct_id, flags=flags)
+```
+
+To narrow the set of flags that get attached to a captured event, use the in-memory
+helpers `only` and `only_accessed`. To narrow the set of flags requested
+from the server in the first place, pass `flag_keys` to `Client.evaluate_flags`.
+
+Reading a flag sends `$feature_flag_called`, deduplicated as `is_enabled`
+describes. When the flag was evaluated remotely and its config version 2 record is
+a complete experiment split (an experiment rule with a rule ID and a variant key),
+the read also sends `$experiment_exposure`. The SDK sends one exposure per
+distinct ID, groups, flag, rule and variant. `send_feature_flag_events=False`
+suppresses both events.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`get_flag` | Return the flag value. Fires `$feature_flag_called` on first access.
+`get_flag_payload` | Return the payload associated with a flag.
+`is_enabled` | Return whether the flag is enabled. Fires `$feature_flag_called` on the first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+`only` | Return a filtered copy containing only flags with the given keys. Keys that are not present in the evaluation are dropped and logged as a warning.
+`only_accessed` | Return a filtered copy containing only flags accessed via `is_enabled` or `get_flag` before this call.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`keys` | `List[str]` | Return the flag keys that are part of this evaluation.
+`unresolved_flags` | `Mapping[str, UnresolvedFlagReason]` | Return a read-only mapping of flag key to the reason local evaluation left it without a value.
+
+Internal — instances are created by the SDK via `Client.evaluate_flags()`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag`
+
+```python
+get_flag(key: str, *, send_feature_flag_events: bool = True) -> Optional[FlagValue]
+```
+
+Return the flag value. Fires `$feature_flag_called` on first access.
+
+Returns the variant string for multivariate flags, `True` for enabled flags
+without a variant, `False` for disabled flags, and `None` for flags that
+were not returned by the evaluation.
+
+Pass `send_feature_flag_events=False` to skip the event for this read, as
+with `is_enabled`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag_payload`
+
+```python
+get_flag_payload(key: str) -> Optional[Any]
+```
+
+Return the payload associated with a flag.
+
+Does not count as an access for `only_accessed` and does not fire any event.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.is_enabled`
+
+```python
+is_enabled(key: str, default_value: bool = False, *, send_feature_flag_events: bool = True) -> bool
+```
+
+Return whether the flag is enabled. Fires `$feature_flag_called` on the
+first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`default_value` | `bool` | Returned when the flag has no value in this evaluation — the key was not part of the evaluated set, or the evaluation itself came back empty (failed `/flags` request, quota limit, or no resolvable `distinct_id`). Defaults to `False`. | `False`
+`send_feature_flag_events` | `bool` | Whether this read sends `$feature_flag_called`. When `False`, no event is sent and the dedupe cache is left alone, but the key still counts as accessed for `only_accessed`. | `True`
+
+A flag that has a value always wins over `default_value`, including a
+disabled flag, which returns `False` even when `default_value=True`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.keys`
+
+```python
+keys: List[str]
+```
+
+Return the flag keys that are part of this evaluation.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only`
+
+```python
+only(keys: List[str]) -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags with the given keys. Keys that
+are not present in the evaluation are dropped and logged as a warning.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only_accessed`
+
+```python
+only_accessed() -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags accessed via `is_enabled`
+or `get_flag` before this call.
+
+Order-dependent: if nothing has been accessed yet, the returned snapshot is
+empty. The method honors its name — pre-access if you want a populated result.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.unresolved_flags`
+
+```python
+unresolved_flags: Mapping[str, UnresolvedFlagReason]
+```
+
+Return a read-only mapping of flag key to the reason local evaluation
+left it without a value.
+
+A flag is listed when it has a loaded local definition, was in the requested
+scope, was inconclusive locally, and no remote value filled the gap. Listed
+flags are not part of `keys`, and reading one reports the
+`local_evaluation_inconclusive` error instead of `flag_missing`. Reading
+this mapping does not count as an access and does not fire any event.
+Snapshots returned by `only` and `only_accessed`, and by
+`AsyncClient.evaluate_flags()`, which evaluates only remotely, carry no
+entries.
+
+### `FeatureFlagResult`
+
+```python
+FeatureFlagResult(key: str, enabled: bool, variant: Optional[str], payload: Optional[Any], reason: Optional[str]) -> None
+```
+
+The result of calling a feature flag which includes the flag result, variant, and payload.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | The unique identifier of the feature flag.
+`enabled` | `bool` | Whether the feature flag is enabled for the current context.
+`variant` | `Optional[str]` | The variant value if the flag is enabled and has variants, None otherwise.
+`payload` | `Optional[Any]` | Additional data associated with the feature flag, if any.
+`reason` | `Optional[str]` | A description of why the flag was enabled or disabled, if available.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_flag_details` | Create a FeatureFlagResult from a FeatureFlag object.
+`from_value_and_payload` | Creates a FeatureFlagResult from a flag value and payload.
+`get_value` | Returns the value of the flag. This is the variant if it exists, otherwise the enabled value. This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+#### `posthog.types.FeatureFlagResult.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlagResult.from_flag_details`
+
+```python
+from_flag_details(details: Union[FeatureFlag, None], override_match_value: Optional[FlagValue] = None) -> FeatureFlagResult | None
+```
+
+Create a FeatureFlagResult from a FeatureFlag object.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`details` | `Union[FeatureFlag, None]` | The FeatureFlag object to convert. | *required*
+`override_match_value` | `Optional[FlagValue]` | If provided, this value will be used to populate the enabled and variant fields instead of the values from the FeatureFlag. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagResult \| None` | FeatureFlagResult | None: A new FeatureFlagResult instance, or None if details is None.
+
+#### `posthog.types.FeatureFlagResult.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: Union[FlagValue, None], payload: Any) -> Union[FeatureFlagResult, None]
+```
+
+Creates a FeatureFlagResult from a flag value and payload.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The unique identifier of the feature flag. | *required*
+`value` | `Union[FlagValue, None]` | The value of the flag (string variant or boolean). | *required*
+`payload` | `Any` | Additional data associated with the feature flag. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Union[FeatureFlagResult, None]` | Union[FeatureFlagResult, None]: A new FeatureFlagResult instance, or None if value is None.
+
+#### `posthog.types.FeatureFlagResult.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Returns the value of the flag. This is the variant if it exists, otherwise the enabled value.
+This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+**Returns:**
+
+Name | Type | Description
+---- | ---- | -----------
+`FlagValue` | `FlagValue` | Either a string variant or boolean value representing the flag's state.
+
+#### `posthog.types.FeatureFlagResult.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlagResult.payload`
+
+```python
+payload: Optional[Any]
+```
+
+#### `posthog.types.FeatureFlagResult.reason`
+
+```python
+reason: Optional[str]
+```
+
+#### `posthog.types.FeatureFlagResult.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FeatureFlag`
+
+```python
+FeatureFlag(key: str, enabled: bool, variant: Optional[str], reason: Optional[FlagReason], metadata: Union[FlagMetadata, LegacyFlagMetadata]) -> None
+```
+
+Detailed feature flag evaluation returned by the flags API.
+
+`enabled`, `variant` and `metadata.payload` are the value rendered the way
+responses before `/flags?v=4` carried it, which the legacy getters return.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | Feature flag key.
+`enabled` | `bool` | Whether the flag is enabled for the evaluated user or group.
+`variant` | `Optional[str]` | Variant key for multivariate flags, otherwise `None`.
+`reason` | `Optional[FlagReason]` | Optional reason metadata explaining the result.
+`metadata` | `Union[FlagMetadata, LegacyFlagMetadata]` | Payload and other metadata returned by the API.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_json` | Parse one flag record of a `/flags` response.
+`from_value_and_payload` | Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+`get_value` | Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlag.from_json`
+
+```python
+from_json(resp: Any) -> FeatureFlag
+```
+
+Parse one flag record of a `/flags` response.
+
+A record with a `value` member is a `/flags?v=4` record. A record
+without one comes from an older server: its value is `variant`, or
+`enabled` when there is no variant, and its config version is `1`.
+
+#### `posthog.types.FeatureFlag.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: FlagValue, payload: Any) -> FeatureFlag
+```
+
+Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+
+#### `posthog.types.FeatureFlag.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlag.metadata`
+
+```python
+metadata: Union[FlagMetadata, LegacyFlagMetadata]
+```
+
+#### `posthog.types.FeatureFlag.reason`
+
+```python
+reason: Optional[FlagReason]
+```
+
+#### `posthog.types.FeatureFlag.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FlagsAndPayloads`
+
+Bases: `TypedDict`
+
+Feature flag values and payloads keyed by feature flag key.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`featureFlags` | `Optional[dict[str, FlagValue]]` | Each flag's value, keyed by flag key.
+`featureFlagPayloads` | `Optional[dict[str, Any]]` | Each flag's payload, keyed by flag key.
+
+#### `posthog.types.FlagsAndPayloads.featureFlagPayloads`
+
+```python
+featureFlagPayloads: Optional[dict[str, Any]]
+```
+
+#### `posthog.types.FlagsAndPayloads.featureFlags`
+
+```python
+featureFlags: Optional[dict[str, FlagValue]]
+```
+
+### `UnresolvedFlagReason`
+
+Bases: `str`, `Enum`
+
+Why local evaluation left a flag without a value.
+
+Reported by `FeatureFlagEvaluations.unresolved_flags`. Inheriting from
+`str` keeps the members directly comparable to their string values. When more
+than 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, 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.
+
+
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`EXPERIENCE_CONTINUITY` | |
+`MISSING_CONTEXT` | |
+`UNRESOLVED_DEPENDENCY` | |
+`UNSUPPORTED_DEFINITION` | |
+
+#### `posthog.types.UnresolvedFlagReason.EXPERIENCE_CONTINUITY`
+
+```python
+EXPERIENCE_CONTINUITY = 'experience_continuity'
+```
+
+#### `posthog.types.UnresolvedFlagReason.MISSING_CONTEXT`
+
+```python
+MISSING_CONTEXT = 'missing_context'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNRESOLVED_DEPENDENCY`
+
+```python
+UNRESOLVED_DEPENDENCY = 'unresolved_dependency'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNSUPPORTED_DEFINITION`
+
+```python
+UNSUPPORTED_DEFINITION = 'unsupported_definition'
+```
+
+### `InconclusiveMatchError`
+
+```python
+InconclusiveMatchError(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when local evaluation can't determine a flag's value. `reason` says
+why, as reported by `FeatureFlagEvaluations.unresolved_flags`.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why local evaluation couldn't resolve the flag.
+
+#### `posthog.feature_flags.InconclusiveMatchError.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `RequiresServerEvaluation`
+
+```python
+RequiresServerEvaluation(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when feature flag evaluation requires server-side data that is not
+available locally (e.g., static cohorts).
+
+This error should propagate immediately to trigger API fallback, unlike
+InconclusiveMatchError which allows trying other conditions.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why the flag needs server-side evaluation.
+
+#### `posthog.feature_flags.RequiresServerEvaluation.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `Span`
+
+A handle to a span.
+
+Every method is safe to call on any handle, including after `end()` and
+on the inert handles returned when tracing is off, so calling code never
+branches on whether tracing is running. Entering a handle (`with span:`)
+makes it the active span for the block and ends it on exit, recording an
+`Exception` raised inside it. A `BaseException` that is not an
+`Exception` (`GeneratorExit`, `CancelledError`, `KeyboardInterrupt`)
+still ends the span but is not recorded as a failure.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`add_event` | Add a timestamped event to the span. Ignored after `end()`.
+`end` | End the span and queue it for export. Idempotent.
+`record_exception` | Record an exception as an `exception` event and mark the span `error`.
+`set_attribute` | Set one attribute on the span; last write wins. Ignored after `end()`.
+`set_attributes` | Set several attributes at once; last write wins per key. Ignored after `end()`.
+`set_status` | Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+`traceparent` | The W3C `traceparent` header value to propagate, or `None`.
+`tracestate` | The W3C `tracestate` header value to propagate, or `None`.
+`update_name` | Rename the span, for a name only known after it started. Ignored after `end()`.
+
+#### `posthog.tracing.span.Span.add_event`
+
+```python
+add_event(name: str, attributes: Optional[Mapping[str, Any]] = None, timestamp: Union[datetime, float, None] = None) -> Span
+```
+
+Add a timestamped event to the span. Ignored after `end()`.
+
+`timestamp` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`. Returns the span, so calls
+chain.
+
+**Examples:**
+
+```python
+span.add_event("cache.miss", {"key": "user:42"})
+```
+
+#### `posthog.tracing.span.Span.end`
+
+```python
+end(end_time: Union[datetime, float, None] = None) -> None
+```
+
+End the span and queue it for export. Idempotent.
+
+`end_time` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`, and is never earlier than
+the start. Later calls, and later mutations, no-op. `with span:`
+ends the span on exit, so call this only for spans started manually.
+
+**Examples:**
+
+```python
+span = posthog.start_span("job")
+try:
+ run_job()
+finally:
+ span.end()
+```
+
+#### `posthog.tracing.span.Span.record_exception`
+
+```python
+record_exception(exception: BaseException) -> Span
+```
+
+Record an exception as an `exception` event and mark the span `error`.
+
+Ignored after `end()`. The event carries `exception.type`,
+`exception.message` and, for a raised exception,
+`exception.stacktrace` (its last `max_attribute_value_length`
+characters, so a chained traceback keeps the outermost exception and
+may lose its cause). Returns the span, so calls chain. Inside
+`with span:` a raised `Exception` is recorded automatically, so
+this is for exceptions that are caught and handled.
+
+**Examples:**
+
+```python
+try:
+ charge(card)
+except PaymentError as e:
+ span.record_exception(e)
+```
+
+#### `posthog.tracing.span.Span.set_attribute`
+
+```python
+set_attribute(key: str, value: Any) -> Span
+```
+
+Set one attribute on the span; last write wins. Ignored after `end()`.
+
+Returns the span, so calls chain. Prefer primitive values: strings,
+booleans, integers and floats keep their type. Lists and mappings are
+sent as OTLP arrays and maps, but PostHog stores them as serialized
+strings. `None` removes the key; anything else is stringified.
+
+**Examples:**
+
+```python
+span.set_attribute("http.status_code", 200).set_attribute("cache.hit", True)
+```
+
+#### `posthog.tracing.span.Span.set_attributes`
+
+```python
+set_attributes(attributes: Mapping[str, Any]) -> Span
+```
+
+Set several attributes at once; last write wins per key. Ignored after `end()`.
+
+Returns the span, so calls chain. Same encoding as `set_attribute()`.
+
+**Examples:**
+
+```python
+span.set_attributes({"db.system": "postgresql", "db.rows": 12})
+```
+
+#### `posthog.tracing.span.Span.set_status`
+
+```python
+set_status(code: str, message: Optional[str] = None) -> Span
+```
+
+Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+
+Unset by default. Any other `code` is ignored. `ok` is final for the
+scoped form: an `Exception` raised inside `with span:` does not override
+it. Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span.set_status("error", "upstream timed out")
+```
+
+#### `posthog.tracing.span.Span.traceparent`
+
+```python
+traceparent() -> Optional[str]
+```
+
+The W3C `traceparent` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.tracestate`
+
+```python
+tracestate() -> Optional[str]
+```
+
+The W3C `tracestate` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.update_name`
+
+```python
+update_name(name: str) -> Span
+```
+
+Rename the span, for a name only known after it started. Ignored after `end()`.
+
+Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span = posthog.start_span("http.request")
+span.update_name(f"{request.method} {route.pattern}")
+```
+
+### `Emails`
+
+```python
+Emails(secret_key: Optional[str], *, host: Optional[str] = None, timeout: float = 15, max_retries: int = 2, disabled: bool = False, session: Optional[requests.Session] = None, migrated_from: Optional[str] = None) -> None
+```
+
+Bases: `_EmailsBase`
+
+Sends transactional email from PostHog email templates or from content in your code.
+
+`host` is your PostHog app host. PostHog Cloud ingestion hosts map to the
+app host, so `us.i.posthog.com` sends to `us.posthog.com`. Any other
+host is used as given.
+
+Each send retries network errors, rate limits and an unavailable service up
+to `max_retries` times, with the same idempotency key. Set
+`max_retries=0` when a job runner already retries the send. `timeout`
+is in seconds, per request. Pass `session` to send through your own
+`requests.Session`, for example a test double. `migrated_from`, such
+as `"resend"`, tells PostHog which provider your sends came from.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`close` | Close the HTTP connections this client opened. A `session` you passed in stays open.
+`get` | Read what happened to an email that `send` queued.
+`send` | Queue one email, from a template in PostHog or from content in your code.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disabled` | |
+`host` | |
+`max_retries` | |
+`migrated_from` | |
+`secret_key` | |
+`timeout` | |
+
+#### `posthog.emails.Emails.close`
+
+```python
+close() -> None
+```
+
+Close the HTTP connections this client opened. A `session` you passed in stays open.
+
+#### `posthog.emails.Emails.disabled`
+
+```python
+disabled = disabled
+```
+
+#### `posthog.emails.Emails.get`
+
+```python
+get(message_id: Union[str, UUID]) -> EmailStatus
+```
+
+Read what happened to an email that `send` queued.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`message_id` | `Union[str, UUID]` | The `id` of the `SendEmailResult` that `send` returned. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`EmailStatus` | The email's latest status, for 30 days after the send.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not answer with a status. `code` is `not_found` for an unknown ID, an email older than 30 days, or for a few seconds after the send.
+`ValueError` | `message_id` is not a message ID.
+
+**Examples:**
+
+```python
+result = emails.send(to="user@example.com", template_id="...")
+status = emails.get(result.id)
+if status.status == "bounced":
+ print(status.reason)
+```
+
+#### `posthog.emails.Emails.host`
+
+```python
+host = determine_app_host(host)
+```
+
+#### `posthog.emails.Emails.max_retries`
+
+```python
+max_retries = max_retries
+```
+
+#### `posthog.emails.Emails.migrated_from`
+
+```python
+migrated_from = migrated_from
+```
+
+#### `posthog.emails.Emails.secret_key`
+
+```python
+secret_key = secret_key.strip() if isinstance(secret_key, str) else None
+```
+
+#### `posthog.emails.Emails.send`
+
+```python
+send(**kwargs: Any) -> SendEmailResult
+```
+
+Queue one email, from a template in PostHog or from content in your code.
+
+Pass exactly one form. The template form names a template made in
+PostHog with `template_id`. The code form names the email with
+`template_key` and passes `subject` and `html`, `text` or both:
+see `CodeEmailArgs`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_id` | | The UUID of a template made transactional in PostHog. |
+`template_data` | | Values for the template's `{{ variables.* }}` placeholders. Values are encoded the way capture encodes properties. |
+`distinct_id` | | The recipient's distinct ID in your product. The email's events go to this person. Without it, they go to a person whose distinct ID is the email address. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. A send with a key that PostHog has already accepted queues nothing and returns the first send's result. Without it, the client makes a key that covers its own retries. Pass a key derived from what the email is for, such as `welcome:user_123`, to cover retries outside this call, too. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`SendEmailResult` | The queued email. A result means PostHog queued the email, not that it was delivered.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not queue the email, or the client could not tell whether it did.
+`(TypeError, ValueError)` | An argument has the wrong type or format.
+
+**Examples:**
+
+```python
+emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+ idempotency_key="welcome:user_123",
+)
+emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ distinct_id="user_123",
+)
+```
+
+#### `posthog.emails.Emails.timeout`
+
+```python
+timeout = timeout
+```
+
+### `EmailError`
+
+```python
+EmailError(*, name: str, code: str, message: str, status_code: Optional[int] = None, why: Optional[str] = None, fix: Optional[str] = None, docs_url: Optional[str] = None, field: Optional[str] = None, retry_after: Optional[float] = None) -> None
+```
+
+Bases: `Exception`
+
+PostHog did not queue the email, or the client could not tell whether it did.
+
+Branch on `code`, PostHog's stable error code, or on `name`, a coarse
+category of the failure. The message never contains the secret key or the
+request body.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`name` | | A coarse category of the failure.
+`code` | | PostHog's stable error code.
+`message` | | What went wrong. It never contains the secret key or the request body.
+`status_code` | | The HTTP status of the response, or `None` when none arrived.
+`why` | | PostHog's explanation of the failure, when it gave one.
+`fix` | | What to change to fix it, when PostHog said.
+`docs_url` | | A docs page about the error, when PostHog gave one.
+`field` | | The request field the error is about, when there is one.
+`retry_after` | | Seconds to wait before retrying, when PostHog said.
+
+#### `posthog.emails.EmailError.code`
+
+```python
+code = code
+```
+
+#### `posthog.emails.EmailError.docs_url`
+
+```python
+docs_url = docs_url
+```
+
+#### `posthog.emails.EmailError.field`
+
+```python
+field = field
+```
+
+#### `posthog.emails.EmailError.fix`
+
+```python
+fix = fix
+```
+
+#### `posthog.emails.EmailError.message`
+
+```python
+message = message
+```
+
+#### `posthog.emails.EmailError.name`
+
+```python
+name = name
+```
+
+#### `posthog.emails.EmailError.retry_after`
+
+```python
+retry_after = retry_after
+```
+
+#### `posthog.emails.EmailError.status_code`
+
+```python
+status_code = status_code
+```
+
+#### `posthog.emails.EmailError.why`
+
+```python
+why = why
+```
+
+### `SendEmailResult`
+
+```python
+SendEmailResult(id: str, replayed: bool = False, warnings: tuple[EmailWarning, ...] = ()) -> None
+```
+
+The queued email. `id` is its message ID.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`id` | `str` | The email's message ID.
+`replayed` | `bool` | `True` when the response says PostHog replayed an earlier send for the same `idempotency_key` instead of sending again.
+`warnings` | `tuple[EmailWarning, ...]` | Warnings PostHog returned about the request.
+
+#### `posthog.emails.SendEmailResult.id`
+
+```python
+id: str
+```
+
+#### `posthog.emails.SendEmailResult.replayed`
+
+```python
+replayed: bool = False
+```
+
+#### `posthog.emails.SendEmailResult.warnings`
+
+```python
+warnings: tuple[EmailWarning, ...] = ()
+```
+
+### `OptionalSetArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the set method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the user to set properties on. If not set, the context distinct_id is used, if available, otherwise this function does nothing. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to set on the person |
+`timestamp` | | When the properties were set (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this operation. If not provided, one is generated. This UUID is returned, so you can correlate it with actions in your app. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this operation. Defaults to False. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalSetArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalSetArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalSetArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalSetArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalSetArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `CodeEmailArgs`
+
+Bases: `_RecipientArgs`
+
+A send of email content that your code rendered for one recipient, named by a key.
+
+The content goes out as is. To send a React email, render it to HTML in
+your app first.
+
+An optional field passed as `None` counts as left out.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_key` | | Names the email, so its metrics, logs and status group under it. Letters, digits, `-` and `_`, at most 400. |
+`subject` | | The subject line. |
+`html` | | The HTML body. Give `html`, `text` or both. |
+`text` | | The plain-text body. Without it, PostHog derives it from `html`. HTML with no text in it, such as a single image, goes out without a plain-text part. |
+`from_` | | A verified sender, such as `"Acme "`. |
+`reply_to` | | One address or a list of addresses. An empty list sends no reply-to. |
+`capture_engagement` | | Capture the email's opens and clicks as events of the recipient. Defaults to `True`. A project whose admin turned engagement capture off captures nothing, whatever the send asks. A template made in PostHog follows the project's setting, so the template form doesn't take it. |
+`distinct_id` | | The recipient's distinct ID in your product. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. Template sends and code sends share one set of keys: a key already used for another email, or for a `template_id` send, raises `idempotency_key_reused`. A retry with the same key returns the first send's result, also when its workflow was paused since. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_engagement` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[str]]` |
+`from_` | `NotRequired[Optional[str]]` |
+`html` | `NotRequired[Optional[str]]` |
+`idempotency_key` | `NotRequired[Optional[str]]` |
+`max_retries` | `NotRequired[Optional[int]]` |
+`reply_to` | `NotRequired[Optional[Union[str, Sequence[str]]]]` |
+`subject` | `str` |
+`template_key` | `str` |
+`text` | `NotRequired[Optional[str]]` |
+`to` | `str` |
+
+#### `posthog.emails.CodeEmailArgs.capture_engagement`
+
+```python
+capture_engagement: NotRequired[Optional[bool]]
+```
+
+#### `posthog.emails.CodeEmailArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.from_`
+
+```python
+from_: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.html`
+
+```python
+html: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.idempotency_key`
+
+```python
+idempotency_key: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.max_retries`
+
+```python
+max_retries: NotRequired[Optional[int]]
+```
+
+#### `posthog.emails.CodeEmailArgs.reply_to`
+
+```python
+reply_to: NotRequired[Optional[Union[str, Sequence[str]]]]
+```
+
+#### `posthog.emails.CodeEmailArgs.subject`
+
+```python
+subject: str
+```
+
+#### `posthog.emails.CodeEmailArgs.template_key`
+
+```python
+template_key: str
+```
+
+#### `posthog.emails.CodeEmailArgs.text`
+
+```python
+text: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.to`
+
+```python
+to: str
+```
diff --git a/references/posthog-python-8.md b/references/posthog-python-8.md
new file mode 100644
index 000000000..8f9198f3a
--- /dev/null
+++ b/references/posthog-python-8.md
@@ -0,0 +1,4350 @@
+---
+title: "PostHog Python SDK 8.x (experimental)"
+sidebar: Docs
+showTitle: true
+contentMaxWidthClass: max-w-full
+platformLogo: python
+tableOfContents:
+ - value: "Getting started"
+ url: getting-started
+ depth: 0
+ - value: "Setup"
+ url: setup
+ depth: 0
+ - value: "Capture"
+ url: capture
+ depth: 0
+ - value: "Identify"
+ url: identify
+ depth: 0
+ - value: "Traces"
+ url: traces
+ depth: 0
+ - value: "Alias"
+ url: alias
+ depth: 0
+ - value: "Capture AI"
+ url: capture-ai
+ depth: 0
+ - value: "Capture exception"
+ url: capture-exception
+ depth: 0
+ - value: "Emails"
+ url: emails
+ depth: 0
+ - value: "Flush"
+ url: flush
+ depth: 0
+ - value: "Get feature flag"
+ url: get-feature-flag
+ depth: 0
+ - value: "Get feature flag payload"
+ url: get-feature-flag-payload
+ depth: 0
+ - value: "Get feature flag result"
+ url: get-feature-flag-result
+ depth: 0
+ - value: "Get feature flags"
+ url: get-feature-flags
+ depth: 0
+ - value: "Get feature flags and payloads"
+ url: get-feature-flags-and-payloads
+ depth: 0
+ - value: "Evaluate flags"
+ url: evaluate-flags
+ depth: 0
+ - value: "Group identify"
+ url: group-identify
+ depth: 0
+ - value: "Is feature enabled"
+ url: is-feature-enabled
+ depth: 0
+ - value: "Shutdown"
+ url: shutdown
+ depth: 0
+ - value: "Flag definition loader"
+ url: flag-definition-loader
+ depth: 0
+ - value: "SDK utils"
+ url: sdk-utils
+ depth: 0
+ - value: "AsyncClient"
+ url: asyncclient
+ depth: 0
+ - value: "Module functions"
+ url: module-functions
+ depth: 0
+ - value: "Types"
+ url: types
+ depth: 0
+---
+
+## Getting started
+
+
+The Python SDK captures events, evaluates feature flags and reports errors from Python 3.10 or later.
+
+To send your first event, install the package, create a client, capture an event, and shut the client down, as the steps below show.
+
+### Install
+
+```bash
+pip install posthog
+```
+
+### Initialize
+
+Create one client for your app with your project token and host. Your project token and host are in your [project settings](https://app.posthog.com/project/settings). Keep the token in an environment variable rather than in code.
+
+```python
+from posthog import Posthog
+
+posthog = Posthog("", host="")
+```
+
+### Capture an event
+
+```python
+posthog.capture("user_signed_up", distinct_id="user_123", properties={"plan": "free"})
+```
+
+`capture` queues the event and returns right away. A background thread sends it.
+
+### Shut down
+
+Call `shutdown()` before your process exits, so queued events are sent.
+
+```python
+posthog.shutdown()
+```
+
+In an asyncio app, use `AsyncPosthog` as an async context manager instead. See [AsyncClient](#asyncclient).
+
+## Setup
+
+### `Client(...)`
+
+```python
+Client(project_api_key: str, host=None, *, debug=False, max_queue_size=10000, send=True, on_error=None, flush_at=100, flush_interval=5.0, max_retries=3, sync_mode=False, timeout: float = 15, thread=1, poll_interval=30, personal_api_key=None, disabled=False, disable_geoip=True, is_server=True, historical_migration=False, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries=1, super_properties=None, super_options=None, enable_exception_autocapture=False, log_captured_exceptions=False, project_root=None, privacy_mode=False, before_send=None, flag_fallback_cache_url=None, enable_local_evaluation=True, flag_definition_cache_provider: Optional[FlagDefinitionCacheProvider] = None, capture_exception_code_variables=False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: list[str] | None = None, enable_exception_autocapture_rate_limiting=False, exception_autocapture_bucket_size=ExceptionCapture.DEFAULT_BUCKET_SIZE, exception_autocapture_refill_rate=ExceptionCapture.DEFAULT_REFILL_RATE, exception_autocapture_refill_interval_seconds=ExceptionCapture.DEFAULT_REFILL_INTERVAL_SECONDS, capture_compression: Optional[Union[CaptureCompression, str]] = None, capture_ai_compression: Optional[Union[CaptureCompression, str]] = None, capture_ai_max_queue_size: int = 1000, capture_ai_timeout: float = 30, capture_ai_max_event_bytes: int = AI_MAX_MSG_SIZE, secret_key=None, metrics: Optional[dict] = None, enable_full_ai_capture=False, capture_trace_context=False, traces: Optional[dict] = None, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None)
+```
+
+Initialize a new PostHog client instance.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`project_api_key` | `str` | PostHog project API key/token. | *required*
+`host` | | PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as `https://us.posthog.com` are mapped to the corresponding ingestion host. | `None`
+`debug` | | Enable verbose SDK logging and re-raise errors from public API methods. | `False`
+`max_queue_size` | | Maximum number of analytics events buffered before upload. AI events use `capture_ai_max_queue_size`. | `10000`
+`send` | | If False, queueing succeeds but events are not sent. | `True`
+`on_error` | | Optional callback `(error, batch)` invoked when an upload fails: by background consumers, or on the calling thread in `sync_mode`. Capture failures arrive as `CaptureError`. Without it, each failed batch logs one aggregate line. A capture that fails inside the callback logs that line instead of calling it again. Keep it short and non-blocking. Calling lifecycle methods directly is safe and deferred, but do not start another thread or task that calls `flush()`, `join()`, or `shutdown()` and then wait for it from the callback. | `None`
+`flush_at` | | Number of queued events that triggers a batch upload. | `100`
+`flush_interval` | | Maximum seconds a background consumer waits before flushing a partial batch. | `5.0`
+`max_retries` | | Number of upload retries. Values below 0 are treated as 0. | `3`
+`sync_mode` | | If True, send each event synchronously instead of using background worker threads. This blocks the calling thread; in asyncio applications such as FastAPI, use `AsyncPosthog` instead. | `False`
+`timeout` | `float` | HTTP request timeout in seconds for event uploads. | `15`
+`thread` | | Number of background consumer threads. | `1`
+`poll_interval` | | Seconds between local feature flag definition refreshes. | `30`
+`secret_key` | | A Personal API Key or Project Secret API Key, used to authenticate local feature flag evaluation, remote config payloads, and decrypted flag payloads. For example, `posthog.Client(project_api_key, secret_key="phx_...")`. | `None`
+`personal_api_key` | | Deprecated alias for `secret_key`. Still honored for backwards compatibility; prefer `secret_key`, which also accepts a Project Secret API Key. | `None`
+`disabled` | | If True, disable captures and API requests. Useful in tests. | `False`
+`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. | `True`
+`is_server` | | Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally. Events get `$is_server` only when the event, context tags and `super_properties` leave it unset. | `True`
+`historical_migration` | | Mark events as historical migration imports. | `False`
+`feature_flags_request_timeout_seconds` | `float` | Timeout in seconds for feature flag and remote config requests. | `3`
+`feature_flags_request_max_retries` | | Number of retries for feature flag requests after network, transport, or timeout failures. Defaults to 1. Set to 0 to disable retries. | `1`
+`app_host` | `Optional[str]` | Your PostHog app host, such as `https://posthog.example.com`. `emails` sends there. Needed only when `host` is not PostHog Cloud, for example a reverse proxy, which must not receive the secret key. | `None`
+`email_request_timeout_seconds` | `float` | Timeout in seconds for each email send request. Defaults to 15. | `15`
+`email_request_max_retries` | `int` | Number of retries for an email send after a network error, a rate limit, or an unavailable service. Defaults to 2. Set to 0 when a job runner already retries the send. | `2`
+`migrated_from` | `Optional[str]` | The email provider you moved from, such as `"resend"`. `emails` sends it with every request. | `None`
+`super_properties` | | Properties for every captured event. They fill only keys the event leaves unset, before `before_send` runs. `$set`, `$set_once`, `$groups` and `$group_set` fill one level deep. An event's own properties and context tags override them, and `before_send` can change or remove them. | `None`
+`super_options` | | Capture options for every captured event, such as `{"cookieless_mode": True}`. They fill only options the event leaves unset, before `before_send` runs. An event's own `options` and context options override them, and `before_send` can change them. | `None`
+`enable_exception_autocapture` | | Automatically capture uncaught exceptions. | `False`
+`log_captured_exceptions` | | Also log exceptions captured by error tracking. | `False`
+`project_root` | | Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory. | `None`
+`privacy_mode` | | For AI observability, capture usage metadata without prompt inputs or outputs. | `False`
+`enable_full_ai_capture` | | Capture full AI content in PostHog AI wrapper events: skips string truncation and passes media (base64/data URIs) through unredacted. `privacy_mode` always wins. Wrapper events use the AI capture endpoint whether or not this is set. Defaults to False. | `False`
+`before_send` | | Optional callback that can modify or drop events before upload. Return `None` to drop an event. Context tags, context options, `super_properties`, `super_options` and the values the SDK adds, such as `$is_server`, `$geoip_disable` and `$os`, fill in before it runs, so it can change or remove them. | `None`
+`flag_fallback_cache_url` | | Optional feature flag fallback cache URL, such as `memory://local/?ttl=300&size=10000` or a Redis URL. | `None`
+`enable_local_evaluation` | | Whether to poll feature flag definitions for local evaluation when a personal API key is configured. | `True`
+`flag_definition_cache_provider` | `Optional[FlagDefinitionCacheProvider]` | Optional external cache provider for sharing feature flag definitions across workers. | `None`
+`capture_exception_code_variables` | | Capture local variable values on exception stack frames. | `False`
+`capture_trace_context` | | When OpenTelemetry is installed and a valid span is active at capture time, add its trace and span IDs as `$trace_id` and `$span_id` properties to events captured with `capture()` and `capture_ai()`, so they can be correlated with backend traces. They fill after context tags and `super_properties`, before `before_send`. A `$trace_id` or `$span_id` from the event, a context tag or `super_properties` stops the SDK adding either ID. Exception events (`capture_exception`) always attach these IDs regardless of this setting. Defaults to False. | `False`
+`traces` | `Optional[dict]` | Config dict for distributed tracing: `service_name`, `service_version`, `environment`, `resource_attributes`, `flush_interval` (5 s), `max_queue_size` (2048), `max_export_batch_size` (512), `max_live_spans` (10000), `max_span_age` (3600 s), `max_attributes_per_span` (128), `max_events_per_span` (128), `max_attribute_value_length` (8192). `before_span_send` is a callable, or a list run in order, that receives each finished span as a dict (`trace_id`, `span_id` and `parent_span_id` are read-only) and returns it, edited, or `None` to drop it; a hook that raises drops the span. Tracing is off until this is provided. Spans export on a background timer even with `sync_mode`; serverless handlers should call `flush()` before returning. Defaults to None. | `None`
+`code_variables_mask_patterns` | | Variable-name patterns to mask when capturing code variables. | `None`
+`code_variables_ignore_patterns` | | Variable-name patterns to omit when capturing code variables. | `None`
+`code_variables_mask_url_credentials` | | Scrub credentials embedded in URLs/DSNs (e.g. `user:pass@host`) from captured code variables, regardless of the surrounding variable name. Defaults to True. | `None`
+`code_variables_detect_secrets` | | Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True. | `None`
+`in_app_modules` | `list[str] \| None` | Module/package prefixes treated as in-app frames in captured exceptions. | `None`
+`enable_exception_autocapture_rate_limiting` | | Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default. | `False`
+`exception_autocapture_bucket_size` | | Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100). | `DEFAULT_BUCKET_SIZE`
+`exception_autocapture_refill_rate` | | Tokens restored per refill interval for each exception type's bucket. | `DEFAULT_REFILL_RATE`
+`exception_autocapture_refill_interval_seconds` | | Seconds between token refills for autocaptured exception rate limiting. | `DEFAULT_REFILL_INTERVAL_SECONDS`
+`capture_compression` | `Optional[Union[CaptureCompression, str]]` | Request-body compression for `capture()` uploads. `CaptureCompression.GZIP` or `DEFLATE` (or the strings `"gzip"`/`"deflate"`). When omitted, the `POSTHOG_CAPTURE_COMPRESSION` env var is consulted, then no compression. | `None`
+`capture_ai_compression` | `Optional[Union[CaptureCompression, str]]` | Request-body compression for `capture_ai()` uploads, set independently of `capture_compression`. Defaults to no compression, and the env var does not apply. `CaptureCompression.ZSTD` suits large AI payloads. | `None`
+`capture_ai_max_queue_size` | `int` | Maximum number of AI events buffered before upload. Defaults to 1000, lower than `max_queue_size` because AI events are much larger. | `1000`
+`capture_ai_timeout` | `float` | Seconds allowed for one AI upload request. Defaults to 30, longer than `timeout` because AI batches are much larger. | `30`
+`capture_ai_max_event_bytes` | `int` | Largest serialized AI event the SDK sends; a larger one is dropped with an error log. Defaults to the AI endpoint's ceiling plus envelope headroom, and may only be lowered. | `AI_MAX_MSG_SIZE`
+
+**Examples:**
+
+```python
+from posthog import Posthog
+
+posthog = Posthog('', host='')
+```
+
+## Capture
+
+### `Client.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to capture. | *required*
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to include with the event. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | A dictionary of group information. It merges into a `$groups` property and wins key by key. |
+`flags` | | A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. |
+`send_feature_flags` | | Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. |
+`disable_geoip` | | Whether to disable GeoIP for this event. It wins over a `$geoip_disable` in context tags or `super_properties`. A `$geoip_disable` property in this call's `properties` wins over it. |
+`options` | | Capture options for this event, such as `{"process_person_profile": False}`. Sent as given, for PostHog to validate. They override context options and `super_options`, which fill in before `before_send` runs. An option overrides its legacy `$` property, such as `$process_person_profile`. A `None` option counts as unset. |
+
+**Examples:**
+
+```python
+# Anonymous event
+posthog.capture('some-anon-event')
+```
+```python
+# Context usage
+from posthog import identify_context, new_context
+with new_context():
+ identify_context('distinct_id_of_the_user')
+ posthog.capture('user_signed_up')
+ posthog.capture('user_logged_in')
+ posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')
+```
+```python
+# Set event properties
+posthog.capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+```python
+# Page view event
+posthog.capture('$pageview', distinct_id="distinct_id_of_the_user", properties={'$current_url': 'https://example.com'})
+```
+
+## Identify
+
+### `Client.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+# Set with distinct id
+posthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+### `Client.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile only if they haven't been set before.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set once. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Traces
+
+### `Client.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on
+the way out); or call `end()` yourself for a span that cannot wrap a
+block. Spans started inside the block nest under it automatically.
+Always returns a usable handle, even when tracing is off, so calling
+code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. A forked child starts with no active span; pass the parent span to continue a trace across a fork. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+posthog = Posthog("", traces={"service_name": "checkout-api"})
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `Client.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes
+it active; a span started manually is not. Use it to propagate the
+trace to the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+## Alias
+
+### `Client.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+Create an alias between two distinct IDs.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The previous distinct ID. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`distinct_id` | `Optional[str]` | The new distinct ID to alias to. Required - the call is dropped with a warning if it is missing or empty. The context distinct ID is never used here. | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+`options` | `Optional[Dict[str, Any]]` | Capture options for this event, sent as given. | `None`
+
+**Examples:**
+
+```python
+posthog.alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Capture AI
+
+### `Client.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size
+cap, batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`:
+the event UUID, or None when the event was not admitted (disabled
+client, or dropped by `before_send`). The event is queued on an
+isolated AI lane with its own consumer pool and a higher per-event
+size cap, posting to the dedicated AI ingestion endpoint. The payload
+is sent as given — no redaction or truncation is applied here.
+
+## Capture exception
+
+### `Client.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg], *, level: Optional[str] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception for error tracking.
+
+When OpenTelemetry is installed and a valid span is active, its trace and
+span IDs are added as `$trace_id` and `$span_id` event properties,
+unless the event, a context tag or `super_properties` sets either one.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. | *required*
+`level` | `Optional[str]` | The `$exception_level`, such as `"warning"` or `"fatal"`. Defaults to `"error"`. An unknown value counts as unset. | `None`
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of additional properties. Reserved exception properties, such as `$exception_list` and `$exception_level`, are ignored. |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. Attaches those exact flag values to the captured `$exception` event. |
+`send_feature_flags` | | Deprecated. Pass `flags` from `evaluate_flags()` instead. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+try:
+ # Some code that might fail
+ pass
+except Exception as e:
+ posthog.capture_exception(e, distinct_id='user_distinct_id', properties=additional_properties)
+```
+
+## Emails
+
+### `Client.emails`
+
+```python
+emails: Emails
+```
+
+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 the `transactional_email:write`
+scope. Sends go to `app_host`, or to the PostHog Cloud app host of
+`host`. `email_request_timeout_seconds` and `email_request_max_retries`
+configure each send. A disabled or shut-down client sends nothing. See
+`posthog.emails` for setup.
+
+**Examples:**
+
+```python
+client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+)
+```
+
+## Flush
+
+### `Client.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events, ended spans and autocaptured metrics, keeping the client reusable.
+
+For a client shared across requests or serverless invocations (including
+the module-level client), call `flush()` before a short-lived invocation
+returns. Use `shutdown()` instead only for final process cleanup or when
+disposing of a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after
+a timeout or span export failure, and failed events may be dropped by the
+consumers. Calls made directly from SDK callbacks such as `on_error` are
+deferred rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently. The span exporter waits up to this many seconds for an in-flight flush, then uses a fresh drain budget once it acquires the lock. If the lock wait times out, the in-flight flush is left to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. Each span request is bounded by the client's `timeout` in seconds, and the last request is not cut short. This is therefore not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the shared client open.
+posthog.flush(timeout_seconds=10)
+```
+
+## Get feature flag
+
+### `Client.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get multivariate feature flag value for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag payload
+
+### `Client.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, *, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload for a feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`match_value` | `Optional[FlagValue]` | The specific flag value to get payload for. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Deprecated. Use get_feature_flag() instead if you need events. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This method returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag result
+
+### `Client.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely
+depending on whether local evaluation is enabled and the flag can be locally evaluated.
+This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.
+When the flag was evaluated remotely and its config version 2 record is a complete experiment
+split (an experiment rule with a rule ID and a variant key), it also captures the
+`$experiment_exposure` event, once per distinct ID, groups, flag, rule and variant.
+
+**Examples:**
+
+```python
+flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')
+if flag_result and flag_result.get_value() == 'variant-key':
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = flag_result.payload
+```
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagResult]` | Optional[FeatureFlagResult]: The feature flag result or None if disabled/not found.
+
+## Get feature flags
+
+### `Client.get_feature_variants`
+
+```python
+get_feature_variants(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Union[bool, str]]
+```
+
+Get feature flag variants for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+### `Client.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> Optional[dict[str, Union[bool, str]]]
+```
+
+Get all feature flags for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags('distinct_id_of_your_user')
+```
+
+## Get feature flags and payloads
+
+### `Client.get_feature_flags_and_payloads`
+
+```python
+get_feature_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get feature flags and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+result = posthog.get_feature_flags_and_payloads('')
+```
+
+### `Client.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get all feature flags and their payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags_and_payloads('distinct_id_of_your_user')
+```
+
+## Evaluate flags
+
+### `Client.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[List[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+Local evaluation is transparent: when the poller resolves a flag, the
+snapshot's `$feature_flag_called` events are tagged `locally_evaluated=True`
+and reason `"Evaluated locally"`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If True, never fall back to remote evaluation — flags that can't be evaluated locally are omitted from the snapshot and listed with a reason in its `unresolved_flags`. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[List[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is True. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagEvaluations` | A `FeatureFlagEvaluations` snapshot.
+
+**Examples:**
+
+```python
+flags = posthog.evaluate_flags(
+ "user_123",
+ person_properties={"plan": "enterprise"},
+)
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+## Group identify
+
+### `Client.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+Identify a group and set its properties.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | The type of group (e.g., 'company', 'team'). Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | The unique identifier for the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | A dictionary of properties to set on the group. | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[Union[str, UUID]]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user performing the action. Falls back to the context distinct ID, then to `$_`. | `None`
+`options` | `Optional[Dict[str, Any]]` | Capture options for this event, sent as given. | `None`
+
+**Examples:**
+
+```python
+posthog.group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Is feature enabled
+
+### `Client.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Check if a feature flag is enabled for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Shutdown
+
+### `Client.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and end the consumer threads. Do not use directly, call `shutdown()` instead.
+
+Failed or undrainable events may be dropped and reported through logging
+or `on_error`; returning does not guarantee server receipt. Lifecycle
+cleanup is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+posthog.join()
+```
+
+### `Client.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the client.
+
+Call this for final process cleanup or when disposing of a client that
+will not be reused. It closes capture lanes, stops background workers and
+the feature flag poller, and tears down integrations. Do not call it at the
+end of each request or serverless invocation when the client is shared;
+call `flush()` before returning instead. A shut-down client cannot be
+reused; create a new client if needed.
+
+Normally this method blocks until queued events have been attempted and
+cleanup finishes. Failed or undrainable events may be dropped and
+reported through logging or `on_error`; returning does not guarantee
+server receipt. Event draining has no timeout. Queued spans get one final
+flush with up to 30 seconds waiting for an in-flight flush, then a fresh
+30-second drain budget; the last HTTP request is not cut short. Any spans
+it cannot send are discarded with a warning, as are spans still open.
+Lifecycle cleanup is attempted once, and cleanup failures
+are logged without retry. When called directly from an SDK callback such as
+`on_error`, shutdown is deferred to avoid blocking the worker that
+invoked the callback. If the callback must coordinate a blocking
+shutdown, have it signal an
+application-owned thread and return before that thread calls shutdown.
+Do not wait inside the callback for another thread or task that calls a
+lifecycle method.
+
+**Examples:**
+
+```python
+posthog.shutdown()
+```
+
+## Flag definition loader
+
+### `Client.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flags for local evaluation.
+
+**Examples:**
+
+```python
+posthog.load_feature_flags()
+```
+
+### `Client.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Return feature flag definitions loaded for local evaluation.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The currently loaded feature flag definitions, or `None` before local evaluation has loaded definitions.
+
+## SDK utils
+
+### `Client.queue`
+
+```python
+queue: Queue
+```
+
+The analytics lane's queue (kept for backwards compatibility).
+
+### `Client.consumers`
+
+```python
+consumers: Optional[List[Consumer]]
+```
+
+Flat list of the lanes' consumers, analytics first (kept for backwards compatibility).
+
+### `Client.new_context`
+
+```python
+new_context(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+with client.new_context():
+ client.identify_context('')
+ client.capture('event_name')
+```
+
+### `Client.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the wrapped function using this client.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+### `Client.tag`
+
+```python
+tag(name: str, value: Any) -> None
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key. | *required*
+`value` | `Any` | The tag value. | *required*
+
+### `Client.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context.
+
+### `Client.set_context_option`
+
+```python
+set_context_option(key: str, value: Any) -> None
+```
+
+Set a capture option for every event captured within the current context.
+
+Context options fill options an event leaves unset, before
+`before_send` runs, so the hook sees them. They override
+`super_options`. An event's own `options` override them, and
+`before_send` can change them.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The option name, such as `"process_person_profile"`. | *required*
+`value` | `Any` | The option value, sent as given. | *required*
+
+### `Client.get_context_options`
+
+```python
+get_context_options() -> Dict[str, Any]
+```
+
+Get all capture options from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all capture options in the current context.
+
+### `Client.identify_context`
+
+```python
+identify_context(distinct_id: str) -> None
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_session`
+
+```python
+set_context_session(session_id: str) -> None
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str) -> None
+```
+
+Set the device ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children. | *required*
+
+### `Client.feature_flags`
+
+```python
+feature_flags
+```
+
+Get the local evaluation feature flags.
+
+### `Client.get_feature_payloads`
+
+```python
+get_feature_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Optional[str]]
+```
+
+Get feature flag payloads for a user, preserving valid serialized JSON.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+payloads = posthog.get_feature_payloads('')
+```
+
+### `Client.get_flags_decision`
+
+```python
+get_flags_decision(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsResponse
+```
+
+Get feature flags decision.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+decision = posthog.get_flags_decision('user123')
+```
+
+### `Client.metrics`
+
+```python
+metrics: PostHogMetrics
+```
+
+The `posthog.metrics` API: a statsd-style pre-aggregating metrics client — alpha.
+
+Samples fold into per-series aggregates in memory and flush as one OTLP
+data point per series per window, so recording from hot paths is cheap.
+Configure via the `metrics` client option; pending metrics flush on
+`shutdown()`.
+
+**Examples:**
+
+```python
+client = Posthog("", metrics={"service_name": "billing-worker"})
+client.metrics.count("invoices.processed", 1, attributes={"plan": "pro"})
+client.metrics.gauge("queue.depth", 42)
+client.metrics.histogram("job.duration", 187, unit="ms")
+```
+
+### `Client.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The remote config feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag, or `None` if the client is disabled, no personal API key is configured, or the request fails. Encrypted payloads are decrypted by PostHog before being returned.
+
+
+Note
+
+Requires `secret_key` for authentication.
+
+
+
+### `Client.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagEvaluationRuntime]` | The flag's evaluation runtime, or `None` when local evaluation has not loaded a definition for this key. A definition that carries no runtime reports `FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+runtime = posthog.get_feature_flag_evaluation_runtime("my-flag")
+if runtime is FeatureFlagEvaluationRuntime.SERVER:
+ ...
+```
+
+### `Client.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime,
+so it is returned for `CLIENT` and for `SERVER`, and asking for
+`ALL` returns every loaded flag. Use this to decide which flags to hand
+to a browser when a backend serves flags to its own frontend.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`evaluation_runtime` | `Union[FeatureFlagEvaluationRuntime, str]` | The runtime to match, as a `FeatureFlagEvaluationRuntime` or its string value. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`list[str]` | The matching flag keys, in the order local evaluation loaded them. Empty when no definitions are loaded.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+client_keys = posthog.get_feature_flag_keys_by_evaluation_runtime(
+ FeatureFlagEvaluationRuntime.CLIENT
+)
+```
+
+### `posthog.integrations.django.PosthogContextMiddleware`
+
+```python
+PosthogContextMiddleware(get_response)
+```
+
+Middleware to automatically track Django requests.
+
+This middleware wraps all calls with a posthog context. It attempts to extract the following from the request:
+- Session ID, (extracted from `X-POSTHOG-SESSION-ID`)
+- Distinct ID, (extracted from `X-POSTHOG-DISTINCT-ID`, falling back to the authenticated request user ID)
+- Authenticated user email as `email`
+- Request URL as `$current_url`
+- Request method as `$request_method`
+- Request path as `$request_path`
+- Forwarded IP address as `$ip`
+- User agent as `$user_agent`
+
+Configure the integration with these Django settings:
+- `POSTHOG_MW_CLIENT`: client used for automatic exception capture, or the global client.
+ This does not redirect events explicitly captured through other clients.
+- `POSTHOG_MW_CAPTURE_EXCEPTIONS`: `False` enables context enrichment only;
+ `True` enables automatic exception capture; `None` inherits the effective client's
+ `enable_exception_autocapture`. When omitted, the legacy default is `True`.
+- `POSTHOG_MW_REQUEST_FILTER`: a callback receiving the request. Returning `False`
+ disables both enrichment and automatic exception capture for that request.
+- `POSTHOG_MW_EXTRA_PROPERTIES`: a callback returning additional event properties.
+- `POSTHOG_MW_CAPTURE_TRACING_HEADERS`: read PostHog identity and session headers
+ as request-scoped analytics context (default: `True`). Explicit capture IDs and
+ event properties take precedence. These values are never authentication or
+ authorization. Authenticated Django user identity remains the fallback when no
+ usable header ID is available or header capture is disabled.
+- `POSTHOG_MW_TRUST_TRACING_HEADERS`: deprecated alias for
+ `POSTHOG_MW_CAPTURE_TRACING_HEADERS`; the capture-named setting takes precedence.
+- `POSTHOG_MW_PROPERTIES_MAP`: an optional callback transforming request properties.
+
+The old `POSTHOG_MW_EXTRA_TAGS` and `POSTHOG_MW_TAG_MAP` settings remain aliases;
+the property-named settings take precedence when both are configured.
+
+Request properties are included on all events captured within the active context,
+including when automatic exception capture is disabled.
+See the context documentation for more information. The extracted distinct ID and session ID,
+if found, are used to associate all events captured in the middleware context with the same distinct ID
+and session as currently active on the frontend. See the documentation for `set_context_session`
+and `identify_context` for more details.
+
+This middleware is hybrid-capable: it supports both WSGI (sync) and ASGI (async) Django applications. The middleware
+detects at initialization whether the next middleware in the chain is async or sync, and adapts its behavior accordingly.
+This ensures compatibility with both pure sync and pure async middleware chains, as well as mixed chains in ASGI mode.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`aextract_properties` | Async version of extract_properties for use in async request handling.
+`aextract_request_user` | Async version of extract_request_user for use in async request handling.
+`aextract_tags` | Compatibility alias for `aextract_properties`.
+`extract_properties` | Extract event properties and identity from a synchronous request.
+`extract_request_user` | Extract user ID and email from request in sync context.
+`extract_tags` | Compatibility alias for `extract_properties`.
+`process_exception` | Process exceptions from views and downstream middleware.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`async_capable` | |
+`capture_exceptions` | `Optional[bool]` |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`extra_tags` | | Compatibility alias for `extra_properties`.
+`get_response` | |
+`properties_map` | |
+`request_filter` | |
+`sync_capable` | |
+`tag_map` | | Compatibility alias for `properties_map`.
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+Initialize the middleware with Django's next handler.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`get_response` | | The next middleware or view handler in Django's middleware chain. May be synchronous or asynchronous. |
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_properties`
+
+```python
+async aextract_properties(request)
+```
+
+Async version of extract_properties for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_request_user`
+
+```python
+async aextract_request_user(request)
+```
+
+Async version of extract_request_user for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_tags`
+
+```python
+async aextract_tags(request)
+```
+
+Compatibility alias for `aextract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.async_capable`
+
+```python
+async_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_exceptions`
+
+```python
+capture_exceptions: Optional[bool] = capture_exceptions if (capture_exceptions is None or isinstance(capture_exceptions, bool)) else True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers, canonical_name='POSTHOG_MW_CAPTURE_TRACING_HEADERS', deprecated_name='POSTHOG_MW_TRUST_TRACING_HEADERS')
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.client`
+
+```python
+client = cast('Optional[Client]', settings.POSTHOG_MW_CLIENT)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_properties`
+
+```python
+extra_properties = cast('Callable[[HttpRequest], Dict[str, Any]]', extra_properties) if callable(extra_properties) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_tags`
+
+```python
+extra_tags
+```
+
+Compatibility alias for `extra_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_properties`
+
+```python
+extract_properties(request)
+```
+
+Extract event properties and identity from a synchronous request.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_request_user`
+
+```python
+extract_request_user(request)
+```
+
+Extract user ID and email from request in sync context.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_tags`
+
+```python
+extract_tags(request)
+```
+
+Compatibility alias for `extract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.get_response`
+
+```python
+get_response = get_response
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.process_exception`
+
+```python
+process_exception(request, exception)
+```
+
+Process exceptions from views and downstream middleware.
+
+Django calls this WHILE still inside the context created by __call__,
+so request tags have already been extracted and set. This method just
+needs to capture the exception directly.
+
+Django converts view exceptions into responses before they propagate through
+the middleware stack, so the context manager in __call__/__acall__ never sees them.
+
+Note: Django's process_exception is always synchronous, even for async views.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.properties_map`
+
+```python
+properties_map = cast('Callable[[Dict[str, Any]], Dict[str, Any]]', properties_map) if callable(properties_map) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.request_filter`
+
+```python
+request_filter = cast('Optional[Callable[[HttpRequest], bool]]', settings.POSTHOG_MW_REQUEST_FILTER)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.sync_capable`
+
+```python
+sync_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.tag_map`
+
+```python
+tag_map
+```
+
+Compatibility alias for `properties_map`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.flask.PosthogFlaskIntegration`
+
+```python
+PosthogFlaskIntegration(app: Optional[Flask] = None, *, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[Callable[[Request], bool]] = None, extra_properties: Optional[Callable[[Request], Mapping[str, Any]]] = None, trust_tracing_headers: Optional[bool] = None, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog request context and exception tracking to a Flask app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `Optional[Flask]` | An optional Flask application. If omitted, call `init_app` later (the Flask application-factory pattern). | `None`
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions that reach Flask's unhandled exception machinery. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[Callable[[Request], bool]]` | Optional callback receiving Flask's request object. A false return value disables both context and exception capture for that request. | `None`
+`extra_properties` | `Optional[Callable[[Request], Mapping[str, Any]]]` | Optional callback returning additional event properties. This is useful for application-specific metadata such as an authenticated user's role. Values should not contain secrets or request bodies. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+The integration intentionally does not capture exceptions handled by an
+application error handler, expected HTTP exceptions, request or response
+bodies, query strings, cookies, authorization headers, or arbitrary headers.
+Call `capture_exception` explicitly from a custom error handler if a
+handled exception should be reported.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`init_app` | Register the integration with a Flask application once.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.init_app`
+
+```python
+init_app(app: Flask) -> None
+```
+
+Register the integration with a Flask application once.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.asgi.PosthogASGIMiddleware`
+
+```python
+PosthogASGIMiddleware(app: _ASGIApp, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[_RequestFilter] = None, extra_properties: Optional[_ExtraProperties] = None, trust_tracing_headers: Optional[bool] = None, *, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog context and automatic exception capture to an ASGI app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `_ASGIApp` | The downstream ASGI application. | *required*
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions escaping the downstream app. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[_RequestFilter]` | Optional sync or async callback receiving the ASGI scope. Returning `False` bypasses all instrumentation for that scope. | `None`
+`extra_properties` | `Optional[_ExtraProperties]` | Optional sync or async callback receiving the ASGI scope and returning additional event properties. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`app` | |
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.app`
+
+```python
+app = app
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.celery.PosthogCeleryIntegration`
+
+```python
+PosthogCeleryIntegration(client: Optional[Client] = None, capture_exceptions: bool = True, capture_task_lifecycle_events: bool = True, propagate_context: bool = True, task_filter: Optional[Callable[[Optional[str], dict[str, Any]], bool]] = None)
+```
+
+Celery integration that captures task lifecycle events and exceptions.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`client` | `Optional[Client]` | Optional `Client` instance. When provided, all events and exceptions are captured through this client rather than the global `posthog` module. Don't skip this if using a custom flag definition cache provider, and pass the custom `Client` instance here initialized with the custom provider so fork safety for that provider is handled correctly. | `None`
+`capture_exceptions` | `bool` | Whether to capture task exceptions via `capture_exception` (default `True`). | `True`
+`capture_task_lifecycle_events` | `bool` | Whether to emit lifecycle events of the task such as "started", "success", "failure" etc. (default `True`). | `True`
+`propagate_context` | `bool` | Whether to propagate PostHog context (distinct ID, session ID, tags, context options) from the producer to the worker via task headers (default `True`). | `True`
+`task_filter` | `Optional[Callable[[Optional[str], dict[str, Any]], bool]]` | Optional callback `(task_name, task_properties) -> bool` expected to return `False` if a given task should not be tracked. | `None`
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`instrument` | Connect Celery signal handlers to capture task events and exceptions. Call this after initializing the PostHog client and this integration.
+`shutdown` | Disconnect all signal handlers registered by `instrument()`, flush all pending events and cleanly shutdown the integration.
+`uninstrument` | Disconnect Celery signal handlers and unregister exit cleanup.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_task_lifecycle_events` | |
+`client` | |
+`propagate_context` | |
+`task_filter` | |
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_task_lifecycle_events`
+
+```python
+capture_task_lifecycle_events = capture_task_lifecycle_events
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.instrument`
+
+```python
+instrument() -> None
+```
+
+Connect Celery signal handlers to capture task events and exceptions.
+Call this after initializing the PostHog client and this integration.
+
+If Celery runs on a single host, reinstrumenting in worker children is
+not strictly necessary because the PostHog client and this integration
+are fork-safe. If Celery workers run across multiple hosts, each worker
+process must initialize PostHog, this integration, and call
+`instrument()`. Celery provides `worker_process_init` signal to help
+with this.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.propagate_context`
+
+```python
+propagate_context = propagate_context
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Disconnect all signal handlers registered by `instrument()`, flush all pending events
+and cleanly shutdown the integration.
+
+`shutdown()` is also registered on `worker_process_shutdown` and `atexit` signals,
+but there is no guarantee those will always be called, so we strongly recommend calling
+it manually when the integration is no longer needed to avoid data loss.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.task_filter`
+
+```python
+task_filter = task_filter
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.uninstrument`
+
+```python
+uninstrument() -> None
+```
+
+Disconnect Celery signal handlers and unregister exit cleanup.
+
+Do not use directly, call `shutdown()` instead.
+
+### `posthog.request.set_socket_options`
+
+```python
+set_socket_options(socket_options: Optional[SocketOptions]) -> None
+```
+
+Configure socket options for all SDK HTTP connections.
+
+Call this during initialization, before making API requests. Pass `None`
+to reset to the default socket behavior.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`socket_options` | `Optional[SocketOptions]` | A list of `(level, option, value)` tuples accepted by urllib3/`socket.setsockopt()`, or `None` to reset defaults. | *required*
+
+
+Example
+
+from posthog import set_socket_options
+set_socket_options([(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)])
+
+
+
+### `posthog.request.enable_keep_alive`
+
+```python
+enable_keep_alive() -> None
+```
+
+Enable TCP keepalive for SDK HTTP connections.
+
+This helps prevent idle pooled connections from being dropped by network
+infrastructure. Call during initialization, before making API requests.
+
+### `posthog.request.disable_connection_reuse`
+
+```python
+disable_connection_reuse() -> None
+```
+
+Disable HTTP connection reuse for SDK requests.
+
+Each request will create a fresh connection. This can avoid issues with
+environments that terminate pooled connections, but adds per-request
+overhead. Call during initialization, before making API requests.
+
+## AsyncClient
+
+Needs the `async` extra, `posthog[async]`.
+
+### `AsyncClient(...)`
+
+```python
+AsyncClient(project_api_key: str, host: Optional[str] = None, *, debug: bool = False, max_queue_size: int = 10000, send: bool = True, on_error=None, flush_at: int = 100, flush_interval: float = 5.0, max_retries: int = 3, timeout: float = 15, thread: int = 1, disabled: bool = False, disable_geoip: bool = True, is_server: bool = True, historical_migration: bool = False, super_properties: Optional[dict[str, Any]] = None, super_options: Optional[dict[str, Any]] = None, before_send=None, log_captured_exceptions: bool = False, project_root: Optional[str] = None, capture_exception_code_variables: bool = False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: Optional[list[str]] = None, capture_compression: Optional[Union[CaptureCompression, str]] = None, capture_ai_compression: Optional[Union[CaptureCompression, str]] = None, capture_ai_max_queue_size: int = 1000, capture_ai_timeout: float = 30, capture_ai_max_event_bytes: int = AI_MAX_MSG_SIZE, privacy_mode: bool = False, enable_full_ai_capture: bool = False, capture_trace_context: bool = False, secret_key: Optional[str] = None, personal_api_key: Optional[str] = None, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries: int = 1, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None) -> None
+```
+
+### `AsyncClient.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Queue an event without blocking for network delivery.
+
+### `AsyncClient.capture_immediate`
+
+```python
+async capture_immediate(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture one event and wait until its delivery attempt completes.
+
+### `AsyncClient.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+### `AsyncClient.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, *, level: Optional[str] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception. This method never raises, including in debug mode.
+
+`level` sets `$exception_level` and defaults to `"error"`. An unknown
+value counts as unset. Reserved exception properties in `properties`,
+such as `$exception_list` and `$exception_level`, are ignored.
+
+When OpenTelemetry is installed and a valid span is active, its trace and
+span IDs are added as `$trace_id` and `$span_id` event properties,
+unless the event, a context tag or `super_properties` sets either one.
+
+### `AsyncClient.emails`
+
+```python
+emails: AsyncEmails
+```
+
+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 the `transactional_email:write`
+scope, and `posthog[async]`. Sends go to `app_host`, or to the PostHog
+Cloud app host of `host`. `email_request_timeout_seconds` and
+`email_request_max_retries` configure each send. A disabled or shut-down
+client sends nothing. See `posthog.emails` for setup.
+
+**Examples:**
+
+```python
+await client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ distinct_id="user_123",
+)
+```
+
+### `AsyncClient.flush`
+
+```python
+async flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+### `AsyncClient.evaluate_flags`
+
+```python
+async evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate flags remotely without blocking the event loop.
+
+The returned snapshot has synchronous in-memory accessors. Pass it to
+`capture(flags=...)` to attach the exact values used for branching.
+This client does not evaluate flags locally, so the snapshot's
+`unresolved_flags` is always empty.
+
+### `AsyncClient.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+### `AsyncClient.shutdown`
+
+```python
+async shutdown() -> None
+```
+
+### `AsyncClient.join`
+
+```python
+async join() -> None
+```
+
+### `AsyncClient.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Queue an AI event for the AI capture endpoint without blocking.
+
+Takes the same arguments and returns the same value as `capture()`.
+The event uses a separate queue with a larger per-event size cap. The
+payload is sent as given, with no redaction or truncation.
+
+### `AsyncClient.capture_ai_immediate`
+
+```python
+async capture_ai_immediate(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture one AI event and wait until its delivery attempt completes.
+
+Uses the AI capture endpoint and the `capture_ai_*` settings.
+
+### `AsyncClient.get_remote_config_payload`
+
+```python
+async get_remote_config_payload(key: str) -> Optional[Any]
+```
+
+Fetch and decrypt a remote-config payload without blocking the loop.
+
+## Module functions
+
+### `posthog.new_context`
+
+```python
+new_context(fresh: bool = False, capture_exceptions: Optional[bool] = None, client: Optional[Client] = None)
+```
+
+Create a new context scope that will be active for the duration of the with block.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | `bool` | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting. | `None`
+`client` | `Optional[Client]` | Optional Posthog client instance to use for this context (default: None) | `None`
+
+**Examples:**
+
+```python
+from posthog import new_context, tag, capture
+with new_context():
+ tag("request_id", "123")
+ capture("event_name", properties={"property": "value"})
+```
+
+### `posthog.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the function.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+from posthog import scoped, tag, capture
+@scoped()
+def process_payment(payment_id):
+ tag("payment_id", payment_id)
+ capture("payment_started")
+```
+
+### `posthog.set_context_session`
+
+```python
+set_context_session(session_id: str)
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_session
+set_context_session("session_123")
+```
+
+### `posthog.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str)
+```
+
+Set the device ID for the current context, associating all feature flag requests
+in this or child contexts with the given device ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_device_id
+set_context_device_id("device_123")
+```
+
+### `posthog.identify_context`
+
+```python
+identify_context(distinct_id: str)
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import identify_context
+identify_context("user_123")
+```
+
+### `posthog.set_capture_exception_code_variables_context`
+
+```python
+set_capture_exception_code_variables_context(enabled: bool)
+```
+
+Override code-variable capture for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`enabled` | `bool` | Whether exceptions captured in this context should include local variable values from stack frames. | *required*
+
+### `posthog.set_code_variables_mask_patterns_context`
+
+```python
+set_code_variables_mask_patterns_context(mask_patterns: list[str])
+```
+
+Override code-variable mask patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`mask_patterns` | `list[str]` | Variable-name patterns whose values should be replaced with `***` when code variables are captured. | *required*
+
+### `posthog.set_code_variables_ignore_patterns_context`
+
+```python
+set_code_variables_ignore_patterns_context(ignore_patterns: list[str])
+```
+
+Override code-variable ignore patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`ignore_patterns` | `list[str]` | Variable-name patterns that should be omitted entirely when code variables are captured. | *required*
+
+### `posthog.set_code_variables_mask_url_credentials_context`
+
+```python
+set_code_variables_mask_url_credentials_context(enabled: bool)
+```
+
+Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from
+captured code variables for the current context.
+
+### `posthog.set_code_variables_detect_secrets_context`
+
+```python
+set_code_variables_detect_secrets_context(enabled: bool)
+```
+
+Whether to apply entropy-based secret detection as a last-resort redaction of
+high-entropy values (API keys, tokens, strong passwords) in captured code
+variables for the current context.
+
+### `posthog.tag`
+
+```python
+tag(name: str, value: Any)
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key | *required*
+`value` | `Any` | The tag value | *required*
+
+**Examples:**
+
+```python
+from posthog import tag
+tag("user_id", "123")
+```
+
+### `posthog.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context
+
+### `posthog.set_context_option`
+
+```python
+set_context_option(key: str, value: Any) -> None
+```
+
+Set a capture option for every event captured within the current context.
+
+Context options fill options an event leaves unset, before `before_send`
+runs, so the hook sees them. They override `super_options`. An event's
+own `options` override them, and `before_send` can change them.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The option name, such as `"process_person_profile"` | *required*
+`value` | `Any` | The option value, sent as given | *required*
+
+**Examples:**
+
+```python
+from posthog import new_context, set_context_option
+with new_context():
+ set_context_option("process_person_profile", False)
+```
+
+### `posthog.get_context_options`
+
+```python
+get_context_options() -> Dict[str, Any]
+```
+
+Get all capture options from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all capture options in the current context
+
+### `posthog.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture anything a user does within your system.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to specify the event | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional arguments including: distinct_id: Unique identifier for the user properties: Dict of event properties timestamp: When the event occurred. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this event. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. groups: Dict of group types and IDs flags: A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. send_feature_flags: Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. disable_geoip: Whether to disable GeoIP lookup | `{}`
+
+
+Details
+
+Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.
+
+
+
+**Examples:**
+
+```python
+# Context and capture usage
+from posthog import new_context, identify_context, tag, capture
+# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)
+with new_context():
+ # Associate this context with some user, by distinct_id
+ identify_context('some user')
+
+ # Capture an event, associated with the context-level distinct ID ('some user')
+ capture('movie started')
+
+ # Capture an event associated with some other user (overriding the context-level distinct ID)
+ capture('movie joined', distinct_id='some-other-user')
+
+ # Capture an event with some properties
+ capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})
+
+ # Capture an event with some properties
+ capture('purchase', properties={'product_id': '123', 'category': 'romcom'})
+ # Capture an event with some associated group
+ capture('purchase', groups={'company': 'id:5'})
+
+ # Adding a tag to the current context will cause it to appear on all subsequent events
+ tag('some-tag', 'some-value')
+
+ capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict
+```
+```python
+# Set event properties
+from posthog import capture
+capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+
+### `posthog.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size cap,
+batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`: the
+event UUID, or None when the event was not admitted (disabled client, or
+dropped by `before_send`). The event is delivered on an isolated queue
+with its own consumer pool and a higher per-event size cap, posting to
+the dedicated AI ingestion endpoint. The payload is sent as given — no
+redaction or truncation is applied here.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name, normally one of the `$ai_*` event names. | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Same optional arguments as `capture()`. | `{}`
+
+**Examples:**
+
+```python
+from posthog import capture_ai
+
+uuid = capture_ai(
+ "$ai_generation",
+ distinct_id="user_123",
+ properties={"$ai_model": "gpt-5"},
+)
+```
+
+### `posthog.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).
+
+
+
+**Examples:**
+
+```python
+# Set person properties
+from posthog import set
+set(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})
+```
+
+### `posthog.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record, only if they do not yet exist.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set only once. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.
+
+
+
+**Examples:**
+
+```python
+# Set property once
+from posthog import set_once
+set_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})
+
+```
+
+### `posthog.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+Set properties on a group.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | Type of your group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | Unique identifier of the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | Properties to set on the group | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`distinct_id` | `Optional[ID_TYPES]` | Optional distinct ID of the user performing the action | `None`
+`options` | `Optional[Dict[str, Any]]` | Optional capture options for the event, sent as given | `None`
+
+**Examples:**
+
+```python
+# Group identify
+from posthog import group_identify
+group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+### `posthog.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: str, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, options: Optional[Dict[str, Any]] = None) -> Optional[str]
+```
+
+Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The unique ID of the user before | *required*
+`distinct_id` | `str` | The current unique id | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`options` | `Optional[Dict[str, Any]]` | Optional capture options for the event, sent as given | `None`
+
+
+Details
+
+To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+
+
+**Examples:**
+
+```python
+# Alias user
+from posthog import alias
+alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+### `posthog.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, *, level: Optional[str] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture exceptions that happen in your code.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` | `None`
+`level` | `Optional[str]` | The `$exception_level`, such as `"warning"` or `"fatal"`. Defaults to `"error"`. An unknown value counts as unset. | `None`
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, disable_geoip, and options. Reserved exception properties in `properties`, such as `$exception_list` and `$exception_level`, are ignored. | `{}`
+
+
+Details
+
+Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the "traceback"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError("Some Error"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.
+
+
+
+**Examples:**
+
+```python
+# Capture exception
+from posthog import capture_exception
+try:
+ risky_operation()
+except Exception as e:
+ capture_exception(e)
+```
+
+### `posthog.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Use feature flags to enable or disable features for users.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.
+
+
+
+**Examples:**
+
+```python
+# Boolean feature flag
+from posthog import feature_enabled, get_feature_flag_payload
+is_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get feature flag variant for users. Used with experiments.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping from group type to group key | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties in format { group_type_name: { group_properties } } | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+`groups` are a mapping from group type to group key. So, if you have a group type of "organization" and a group key of "5", you would pass groups={"organization": "5"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type "organization" and the group key "5", with the properties name, and employee count, you'll send these as: group_properties={"organization": {"name": "PostHog", "employees": 11}}.
+
+
+
+**Examples:**
+
+```python
+# Multivariate feature flag
+from posthog import get_feature_flag, get_feature_flag_payload
+enabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key':
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> Optional[dict[str, FlagValue]]
+```
+
+Get all flags for a given user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate (evaluates all if None) | `None`
+
+
+Details
+
+Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.
+
+
+
+**Examples:**
+
+```python
+# All flags for user
+from posthog import get_all_flags
+get_all_flags('distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload.
+
+This method evaluates a feature flag and returns a FeatureFlagResult object containing:
+- enabled: Whether the flag is enabled
+- variant: The variant value if the flag has variants
+- payload: The payload associated with the flag (automatically deserialized from JSON)
+- key: The flag key
+- reason: Why the flag was enabled/disabled
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+Example:
+```python
+result = posthog.get_feature_flag_result('beta-feature', 'distinct_id')
+if result and result.enabled:
+ # Use the variant and payload
+ print(f"Variant: {result.variant}")
+ print(f"Payload: {result.payload}")
+```
+
+### `posthog.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload associated with a feature flag value.
+
+Deprecated for new code. Prefer `evaluate_flags()` and
+`flags.get_flag_payload(key)` so flag evaluation happens once per request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`match_value` | `Optional[FlagValue]` | Optional flag value to use when selecting a payload. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This function returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+### `posthog.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The key of the feature flag | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag. If payload is encrypted, the return value will be decrypted
+
+
+Note
+
+Requires secret_key to be set for authentication
+
+
+
+### `posthog.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> FlagsAndPayloads
+```
+
+Get all feature flag values and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate. Evaluates all flags when omitted. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FlagsAndPayloads` | A dict with `featureFlags` and `featureFlagPayloads` entries.
+
+### `posthog.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture()` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If `True`, never fall back to remote evaluation and omit flags that cannot be evaluated locally. The snapshot's `unresolved_flags` lists them with a reason. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[list[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is `True`. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Examples:**
+
+```python
+from posthog import evaluate_flags, capture
+flags = evaluate_flags("user_123", person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+### `posthog.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Returns loaded feature flags.
+
+
+Details
+
+Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.
+
+
+
+**Examples:**
+
+```python
+from posthog import feature_flag_definitions
+definitions = feature_flag_definitions()
+```
+
+### `posthog.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+
+Details
+
+Reads the `evaluation_runtime` each flag definition carries, so no extra
+request is made. Returns `None` when local evaluation has not loaded a
+definition for this key. A definition that carries no runtime reports
+`FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_evaluation_runtime
+runtime = get_feature_flag_evaluation_runtime("my-flag")
+```
+
+### `posthog.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+
+Details
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime, so
+it is returned for `CLIENT` and for `SERVER`. Use this to decide which
+flags to hand to a browser when a backend serves flags to its own
+frontend.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_keys_by_evaluation_runtime
+client_keys = get_feature_flag_keys_by_evaluation_runtime(FeatureFlagEvaluationRuntime.CLIENT)
+```
+
+### `posthog.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flag definitions from PostHog.
+
+**Examples:**
+
+```python
+from posthog import load_feature_flags
+load_feature_flags()
+```
+
+### `posthog.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events and ended spans, keeping the global client reusable.
+
+Call `flush()` before a short-lived request or serverless invocation returns
+when using the shared module-level client. Use `shutdown()` only for final
+process cleanup or a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after a
+timeout or span export failure, and failed events may be dropped by consumers.
+Calls made directly from SDK callbacks such as `on_error` are deferred
+rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently, waiting up to this many seconds for an in-flight flush before starting a fresh drain budget. A lock wait timeout leaves the in-flight flush to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. The last span request is not cut short and is bounded by the client's `timeout` in seconds, so this is not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+import posthog
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the global client open.
+posthog.flush(timeout_seconds=10)
+```
+
+### `posthog.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and stop the client's background workers. Use `shutdown()` directly in most cases.
+
+Failed or undrainable events may be dropped and reported through logging or
+`on_error`; returning does not guarantee server receipt. Lifecycle cleanup
+is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+from posthog import join
+join()
+```
+
+### `posthog.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime.datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on the
+way out); or call `end()` yourself for a span that cannot wrap a block.
+Spans started inside the block nest under it automatically. Always returns
+a usable handle, even when tracing is off, so calling code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+import posthog
+posthog.traces = {"service_name": "checkout-api"}
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `posthog.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes it
+active; a span started manually is not. Use it to propagate the trace to
+the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+### `posthog.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the global client.
+
+Call this for final process cleanup, not at the end of each request or
+serverless invocation that shares the module-level client. Use `flush()`
+before returning from those invocations instead. Shutdown closes capture
+lanes, stops background workers and the feature flag poller, and tears down
+integrations. The global client is not recreated automatically after shutdown.
+
+This normally blocks until queued events have been attempted and cleanup
+finishes. Failed or undrainable events may be dropped and reported through
+logging or `on_error`; returning does not guarantee server receipt. Event
+draining has no timeout. Queued spans get a final flush with up to 30 seconds
+waiting for an in-flight flush, then a fresh 30-second drain budget; the last
+HTTP request is not cut short. Unsent queued spans and still-open spans are
+discarded with a warning.
+Lifecycle cleanup is attempted once, and cleanup failures are logged without
+retry. Calls made directly from SDK callbacks such as `on_error` are deferred
+to avoid deadlocking the worker. If blocking completion is required, signal an application-owned
+thread, return from the callback, and call `shutdown()` from that thread.
+Do not wait inside a callback for another thread or task calling a lifecycle
+method.
+
+**Examples:**
+
+```python
+from posthog import shutdown
+shutdown()
+```
+
+### `posthog.setup`
+
+```python
+setup() -> Client
+```
+
+Create or return the global PostHog client configured by module settings.
+
+Most applications should either instantiate `Posthog` directly or set
+`posthog.api_key`/other module settings before calling top-level helpers.
+`setup()` is called automatically by global APIs such as `capture()`.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Client` | The global `Client` instance. If both `api_key` and `project_api_key` are missing or blank, the client is disabled and module-level calls become no-ops.
+
+## Types
+
+### `OptionalCaptureArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the capture method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the person associated with this event. If not set, the context distinct_id is used, if available, otherwise a UUID is generated, and the event is marked as personless. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to track with the event |
+`timestamp` | | When the event occurred (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this specific event. If not provided, one is generated. The event UUID is returned, so you can correlate it with actions in your app (like showing users an error ID if you capture an exception). If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | Group identifiers to associate with this event (format: {group_type: group_key}) |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. The exact flag values from the snapshot are attached to the event with no additional network call — prefer this over `send_feature_flags`. |
+`send_feature_flags` | | Deprecated — prefer `flags` with a `FeatureFlagEvaluations` snapshot. Whether to include currently active feature flags in the event properties. Can be a boolean or a SendFeatureFlagsOptions object. Defaults to False. Fires a hidden `/flags` request on capture and may return different values than the ones the code branched on. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this event. Defaults to False. |
+`options` | | Capture options for this event, such as `{"process_person_profile": False}`. Sent as given, for PostHog to validate. An option wins over its legacy `$` property, such as `$process_person_profile`. A value that is not a dict is logged and ignored. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`flags` | `NotRequired[Optional[FeatureFlagEvaluations]]` |
+`groups` | `NotRequired[Optional[Dict[str, str]]]` |
+`options` | `NotRequired[Optional[Dict[str, Any]]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`send_feature_flags` | `NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalCaptureArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.flags`
+
+```python
+flags: NotRequired[Optional[FeatureFlagEvaluations]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.groups`
+
+```python
+groups: NotRequired[Optional[Dict[str, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.options`
+
+```python
+options: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.send_feature_flags`
+
+```python
+send_feature_flags: NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `FeatureFlagEvaluations`
+
+```python
+FeatureFlagEvaluations(host: _FeatureFlagEvaluationsHost, distinct_id: str, flags: Dict[str, _EvaluatedFlagRecord], groups: Optional[Mapping[str, Union[str, int]]] = None, disable_geoip: Optional[bool] = None, request_id: Optional[str] = None, evaluated_at: Optional[int] = None, errors_while_computing: bool = False, quota_limited: bool = False, minimal_flag_called_events: bool = False, accessed: Optional[Set[str]] = None, unresolved_flags: Optional[Mapping[str, UnresolvedFlagReason]] = None) -> None
+```
+
+A point-in-time snapshot of feature flag evaluations for a single distinct_id.
+
+Returned by `Client.evaluate_flags` — branch on `is_enabled` /
+`get_flag` and pass the same object to `Client.capture` via the
+`flags` option so the captured event carries the exact flag values the code
+branched on.
+
+```python
+flags = posthog.evaluate_flags(distinct_id, person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id=distinct_id, flags=flags)
+```
+
+To narrow the set of flags that get attached to a captured event, use the in-memory
+helpers `only` and `only_accessed`. To narrow the set of flags requested
+from the server in the first place, pass `flag_keys` to `Client.evaluate_flags`.
+
+Reading a flag sends `$feature_flag_called`, deduplicated as `is_enabled`
+describes. When the flag was evaluated remotely and its config version 2 record is
+a complete experiment split (an experiment rule with a rule ID and a variant key),
+the read also sends `$experiment_exposure`. The SDK sends one exposure per
+distinct ID, groups, flag, rule and variant. `send_feature_flag_events=False`
+suppresses both events.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`get_flag` | Return the flag value. Fires `$feature_flag_called` on first access.
+`get_flag_payload` | Return the payload associated with a flag.
+`is_enabled` | Return whether the flag is enabled. Fires `$feature_flag_called` on the first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+`only` | Return a filtered copy containing only flags with the given keys. Keys that are not present in the evaluation are dropped and logged as a warning.
+`only_accessed` | Return a filtered copy containing only flags accessed via `is_enabled` or `get_flag` before this call.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`keys` | `List[str]` | Return the flag keys that are part of this evaluation.
+`unresolved_flags` | `Mapping[str, UnresolvedFlagReason]` | Return a read-only mapping of flag key to the reason local evaluation left it without a value.
+
+Internal — instances are created by the SDK via `Client.evaluate_flags()`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag`
+
+```python
+get_flag(key: str, *, send_feature_flag_events: bool = True) -> Optional[FlagValue]
+```
+
+Return the flag value. Fires `$feature_flag_called` on first access.
+
+Returns the variant string for multivariate flags, `True` for enabled flags
+without a variant, `False` for disabled flags, and `None` for flags that
+were not returned by the evaluation.
+
+Pass `send_feature_flag_events=False` to skip the event for this read, as
+with `is_enabled`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag_payload`
+
+```python
+get_flag_payload(key: str) -> Optional[Any]
+```
+
+Return the payload associated with a flag.
+
+Does not count as an access for `only_accessed` and does not fire any event.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.is_enabled`
+
+```python
+is_enabled(key: str, default_value: bool = False, *, send_feature_flag_events: bool = True) -> bool
+```
+
+Return whether the flag is enabled. Fires `$feature_flag_called` on the
+first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`default_value` | `bool` | Returned when the flag has no value in this evaluation — the key was not part of the evaluated set, or the evaluation itself came back empty (failed `/flags` request, quota limit, or no resolvable `distinct_id`). Defaults to `False`. | `False`
+`send_feature_flag_events` | `bool` | Whether this read sends `$feature_flag_called`. When `False`, no event is sent and the dedupe cache is left alone, but the key still counts as accessed for `only_accessed`. | `True`
+
+A flag that has a value always wins over `default_value`, including a
+disabled flag, which returns `False` even when `default_value=True`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.keys`
+
+```python
+keys: List[str]
+```
+
+Return the flag keys that are part of this evaluation.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only`
+
+```python
+only(keys: List[str]) -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags with the given keys. Keys that
+are not present in the evaluation are dropped and logged as a warning.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only_accessed`
+
+```python
+only_accessed() -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags accessed via `is_enabled`
+or `get_flag` before this call.
+
+Order-dependent: if nothing has been accessed yet, the returned snapshot is
+empty. The method honors its name — pre-access if you want a populated result.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.unresolved_flags`
+
+```python
+unresolved_flags: Mapping[str, UnresolvedFlagReason]
+```
+
+Return a read-only mapping of flag key to the reason local evaluation
+left it without a value.
+
+A flag is listed when it has a loaded local definition, was in the requested
+scope, was inconclusive locally, and no remote value filled the gap. Listed
+flags are not part of `keys`, and reading one reports the
+`local_evaluation_inconclusive` error instead of `flag_missing`. Reading
+this mapping does not count as an access and does not fire any event.
+Snapshots returned by `only` and `only_accessed`, and by
+`AsyncClient.evaluate_flags()`, which evaluates only remotely, carry no
+entries.
+
+### `FeatureFlagResult`
+
+```python
+FeatureFlagResult(key: str, enabled: bool, variant: Optional[str], payload: Optional[Any], reason: Optional[str]) -> None
+```
+
+The result of calling a feature flag which includes the flag result, variant, and payload.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | The unique identifier of the feature flag.
+`enabled` | `bool` | Whether the feature flag is enabled for the current context.
+`variant` | `Optional[str]` | The variant value if the flag is enabled and has variants, None otherwise.
+`payload` | `Optional[Any]` | Additional data associated with the feature flag, if any.
+`reason` | `Optional[str]` | A description of why the flag was enabled or disabled, if available.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_flag_details` | Create a FeatureFlagResult from a FeatureFlag object.
+`from_value_and_payload` | Creates a FeatureFlagResult from a flag value and payload.
+`get_value` | Returns the value of the flag. This is the variant if it exists, otherwise the enabled value. This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+#### `posthog.types.FeatureFlagResult.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlagResult.from_flag_details`
+
+```python
+from_flag_details(details: Union[FeatureFlag, None], override_match_value: Optional[FlagValue] = None) -> FeatureFlagResult | None
+```
+
+Create a FeatureFlagResult from a FeatureFlag object.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`details` | `Union[FeatureFlag, None]` | The FeatureFlag object to convert. | *required*
+`override_match_value` | `Optional[FlagValue]` | If provided, this value will be used to populate the enabled and variant fields instead of the values from the FeatureFlag. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagResult \| None` | FeatureFlagResult | None: A new FeatureFlagResult instance, or None if details is None.
+
+#### `posthog.types.FeatureFlagResult.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: Union[FlagValue, None], payload: Any) -> Union[FeatureFlagResult, None]
+```
+
+Creates a FeatureFlagResult from a flag value and payload.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The unique identifier of the feature flag. | *required*
+`value` | `Union[FlagValue, None]` | The value of the flag (string variant or boolean). | *required*
+`payload` | `Any` | Additional data associated with the feature flag. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Union[FeatureFlagResult, None]` | Union[FeatureFlagResult, None]: A new FeatureFlagResult instance, or None if value is None.
+
+#### `posthog.types.FeatureFlagResult.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Returns the value of the flag. This is the variant if it exists, otherwise the enabled value.
+This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+**Returns:**
+
+Name | Type | Description
+---- | ---- | -----------
+`FlagValue` | `FlagValue` | Either a string variant or boolean value representing the flag's state.
+
+#### `posthog.types.FeatureFlagResult.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlagResult.payload`
+
+```python
+payload: Optional[Any]
+```
+
+#### `posthog.types.FeatureFlagResult.reason`
+
+```python
+reason: Optional[str]
+```
+
+#### `posthog.types.FeatureFlagResult.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FeatureFlag`
+
+```python
+FeatureFlag(key: str, enabled: bool, variant: Optional[str], reason: Optional[FlagReason], metadata: Union[FlagMetadata, LegacyFlagMetadata]) -> None
+```
+
+Detailed feature flag evaluation returned by the flags API.
+
+`enabled`, `variant` and `metadata.payload` are the value rendered the way
+responses before `/flags?v=4` carried it, which the legacy getters return.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | Feature flag key.
+`enabled` | `bool` | Whether the flag is enabled for the evaluated user or group.
+`variant` | `Optional[str]` | Variant key for multivariate flags, otherwise `None`.
+`reason` | `Optional[FlagReason]` | Optional reason metadata explaining the result.
+`metadata` | `Union[FlagMetadata, LegacyFlagMetadata]` | Payload and other metadata returned by the API.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_json` | Parse one flag record of a `/flags` response.
+`from_value_and_payload` | Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+`get_value` | Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlag.from_json`
+
+```python
+from_json(resp: Any) -> FeatureFlag
+```
+
+Parse one flag record of a `/flags` response.
+
+A record with a `value` member is a `/flags?v=4` record. A record
+without one comes from an older server: its value is `variant`, or
+`enabled` when there is no variant, and its config version is `1`.
+
+#### `posthog.types.FeatureFlag.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: FlagValue, payload: Any) -> FeatureFlag
+```
+
+Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+
+#### `posthog.types.FeatureFlag.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlag.metadata`
+
+```python
+metadata: Union[FlagMetadata, LegacyFlagMetadata]
+```
+
+#### `posthog.types.FeatureFlag.reason`
+
+```python
+reason: Optional[FlagReason]
+```
+
+#### `posthog.types.FeatureFlag.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FlagsAndPayloads`
+
+Bases: `TypedDict`
+
+Feature flag values and payloads keyed by feature flag key.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`featureFlags` | `Optional[dict[str, FlagValue]]` | Each flag's value, keyed by flag key.
+`featureFlagPayloads` | `Optional[dict[str, Any]]` | Each flag's payload, keyed by flag key.
+
+#### `posthog.types.FlagsAndPayloads.featureFlagPayloads`
+
+```python
+featureFlagPayloads: Optional[dict[str, Any]]
+```
+
+#### `posthog.types.FlagsAndPayloads.featureFlags`
+
+```python
+featureFlags: Optional[dict[str, FlagValue]]
+```
+
+### `UnresolvedFlagReason`
+
+Bases: `str`, `Enum`
+
+Why local evaluation left a flag without a value.
+
+Reported by `FeatureFlagEvaluations.unresolved_flags`. Inheriting from
+`str` keeps the members directly comparable to their string values. When more
+than 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, 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.
+
+
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`EXPERIENCE_CONTINUITY` | |
+`MISSING_CONTEXT` | |
+`UNRESOLVED_DEPENDENCY` | |
+`UNSUPPORTED_DEFINITION` | |
+
+#### `posthog.types.UnresolvedFlagReason.EXPERIENCE_CONTINUITY`
+
+```python
+EXPERIENCE_CONTINUITY = 'experience_continuity'
+```
+
+#### `posthog.types.UnresolvedFlagReason.MISSING_CONTEXT`
+
+```python
+MISSING_CONTEXT = 'missing_context'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNRESOLVED_DEPENDENCY`
+
+```python
+UNRESOLVED_DEPENDENCY = 'unresolved_dependency'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNSUPPORTED_DEFINITION`
+
+```python
+UNSUPPORTED_DEFINITION = 'unsupported_definition'
+```
+
+### `InconclusiveMatchError`
+
+```python
+InconclusiveMatchError(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when local evaluation can't determine a flag's value. `reason` says
+why, as reported by `FeatureFlagEvaluations.unresolved_flags`.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why local evaluation couldn't resolve the flag.
+
+#### `posthog.feature_flags.InconclusiveMatchError.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `RequiresServerEvaluation`
+
+```python
+RequiresServerEvaluation(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when feature flag evaluation requires server-side data that is not
+available locally (e.g., static cohorts).
+
+This error should propagate immediately to trigger API fallback, unlike
+InconclusiveMatchError which allows trying other conditions.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why the flag needs server-side evaluation.
+
+#### `posthog.feature_flags.RequiresServerEvaluation.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `CaptureError`
+
+```python
+CaptureError(status: int | str, message: str, *, endpoint: str, retry_after: Optional[float] = None, request_id: Optional[str] = None, attempts: Optional[int] = None, retry_exhausted: Optional[list[str]] = None, drops: Optional[list[tuple[str, Optional[str]]]] = None, event_results: Optional[dict[str, CaptureEventResult]] = None)
+```
+
+Bases: `APIError`
+
+A capture batch that was not fully delivered.
+
+Passed to `on_error` with the batch. `status` is the HTTP status of the
+last attempt, or `0` when no response arrived (`__cause__` holds the
+transport error). A 2xx `status` means the request succeeded but some
+events were dropped or ran out of retries.
+
+`event_results` maps each event uuid to its last verdict from a 2xx
+response. Events missing from it never got a verdict, because every
+attempt that reached them failed as a whole request.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`verdict_summary` | Count the undelivered events by verdict and reason, for example `drop/llm_events_over_quota=2, retry/not_persisted=1`.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`attempts` | |
+`drops` | |
+`endpoint` | |
+`event_results` | |
+`message` | |
+`request_id` | |
+`retry_after` | |
+`retry_exhausted` | |
+`status` | |
+
+#### `posthog.capture_send.CaptureError.attempts`
+
+```python
+attempts = attempts
+```
+
+#### `posthog.capture_send.CaptureError.drops`
+
+```python
+drops = drops or []
+```
+
+#### `posthog.capture_send.CaptureError.endpoint`
+
+```python
+endpoint = endpoint
+```
+
+#### `posthog.capture_send.CaptureError.event_results`
+
+```python
+event_results = event_results or {}
+```
+
+#### `posthog.capture_send.CaptureError.message`
+
+```python
+message = message
+```
+
+#### `posthog.capture_send.CaptureError.request_id`
+
+```python
+request_id = request_id
+```
+
+#### `posthog.capture_send.CaptureError.retry_after`
+
+```python
+retry_after = retry_after
+```
+
+#### `posthog.capture_send.CaptureError.retry_exhausted`
+
+```python
+retry_exhausted = retry_exhausted or []
+```
+
+#### `posthog.capture_send.CaptureError.status`
+
+```python
+status = status
+```
+
+#### `posthog.capture_send.CaptureError.verdict_summary`
+
+```python
+verdict_summary() -> str
+```
+
+Count the undelivered events by verdict and reason, for example
+`drop/llm_events_over_quota=2, retry/not_persisted=1`.
+
+Counts the events in `drops` and `retry_exhausted`: events the
+server dropped, and events still pending retry after the last 2xx
+response. A retry verdict followed by a failed request, for example a
+503 on the last attempt, is not counted; `event_results` keeps it.
+Empty when no event is counted.
+
+### `Span`
+
+A handle to a span.
+
+Every method is safe to call on any handle, including after `end()` and
+on the inert handles returned when tracing is off, so calling code never
+branches on whether tracing is running. Entering a handle (`with span:`)
+makes it the active span for the block and ends it on exit, recording an
+`Exception` raised inside it. A `BaseException` that is not an
+`Exception` (`GeneratorExit`, `CancelledError`, `KeyboardInterrupt`)
+still ends the span but is not recorded as a failure.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`add_event` | Add a timestamped event to the span. Ignored after `end()`.
+`end` | End the span and queue it for export. Idempotent.
+`record_exception` | Record an exception as an `exception` event and mark the span `error`.
+`set_attribute` | Set one attribute on the span; last write wins. Ignored after `end()`.
+`set_attributes` | Set several attributes at once; last write wins per key. Ignored after `end()`.
+`set_status` | Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+`traceparent` | The W3C `traceparent` header value to propagate, or `None`.
+`tracestate` | The W3C `tracestate` header value to propagate, or `None`.
+`update_name` | Rename the span, for a name only known after it started. Ignored after `end()`.
+
+#### `posthog.tracing.span.Span.add_event`
+
+```python
+add_event(name: str, attributes: Optional[Mapping[str, Any]] = None, timestamp: Union[datetime, float, None] = None) -> Span
+```
+
+Add a timestamped event to the span. Ignored after `end()`.
+
+`timestamp` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`. Returns the span, so calls
+chain.
+
+**Examples:**
+
+```python
+span.add_event("cache.miss", {"key": "user:42"})
+```
+
+#### `posthog.tracing.span.Span.end`
+
+```python
+end(end_time: Union[datetime, float, None] = None) -> None
+```
+
+End the span and queue it for export. Idempotent.
+
+`end_time` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`, and is never earlier than
+the start. Later calls, and later mutations, no-op. `with span:`
+ends the span on exit, so call this only for spans started manually.
+
+**Examples:**
+
+```python
+span = posthog.start_span("job")
+try:
+ run_job()
+finally:
+ span.end()
+```
+
+#### `posthog.tracing.span.Span.record_exception`
+
+```python
+record_exception(exception: BaseException) -> Span
+```
+
+Record an exception as an `exception` event and mark the span `error`.
+
+Ignored after `end()`. The event carries `exception.type`,
+`exception.message` and, for a raised exception,
+`exception.stacktrace` (its last `max_attribute_value_length`
+characters, so a chained traceback keeps the outermost exception and
+may lose its cause). Returns the span, so calls chain. Inside
+`with span:` a raised `Exception` is recorded automatically, so
+this is for exceptions that are caught and handled.
+
+**Examples:**
+
+```python
+try:
+ charge(card)
+except PaymentError as e:
+ span.record_exception(e)
+```
+
+#### `posthog.tracing.span.Span.set_attribute`
+
+```python
+set_attribute(key: str, value: Any) -> Span
+```
+
+Set one attribute on the span; last write wins. Ignored after `end()`.
+
+Returns the span, so calls chain. Prefer primitive values: strings,
+booleans, integers and floats keep their type. Lists and mappings are
+sent as OTLP arrays and maps, but PostHog stores them as serialized
+strings. `None` removes the key; anything else is stringified.
+
+**Examples:**
+
+```python
+span.set_attribute("http.status_code", 200).set_attribute("cache.hit", True)
+```
+
+#### `posthog.tracing.span.Span.set_attributes`
+
+```python
+set_attributes(attributes: Mapping[str, Any]) -> Span
+```
+
+Set several attributes at once; last write wins per key. Ignored after `end()`.
+
+Returns the span, so calls chain. Same encoding as `set_attribute()`.
+
+**Examples:**
+
+```python
+span.set_attributes({"db.system": "postgresql", "db.rows": 12})
+```
+
+#### `posthog.tracing.span.Span.set_status`
+
+```python
+set_status(code: str, message: Optional[str] = None) -> Span
+```
+
+Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+
+Unset by default. Any other `code` is ignored. `ok` is final for the
+scoped form: an `Exception` raised inside `with span:` does not override
+it. Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span.set_status("error", "upstream timed out")
+```
+
+#### `posthog.tracing.span.Span.traceparent`
+
+```python
+traceparent() -> Optional[str]
+```
+
+The W3C `traceparent` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.tracestate`
+
+```python
+tracestate() -> Optional[str]
+```
+
+The W3C `tracestate` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.update_name`
+
+```python
+update_name(name: str) -> Span
+```
+
+Rename the span, for a name only known after it started. Ignored after `end()`.
+
+Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span = posthog.start_span("http.request")
+span.update_name(f"{request.method} {route.pattern}")
+```
+
+### `Emails`
+
+```python
+Emails(secret_key: Optional[str], *, host: Optional[str] = None, timeout: float = 15, max_retries: int = 2, disabled: bool = False, session: Optional[requests.Session] = None, migrated_from: Optional[str] = None) -> None
+```
+
+Bases: `_EmailsBase`
+
+Sends transactional email from PostHog email templates or from content in your code.
+
+`host` is your PostHog app host. PostHog Cloud ingestion hosts map to the
+app host, so `us.i.posthog.com` sends to `us.posthog.com`. Any other
+host is used as given.
+
+Each send retries network errors, rate limits and an unavailable service up
+to `max_retries` times, with the same idempotency key. Set
+`max_retries=0` when a job runner already retries the send. `timeout`
+is in seconds, per request. Pass `session` to send through your own
+`requests.Session`, for example a test double. `migrated_from`, such
+as `"resend"`, tells PostHog which provider your sends came from.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`close` | Close the HTTP connections this client opened. A `session` you passed in stays open.
+`get` | Read what happened to an email that `send` queued.
+`send` | Queue one email, from a template in PostHog or from content in your code.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disabled` | |
+`host` | |
+`max_retries` | |
+`migrated_from` | |
+`secret_key` | |
+`timeout` | |
+
+#### `posthog.emails.Emails.close`
+
+```python
+close() -> None
+```
+
+Close the HTTP connections this client opened. A `session` you passed in stays open.
+
+#### `posthog.emails.Emails.disabled`
+
+```python
+disabled = disabled
+```
+
+#### `posthog.emails.Emails.get`
+
+```python
+get(message_id: Union[str, UUID]) -> EmailStatus
+```
+
+Read what happened to an email that `send` queued.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`message_id` | `Union[str, UUID]` | The `id` of the `SendEmailResult` that `send` returned. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`EmailStatus` | The email's latest status, for 30 days after the send.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not answer with a status. `code` is `not_found` for an unknown ID, an email older than 30 days, or for a few seconds after the send.
+`ValueError` | `message_id` is not a message ID.
+
+**Examples:**
+
+```python
+result = emails.send(to="user@example.com", template_id="...")
+status = emails.get(result.id)
+if status.status == "bounced":
+ print(status.reason)
+```
+
+#### `posthog.emails.Emails.host`
+
+```python
+host = determine_app_host(host)
+```
+
+#### `posthog.emails.Emails.max_retries`
+
+```python
+max_retries = max_retries
+```
+
+#### `posthog.emails.Emails.migrated_from`
+
+```python
+migrated_from = migrated_from
+```
+
+#### `posthog.emails.Emails.secret_key`
+
+```python
+secret_key = secret_key.strip() if isinstance(secret_key, str) else None
+```
+
+#### `posthog.emails.Emails.send`
+
+```python
+send(**kwargs: Any) -> SendEmailResult
+```
+
+Queue one email, from a template in PostHog or from content in your code.
+
+Pass exactly one form. The template form names a template made in
+PostHog with `template_id`. The code form names the email with
+`template_key` and passes `subject` and `html`, `text` or both:
+see `CodeEmailArgs`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_id` | | The UUID of a template made transactional in PostHog. |
+`template_data` | | Values for the template's `{{ variables.* }}` placeholders. Values are encoded the way capture encodes properties. |
+`distinct_id` | | The recipient's distinct ID in your product. The email's events go to this person. Without it, they go to a person whose distinct ID is the email address. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. A send with a key that PostHog has already accepted queues nothing and returns the first send's result. Without it, the client makes a key that covers its own retries. Pass a key derived from what the email is for, such as `welcome:user_123`, to cover retries outside this call, too. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`SendEmailResult` | The queued email. A result means PostHog queued the email, not that it was delivered.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not queue the email, or the client could not tell whether it did.
+`(TypeError, ValueError)` | An argument has the wrong type or format.
+
+**Examples:**
+
+```python
+emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+ idempotency_key="welcome:user_123",
+)
+emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ distinct_id="user_123",
+)
+```
+
+#### `posthog.emails.Emails.timeout`
+
+```python
+timeout = timeout
+```
+
+### `EmailError`
+
+```python
+EmailError(*, name: str, code: str, message: str, status_code: Optional[int] = None, why: Optional[str] = None, fix: Optional[str] = None, docs_url: Optional[str] = None, field: Optional[str] = None, retry_after: Optional[float] = None) -> None
+```
+
+Bases: `Exception`
+
+PostHog did not queue the email, or the client could not tell whether it did.
+
+Branch on `code`, PostHog's stable error code, or on `name`, a coarse
+category of the failure. The message never contains the secret key or the
+request body.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`name` | | A coarse category of the failure.
+`code` | | PostHog's stable error code.
+`message` | | What went wrong. It never contains the secret key or the request body.
+`status_code` | | The HTTP status of the response, or `None` when none arrived.
+`why` | | PostHog's explanation of the failure, when it gave one.
+`fix` | | What to change to fix it, when PostHog said.
+`docs_url` | | A docs page about the error, when PostHog gave one.
+`field` | | The request field the error is about, when there is one.
+`retry_after` | | Seconds to wait before retrying, when PostHog said.
+
+#### `posthog.emails.EmailError.code`
+
+```python
+code = code
+```
+
+#### `posthog.emails.EmailError.docs_url`
+
+```python
+docs_url = docs_url
+```
+
+#### `posthog.emails.EmailError.field`
+
+```python
+field = field
+```
+
+#### `posthog.emails.EmailError.fix`
+
+```python
+fix = fix
+```
+
+#### `posthog.emails.EmailError.message`
+
+```python
+message = message
+```
+
+#### `posthog.emails.EmailError.name`
+
+```python
+name = name
+```
+
+#### `posthog.emails.EmailError.retry_after`
+
+```python
+retry_after = retry_after
+```
+
+#### `posthog.emails.EmailError.status_code`
+
+```python
+status_code = status_code
+```
+
+#### `posthog.emails.EmailError.why`
+
+```python
+why = why
+```
+
+### `SendEmailResult`
+
+```python
+SendEmailResult(id: str, replayed: bool = False, warnings: tuple[EmailWarning, ...] = ()) -> None
+```
+
+The queued email. `id` is its message ID.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`id` | `str` | The email's message ID.
+`replayed` | `bool` | `True` when the response says PostHog replayed an earlier send for the same `idempotency_key` instead of sending again.
+`warnings` | `tuple[EmailWarning, ...]` | Warnings PostHog returned about the request.
+
+#### `posthog.emails.SendEmailResult.id`
+
+```python
+id: str
+```
+
+#### `posthog.emails.SendEmailResult.replayed`
+
+```python
+replayed: bool = False
+```
+
+#### `posthog.emails.SendEmailResult.warnings`
+
+```python
+warnings: tuple[EmailWarning, ...] = ()
+```
+
+### `OptionalSetArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the set method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the user to set properties on. If not set, the context distinct_id is used, if available, otherwise this function does nothing. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to set on the person |
+`timestamp` | | When the properties were set (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this operation. If not provided, one is generated. This UUID is returned, so you can correlate it with actions in your app. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this operation. Defaults to False. |
+`options` | | Capture options for this event, sent as given. See `OptionalCaptureArgs`. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`options` | `NotRequired[Optional[Dict[str, Any]]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalSetArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalSetArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalSetArgs.options`
+
+```python
+options: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalSetArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalSetArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalSetArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `CodeEmailArgs`
+
+Bases: `_RecipientArgs`
+
+A send of email content that your code rendered for one recipient, named by a key.
+
+The content goes out as is. To send a React email, render it to HTML in
+your app first.
+
+An optional field passed as `None` counts as left out.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_key` | | Names the email, so its metrics, logs and status group under it. Letters, digits, `-` and `_`, at most 400. |
+`subject` | | The subject line. |
+`html` | | The HTML body. Give `html`, `text` or both. |
+`text` | | The plain-text body. Without it, PostHog derives it from `html`. HTML with no text in it, such as a single image, goes out without a plain-text part. |
+`from_` | | A verified sender, such as `"Acme "`. |
+`reply_to` | | One address or a list of addresses. An empty list sends no reply-to. |
+`capture_engagement` | | Capture the email's opens and clicks as events of the recipient. Defaults to `True`. A project whose admin turned engagement capture off captures nothing, whatever the send asks. A template made in PostHog follows the project's setting, so the template form doesn't take it. |
+`distinct_id` | | The recipient's distinct ID in your product. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. Template sends and code sends share one set of keys: a key already used for another email, or for a `template_id` send, raises `idempotency_key_reused`. A retry with the same key returns the first send's result, also when its workflow was paused since. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_engagement` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[str]]` |
+`from_` | `NotRequired[Optional[str]]` |
+`html` | `NotRequired[Optional[str]]` |
+`idempotency_key` | `NotRequired[Optional[str]]` |
+`max_retries` | `NotRequired[Optional[int]]` |
+`reply_to` | `NotRequired[Optional[Union[str, Sequence[str]]]]` |
+`subject` | `str` |
+`template_key` | `str` |
+`text` | `NotRequired[Optional[str]]` |
+`to` | `str` |
+
+#### `posthog.emails.CodeEmailArgs.capture_engagement`
+
+```python
+capture_engagement: NotRequired[Optional[bool]]
+```
+
+#### `posthog.emails.CodeEmailArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.from_`
+
+```python
+from_: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.html`
+
+```python
+html: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.idempotency_key`
+
+```python
+idempotency_key: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.max_retries`
+
+```python
+max_retries: NotRequired[Optional[int]]
+```
+
+#### `posthog.emails.CodeEmailArgs.reply_to`
+
+```python
+reply_to: NotRequired[Optional[Union[str, Sequence[str]]]]
+```
+
+#### `posthog.emails.CodeEmailArgs.subject`
+
+```python
+subject: str
+```
+
+#### `posthog.emails.CodeEmailArgs.template_key`
+
+```python
+template_key: str
+```
+
+#### `posthog.emails.CodeEmailArgs.text`
+
+```python
+text: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.to`
+
+```python
+to: str
+```
diff --git a/references/posthog-python-migration.md b/references/posthog-python-migration.md
new file mode 100644
index 000000000..628909bc8
--- /dev/null
+++ b/references/posthog-python-migration.md
@@ -0,0 +1,360 @@
+---
+title: PostHog Python SDK migration guides
+sidebar: Docs
+showTitle: true
+---
+
+# Migrating from posthog 7.x to 8.0
+
+posthog 8.0 sends every event through capture v1 and removes the legacy capture path.
+Most apps upgrade without code changes.
+Read the checklist first, then the sections that apply to you.
+
+For the changes every capture v1 SDK shares, such as event options, limits and per-event results, see [Upgrading to capture v1 SDKs](https://posthog.com/docs/libraries/capture-v1).
+
+## Checklist
+
+You need to change code if your app does any of these:
+
+- passes `Client` or `AsyncPosthog` constructor arguments by position after `host`
+- calls `posthog.request.post` or `posthog.request.flags` with positional arguments after `path` or `host`
+- sets `$exception_level` or another reserved exception property in `capture_exception(properties=...)`
+- sets `capture_mode`, `POSTHOG_CAPTURE_MODE` or `gzip`
+- imports `CaptureMode`, `posthog.capture_mode`, `CaptureV1Error`, `posthog.capture_v1`, `request.batch_post`, `EVENTS_ENDPOINT` or `AI_EVENTS_ENDPOINT`
+- sends events to a self-hosted PostHog that does not serve the capture v1 endpoints
+- sends events through a proxy that redirects capture requests to another host
+- reuses one event `uuid` for more than one event
+- expects `super_properties` to override properties passed to a single call, including `$set` and `$groups`
+- sets `$is_server`, `$geoip_disable` or a system property such as `$os` and expects the SDK's value to win
+- has a `before_send` hook that returns a new dict: copy `options`, or the event is sent without them, including the `process_person_profile=False` the SDK sets for events without a distinct ID (see [Event options](#event-options)). The same applies to MCP's `before_send` (see [MCP analytics](#mcp-analytics))
+- captures `$ai_` events with `capture()`: send them with `capture_ai()`
+- tests the AI integrations with a mock client and asserts on `capture`
+- passes its own client object to the AI integrations
+- sets `$lib` or `$lib_version` in a call's `properties`, a context tag or `super_properties`
+- filters insights or dashboards on `$lib = posthog-python-mcp`
+- passes a personal API key (`phx_...`) as the project API key
+- reads event content from the SDK's debug log
+- calls `alias()` without a `distinct_id` and relies on the context distinct ID
+- turns person processing off with `super_options`, `super_properties`, a context option or a context tag, and calls `alias`, `group_identify`, `set` or `set_once` (see [Identity and request context](#identity-and-request-context))
+- runs the Django, Flask or ASGI integration on 7.68 to 7.70 without tracing headers turned on (they are now read by default)
+
+## Endpoints
+
+| Method | Endpoint |
+| --- | --- |
+| `capture`, `set`, `set_once`, `alias`, `group_identify`, `capture_exception`, `AsyncPosthog.capture_immediate` | `/i/v1/analytics/events` |
+| `capture_ai`, `capture_ai_immediate`, and the AI wrapper integrations | `/i/v1/ai/events` |
+| OpenTelemetry (`posthog.ai.otel`) | `/i/v0/ai/otel`, unchanged |
+
+If you send events to a self-hosted PostHog, check that it serves both `/i/v1/analytics/events` and `/i/v1/ai/events` before you upgrade.
+Self-hosted PostHog serves the AI endpoint from a separate capture service, so check each route.
+An endpoint that is not served drops every event sent to it.
+
+If you send events through your own reverse proxy, update it before you upgrade:
+
+- Forward `/i/v1/analytics/events` and `/i/v1/ai/events` to PostHog.
+- Pass `Authorization` (the project token, sent as `Bearer `), every `PostHog-*` header, `Content-Type`, `Content-Encoding` and `User-Agent` through unchanged. PostHog answers `401` without `Authorization` and `400` without the others, and the batch fails.
+- Accept request bodies up to 20 MB. AI requests are often larger than 1 MB, the default limit in nginx and ingress-nginx. A `413` from the proxy fails the batch.
+
+PostHog's managed reverse proxy already does this. See the [proxy guides](https://posthog.com/docs/advanced/proxy).
+
+The SDK follows a `307` or `308` redirect only to the origin of `host` (same scheme, host and port), at most 5 times.
+Any other redirect fails the batch and reaches `on_error`.
+In 7.x the sync client followed redirects to any origin.
+If a proxy redirects capture requests to another host, point `host` at the final host.
+
+## SDK identity
+
+By default every event carries `$lib: "posthog-python"` and the installed package version in `$lib_version`.
+PostHog stores the values the event is sent with.
+
+You can set them in a call's `properties`, a context tag or `super_properties`. Like any other property, each one comes from the most specific place that sets it, so set both in the same place.
+`$lib` and `$lib_version` count as set only when they are non-empty strings.
+If you set `$lib` without `$lib_version`, the SDK adds its own version only when `$lib` is `posthog-python`.
+A `$lib_version` without a `$lib` is replaced with the SDK's.
+`before_send` sees both and can change or remove them.
+In 7.x the SDK overwrote a `$lib` or `$lib_version` set in a call or a context tag.
+
+This changes `super_properties` too:
+
+- `super_properties={"$lib": "my-lib"}` sends no `$lib_version`. In 7.x it sent the SDK version.
+- `super_properties={"$lib_version": "1.0"}` without a `$lib` sends the SDK's `$lib` and version. In 7.x it sent `1.0`.
+
+If an event reaches PostHog without `$lib`, PostHog fills both from the SDK name and version your request sends.
+If `$lib` is that SDK name and `$lib_version` is missing, empty or not a string, PostHog fills `$lib_version` the same way.
+
+MCP analytics events from `posthog.mcp.instrument()` or `PostHogMCP` report `posthog-python-mcp` and the installed package version.
+The integration sets both in each event's own properties, so neither a context tag nor `super_properties` replaces them. `before_send` can.
+In 7.x the MCP integration relabeled the whole client, or the default client when `instrument()` got none: the app's own events, the request headers and feature flag requests.
+In 8.0 those report `posthog-python`, so one client can serve both.
+
+Custom events from `PostHogMCP.capture()` now report `posthog-python`. In 7.x they reported `posthog-python-mcp`.
+Custom events from `McpAnalytics.capture()`, the handle `instrument()` returns, still report `posthog-python-mcp`.
+If an insight or dashboard filters on `$lib = posthog-python-mcp`, check that it still finds the events you expect.
+
+## Removed options and APIs
+
+| Removed | Use instead |
+| --- | --- |
+| `capture_mode`, `CaptureMode`, `POSTHOG_CAPTURE_MODE` | Nothing. Capture v1 is the only path. Setting `posthog.capture_mode` on the module has no effect. |
+| `gzip=True` | `capture_compression=CaptureCompression.GZIP`. The default is no compression. `POSTHOG_CAPTURE_COMPRESSION` still works. |
+| `CaptureV1Error` (`from posthog.capture_v1 import CaptureV1Error`) | `CaptureError` (`from posthog import CaptureError`). There is no alias. |
+| `posthog.capture_v1` | `posthog.capture_event` and `posthog.capture_send` |
+| `request.batch_post`, `async_batch_post`, `EVENTS_ENDPOINT`, `AI_EVENTS_ENDPOINT` | Nothing. Send events through a client. |
+| The `gzip` parameter of `request.post` and `request.flags` | Nothing. The parameters after `path` in `post` and after `host` in `flags` are keyword-only, so a 7.x call that passes them by position raises `TypeError`. A `gzip=` keyword raises no error: it is sent as a field in the request body. |
+| The `backoff` dependency | Add it to your own requirements if your code imports it. |
+
+The `posthoganalytics` package has the same changes. For example, import `CaptureError` from `posthoganalytics`.
+
+Constructor arguments after `host` are keyword-only:
+
+```python
+# 7.x
+Posthog("", "https://us.i.posthog.com", True)
+
+# 8.0
+Posthog("", host="https://us.i.posthog.com", debug=True)
+```
+
+## Errors and `on_error`
+
+Capture v1 returns a result for every event, even when the request succeeds.
+An event can be dropped inside a 2xx response, for example when it is over a product quota.
+8.0 reports those events as failures.
+When the whole request is over the billing limit, capture returns a `402` with no per-event results instead.
+
+- Every capture failure is a `CaptureError`, a subclass of `APIError`. It has these fields:
+ - `status`: the HTTP status, or `0` when the request never got a response. With `0`, `__cause__` holds the network error. In 7.x, `on_error` received the raw `requests` exception.
+ - `endpoint`, `request_id` and `attempts`
+ - `drops`: `(uuid, details)` pairs for the events capture dropped in a 2xx response
+ - `retry_exhausted`: the uuids still waiting for a retry after the last attempt
+ - `event_results`: a `CaptureEventResult(result, details)` for each uuid that got a result in a 2xx response, from `posthog.capture_send`. An event missing from it never got a result.
+ - `verdict_summary()`: counts such as `drop/llm_events_over_quota=1, retry/not_persisted=1`
+- `on_error(error, batch)` receives every failure, including in `sync_mode` and from `AsyncPosthog.capture_immediate`.
+- With `on_error` set, the SDK logs nothing for a failed batch.
+- Without `on_error`, the SDK logs one line per failed batch, for example `2 event(s) not persisted by /i/v1/analytics/events: ...`. The line never contains event content or the server's response text. After a 2xx response it also counts the lost events by PostHog's reason, for example `drop/event_too_big=1`.
+- The 7.x lines `error uploading: ...`, `async capture upload failed (...)` and `Immediate async capture failed (...)` are gone. In `sync_mode`, a failed request no longer logs the 7.x `Error in capture: ...` line, or the same line for another method. Update any log-based alerts that match these lines.
+- In `sync_mode`, a failed `capture()` calls `on_error` and returns `None`. With `debug=True` it calls `on_error` and then re-raises the error.
+- In `sync_mode`, a failed request is retried like a background batch, in the calling thread. With the default `max_retries` of 3, a call makes up to 4 attempts, and each attempt can take up to `timeout` (`capture_ai_timeout` for AI events). With the defaults, an analytics event whose requests keep timing out blocks the call for about a minute. 7.x made one attempt.
+- If a capture inside `on_error` fails, the SDK logs the failure and does not call `on_error` again.
+- The SDK retries `404`, `408`, `429`, `500`, `502`, `503` and `504` responses and network errors. Other error statuses fail the batch at once, including the other 5xx codes. 7.x retried `429` and every 5xx, but not `404`. Capture itself does not return `429`; a proxy in front of it can. A `404` that lasts through every attempt can mean the PostHog deployment has no capture v1 route, for example an older self-hosted install.
+- Each attempt makes one connection try. 7.x also retried a failed connection up to twice inside each attempt, so a capture request could block for up to three times the `timeout` per attempt.
+- Retries start at 100 ms and double each attempt, up to 30 seconds. Each wait varies randomly by up to 25%, so many clients do not retry at the same moment. A `Retry-After` header sets a minimum wait, up to 30 seconds. The `Consumer` default is 3 retries, down from 10. In 7.x the first retry waited up to 1 second.
+- The SDK's own log lines no longer contain event content: the debug line for a queued event names the event and the lane, and the invalid timestamp warning no longer includes the value. When your `before_send` hook raises, the error line names the event and the exception type, not the exception message, which can hold the data the hook was removing. The traceback is logged at debug level. To inspect events, use `before_send`.
+- A personal API key (`phx_...`) passed as the project API key disables the client and logs one error, as an empty key does. Capture rejects personal API keys, and the SDK no longer sends one with every request.
+
+## Invalid events
+
+Capture rejects a whole batch when one event cannot be parsed.
+8.0 drops only the invalid event, so the rest of the batch is delivered.
+
+- An event whose name is missing, `None`, empty or not a string is dropped. The SDK logs one warning per reason per process. 7.x sent it.
+- An event whose `before_send` hook sets `distinct_id` to `None` or a non-string is dropped, with one warning per reason per process. The SDK does not convert the hook's value or make up an ID. 7.x sent it, and capture would reject the whole batch.
+- PostHog drops an event whose name is over 200 UTF-8 bytes (`event_name_too_long`), and `on_error` reports it. 7.x sent events to legacy capture, which had no event name limit.
+- A `NaN` or infinite `float` value is sent as `null`, as in 7.75 and later, and the event is kept. Earlier 7.x versions sent invalid JSON, which made capture reject the whole batch. A `NaN` value in `$set` sets that person property to `null`.
+- An event that cannot be serialized to JSON, for example one with a circular reference, is dropped and logged. As in 7.x, a circular reference logs `Error in capture: maximum recursion depth exceeded` with a long traceback.
+- A property or option key that JSON cannot represent, such as a tuple, is dropped without a log, and the rest of the event is sent. 7.x dropped the event. `int`, finite `float`, `bool` and `None` keys are still converted to strings. A `NaN` or infinite `float` key still drops the event.
+
+## Event uuids
+
+- Each event needs its own uuid. Capture keeps the first event for each uuid in a request and drops the later copies. `on_error` reports each dropped copy in `CaptureError.drops` as `(uuid, "duplicate_event_uuid")`. 7.x sent every copy. Older PostHog versions reject the whole batch with a 400 `duplicate_event_uuid` instead.
+- The SDK accepts a uuid with hyphens, 32 hex digits, `{...}` braces or a `urn:uuid:` prefix, in any case. It sends the lowercase hyphenated form and returns that form from `capture`.
+- Any other value is replaced with a generated uuid, and the SDK logs one warning that names the rule, not the value. An empty string counts as unset, so the SDK generates a uuid without a warning. This applies to `AsyncPosthog` too.
+- Generated uuids are UUIDv7.
+
+## Session and window IDs
+
+Capture v1 sends `$session_id` and `$window_id` as top-level event fields, not as properties.
+The SDK moves them out of `properties` for you.
+
+- A string is sent as given, including `""`.
+- `None` counts as unset and is removed.
+- Any other value is removed and not sent, because capture would reject the whole batch. 7.x sent it as a property. The SDK logs a warning for each one, with the key and the value's type but not the value.
+
+## Identity and request context
+
+- An empty or whitespace-only `distinct_id` counts as missing, so the event gets a generated personless distinct ID. 7.x sent a whitespace-only ID, and capture dropped the event.
+- Generated personless distinct IDs are UUIDv7. 7.x generated UUIDv4.
+- `group_identify` uses the `distinct_id` you pass, then the context distinct ID, then `$_`. 7.x fell back to a random ID, which created a new person on every call. If `$_` is over 200 bytes, pass `distinct_id`: PostHog drops an event whose distinct ID is over 200 bytes.
+- PostHog drops an event whose `distinct_id` is over 200 UTF-8 bytes (`distinct_id_too_large`), and `on_error` reports it. 7.x sent events to legacy capture, which shortened the ID to 200 characters and kept the event.
+- `group_identify` no longer adds the context session ID. A session takes the person of its latest event, and this event's distinct ID is not the session's user.
+- `alias()` needs an explicit `distinct_id`. It no longer falls back to the context distinct ID, which can come from a request header the client controls. Without one, the call is dropped with a warning.
+- Context tags and context options now apply to `alias` and `group_identify`, below the call's own values, as they do for `capture`.
+- `process_person_profile: False` from a context option, `super_options` or a `$process_person_profile` entry in `super_properties` reaches `alias`, `group_identify`, `set` and `set_once` too. A `$process_person_profile` context tag reaches only `alias` and `group_identify`, because `set` and `set_once` add context tags to the person properties they set. Context tags and options are new on `alias` and `group_identify`; `super_properties` already reached them in 7.x. PostHog drops the `$create_alias` and `$groupidentify` events when person processing is off, with an ingestion warning, so they never merge a person or update a group. It keeps the event from `set` or `set_once` but ignores its person update. Once the person exists, events sent with `process_person_profile: False` are still linked to it and billed as identified events. Capture accepts these events, so `on_error` does not report the drop. To keep them, pass the option on the call, which wins over context and `super_options`, or set it in `before_send`:
+
+ ```python
+ posthog.alias(previous_id="anon-1", distinct_id="user-1", options={"process_person_profile": True})
+ posthog.group_identify("company", "acme", {"name": "Acme"}, options={"process_person_profile": True})
+ posthog.set(distinct_id="user-1", properties={"plan": "pro"}, options={"process_person_profile": True})
+ ```
+
+## Tracing headers
+
+The Django, Flask and ASGI integrations read the `X-PostHog-Distinct-Id` and `X-PostHog-Session-Id` headers by default, as in 7.71 and later.
+The headers only fill a missing distinct ID or session ID, and any client can set them, so never use them for authentication.
+
+- To turn this off, set `POSTHOG_MW_CAPTURE_TRACING_HEADERS = False` in Django, or pass `capture_tracing_headers=False` to the Flask or ASGI integration.
+- The 7.68 `trust_tracing_headers` and `POSTHOG_MW_TRUST_TRACING_HEADERS` names still work, but are deprecated.
+- If you upgrade from 7.68, 7.69 or 7.70 and never turned these headers on, they are now read.
+
+## Exceptions
+
+- `capture_exception` takes a `level=` argument on `Client`, `AsyncPosthog` and the module. It sets `$exception_level`, for example `"warning"` or `"fatal"`. The default is `"error"`, and an unknown value counts as unset.
+- `capture_exception` ignores reserved exception properties in `properties`, such as `$exception_list`, `$exception_level` and `$exception_source`. In 7.x they overrode the SDK's values, with a `DeprecationWarning`. Use `level=` instead of `$exception_level`.
+- `AsyncPosthog.capture_exception` now sends `$exception_level`.
+- `AsyncPosthog.capture_exception` now adds `$trace_id` and `$span_id` from the active OpenTelemetry span, like `Client.capture_exception`. In 7.x it added them only with `capture_trace_context=True`.
+
+## Event options
+
+Capture v1 sends processing options in an `options` object, next to `properties`.
+
+- `capture`, `capture_ai`, `set`, `set_once`, `alias`, `group_identify` and `capture_exception` take an `options` argument:
+
+ ```python
+ posthog.capture("signed_up", distinct_id="user-1", options={"cookieless_mode": True})
+ ```
+
+ The MCP capture methods take `event_options` instead (see [MCP analytics](#mcp-analytics)), and the AI integrations take `posthog_options` (see [AI capture](#ai-capture)).
+
+- `super_options`, a new `Client`, `AsyncPosthog` and module setting, sets options on every event, like `super_properties`.
+- `set_context_option(key, value)` sets an option for the current context, like `tag()`. `get_context_options()` returns the options of the current context. Both exist on `Client` and as module functions. `AsyncPosthog` has no context methods, like it has no `tag()`, so call the module functions. They apply to every client in the context.
+- The Celery integration propagates context options to workers, like tags.
+ - A propagated `process_person_profile: True` turns person processing on for worker events without a distinct ID. Each of those events creates a person.
+ - In eager mode (`task_always_eager`), Celery publishes nothing, so the distinct ID, tags and options do not reach the task's events. To carry them, pass the task's PostHog headers with `task.apply(headers=...)`, as described in [references/middleware_configuration.md](../references/middleware_configuration.md).
+- Context tags and options reach `capture`, `capture_ai`, `capture_exception`, `alias` and `group_identify`. Context options also reach `set` and `set_once`. `super_properties` and `super_options` reach every method.
+- Options are sent as given. PostHog validates them. It drops an event with an option value it cannot read, such as a list for `cookieless_mode`, as `invalid_options`, and `on_error` reports it.
+- An `options` value that is not a dict is logged as an error and ignored. The event is still sent.
+- Each option replaces a legacy option property:
+
+ | Option | Replaces |
+ | --- | --- |
+ | `cookieless_mode` | `$cookieless_mode` |
+ | `disable_skew_correction` | `$ignore_sent_at` |
+ | `product_tour_id` | `$product_tour_id` |
+ | `process_person_profile` | `$process_person_profile` |
+
+ Legacy option properties still work, but an option overrides its legacy property. Use options.
+- Pass `True` or `False` for `cookieless_mode`, `disable_skew_correction` and `process_person_profile`. PostHog also reads common forms such as `"false"`, `"off"` or `0`.
+
+- These four options are the full set. PostHog ignores any other key in `options`. Session and window IDs stay `$session_id` and `$window_id` properties (see [Session and window IDs](#session-and-window-ids)).
+- A `None` option counts as unset, so a later step can fill it.
+
+Values apply in this order. Steps 2 to 4 fill only the options and properties that the steps before them left unset:
+
+1. the `options` and `properties` of the call, then the call's `disable_geoip` argument, which fills `$geoip_disable`
+2. context options and tags
+3. `super_options` and `super_properties`
+4. values the SDK sets: `$lib` and `$lib_version` as a pair (see [SDK identity](#sdk-identity)), `$is_server` from `is_server`, `$geoip_disable` from the client's `disable_geoip` setting, system properties such as `$os` and `$python_version`, the `$feature/` and `$active_feature_flags` properties from `flags` or `send_feature_flags`, `$trace_id` and `$span_id` from the active OpenTelemetry span (in `capture` and `capture_ai` only with `capture_trace_context=True`, and always in `capture_exception`), `options.process_person_profile = false` for events without a distinct ID, and `$release_id` from `POSTHOG_RELEASE_ID`
+5. `before_send`, which sees the result of steps 1 to 4 and can change or remove any of it
+
+A property set to `None` counts as set, so no later step fills it.
+`$lib` and `$lib_version` are the exception: they count as set only when they are non-empty strings (see [SDK identity](#sdk-identity)).
+`$set`, `$set_once`, `$groups` and `$group_set` fill one level deep.
+When the call and a later step both set one of them to a dict, the later step adds only the keys the call left out.
+For example, `super_properties={"$set": {"plan": "free", "source": "web"}}` and a call with `properties={"$set": {"plan": "pro"}}` send `{"plan": "pro", "source": "web"}`.
+
+These changes follow from this order:
+
+- Properties passed to a call now override `super_properties`.
+- A `$is_server`, `$geoip_disable`, `$lib`, `$lib_version` or system property such as `$os` that you set in a call or a context tag now wins over the SDK's value. In 7.x the SDK overwrote it. `super_properties` win over the SDK's value too, so `super_properties={"$geoip_disable": False}` turns GeoIP lookup on for events, even with `disable_geoip=True`.
+- Feature flag properties from `flags` or `send_feature_flags` still lose to the same key in the call's `properties`, a context tag or `super_properties`, as in 7.x.
+- A `$trace_id` or `$span_id` in a context tag or `super_properties` now replaces the active OpenTelemetry span's IDs. In 7.x the span's IDs beat context tags. Setting either key in the call's `properties`, a context tag or `super_properties` stops the SDK adding both. In 7.x the SDK still added the other key.
+- A `disable_geoip` argument to a call belongs to that event, so it wins over context tags and `super_properties`. A `$geoip_disable` in the call's own `properties` still wins over it. `disable_geoip=False` now sends `$geoip_disable: false`. In 7.x it sent no `$geoip_disable` property.
+- The `groups` argument merges into a `$groups` property of the call, and wins key by key. In 7.x it replaced the property. MCP events merge their identity's groups into a custom `$groups` property the same way.
+- A `$set`, `$set_once`, `$groups` or `$group_set` in `super_properties` no longer replaces the whole value of the call. The two merge, and the call wins key by key.
+- An event without a distinct ID gets `options.process_person_profile = false`. To turn person processing on for it, set the `process_person_profile` option.
+- Review your `before_send` hooks for the new event shape. To change an option, edit `options`. A hook that returns a new dict must copy `options`, or the event is sent without them. That includes the `process_person_profile = false` the SDK sets for an event without a distinct ID, so PostHog would create a person for its generated ID.
+- When the server enables minimal `$feature_flag_called` events, those events now keep `$window_id`. Their options still apply, because the trim removes only properties.
+
+## AI capture
+
+- `capture_ai` and the AI wrapper integrations send to `/i/v1/ai/events`. The AI endpoint accepts events up to 8 MiB.
+- Send `$ai_` events with `capture_ai`. `capture()` sends every event to `/i/v1/analytics/events`, including `$ai_` events. PostHog accepts them there for now, but this is temporary.
+- `capture_ai` sends any event name to the AI endpoint. PostHog drops an event whose name does not start with `$ai_` as `misrouted_event`, and `on_error` reports it. The SDK writes only a debug log.
+- The OpenTelemetry integration (`PostHogSpanProcessor`, `PostHogTraceExporter`) is unchanged: it still exports spans over OTLP to `/i/v0/ai/otel`.
+- `enable_full_ai_capture` now controls only content: string truncation and media redaction. It no longer chooses the endpoint. `_use_ai_lane` and `_enable_multimodal_capture` still work as aliases.
+- The AI integrations call your client's `capture_ai`, and never `capture`. A custom client object must implement `capture_ai` and accept its `options` keyword argument. If the client has no `capture_ai`, the wrapper, callback handler or tracing processor logs one error when you create it and captures no AI events; provider calls still work. Before, such a client got `capture` calls.
+- Tests that pass a `Mock` client to an AI integration must assert on `mock.capture_ai`, not `mock.capture`.
+- When an AI integration or MCP falls back to a trace, run or session ID, it turns person processing off with a per-event option. This is the only option the integrations set on their own. It wins over your `posthog_options`, `options`, `super_options` and context options. `before_send` can still change it.
+- An empty or whitespace-only distinct ID passed to an AI integration, such as `posthog_distinct_id=""`, counts as missing, so the integration falls back the same way and turns person processing off. In 7.x, an empty ID gave non-streaming wrapper calls a random personless ID. Streaming calls, embeddings and LangChain used the trace or run ID with person processing on. OpenAI Agents already treated an empty ID as missing. Every integration sent a whitespace-only ID as given, with person processing on.
+- The AI integrations take capture options:
+ - Every wrapper method that takes `posthog_properties` also takes `posthog_options`, for the events of that call. This covers OpenAI, Anthropic and Gemini, sync and async, and the Claude Agent SDK `query()` and `PostHogClaudeSDKClient`. The name keeps it apart from the Claude Agent SDK's own `options`.
+ - The Gemini clients take `posthog_options` as a default for every call. A call's `posthog_options` win key by key.
+ - LangChain's `CallbackHandler` and `PostHogMiddleware`, OpenAI Agents' `instrument()` and `PostHogTracingProcessor`, and the Claude Agent SDK's `instrument()` and `PostHogClaudeAgentProcessor` take `options=` for every event. LangChain also reads `posthog_options` from run metadata, like `posthog_properties`. Like properties, the handler's or processor's options win over a run's or a query's. The `$exception` event LangChain captures for a failed run gets the same options.
+ - These are the event's own options, so they win over context options and `super_options`, which still fill the keys they leave unset. `before_send` can still change them.
+ - A value that is not a dict is logged as a warning and ignored. The provider call still runs, and the provider never receives `posthog_options`.
+
+ ```python
+ from posthog.ai.langchain import CallbackHandler
+ from posthog.ai.openai import OpenAI
+
+ client = OpenAI(posthog_client=posthog_client)
+ client.chat.completions.create(
+ model="gpt-5-mini",
+ messages=[{"role": "user", "content": "Hello"}],
+ posthog_distinct_id="user-1",
+ posthog_options={"cookieless_mode": True},
+ )
+
+ handler = CallbackHandler(
+ posthog_client, distinct_id="user-1", options={"cookieless_mode": True}
+ )
+ ```
+- New `Client` and `AsyncPosthog` arguments for the AI lane:
+ - `capture_ai_compression`: default none. `POSTHOG_CAPTURE_COMPRESSION` does not apply to it.
+ - `capture_ai_max_queue_size`: default 1000
+ - `capture_ai_timeout`: default 30 seconds
+ - `capture_ai_max_event_bytes`: default 8 MiB plus 64 KiB. You can only lower it.
+- The AI lane does not use `max_queue_size`, `timeout` or `capture_compression`. An invalid `capture_ai_*` value raises `ValueError` when you create the client.
+- The module-level client has no AI lane settings. To change them, create a `Client`.
+- `AsyncPosthog` has `capture_ai` and `capture_ai_immediate`.
+- `AsyncPosthog` sends events with `requests` in a worker thread. It uses `httpx` only for feature flags and remote config.
+- `AsyncPosthog` accepts `privacy_mode` and `enable_full_ai_capture`, with the same meaning as on `Client`. An AI integration given an `AsyncPosthog` client used to always truncate and redact media.
+
+## MCP analytics
+
+MCP events take options like other events, through an `event_options` argument and an `event_options` callback.
+
+- The `PostHogMCP` capture methods (`capture_tool_call`, `capture_initialize`, `capture_tools_list`, `capture_missing_capability` and `capture_feedback`) and `McpAnalytics.capture`, on the handle `instrument()` returns, take an `event_options` argument. It sets options on that event. For a failed tool call, it also sets them on the `$exception` event.
+- `MCPAnalyticsOptions(event_options=...)` sets options on every event `instrument()` captures automatically, including `$exception` events. It does not apply to `McpAnalytics.capture`. Like `event_properties`, it is a function of `(request, extra)` that returns a dict or `None`, and it can be sync or async.
+- `PostHogMCP.capture()` is the core client's `capture`, so it takes `options`. The MCP capture methods take `event_options`.
+- The SDK passes these options as the event's own options, so they win over context options and `super_options`.
+- An event without an identity always sends `process_person_profile: False`, even when `event_options` sets it to `True`. Its distinct ID is the session ID, so person processing would create a person for each session. To process a person, identify the user with `identify` or pass `distinct_id`.
+- An `event_options` value that is not a dict is logged and ignored. The event is still sent.
+
+```python
+from posthog.mcp import MCPAnalyticsOptions, PostHogMCP, instrument
+
+instrument(
+ server,
+ posthog,
+ MCPAnalyticsOptions(event_options=lambda request, extra: {"cookieless_mode": True}),
+)
+
+mcp_client = PostHogMCP("phc_...")
+mcp_client.capture_tool_call(
+ "search_docs",
+ distinct_id="user-1",
+ event_options={"process_person_profile": False},
+)
+```
+
+`instrument()` captures `$mcp_tool_call` after the tool handler returns.
+A context you open inside the handler has ended by then, so options you set in it with `set_context_option` do not reach `$mcp_tool_call`.
+Events you capture inside that context still get them.
+To set options on `$mcp_tool_call`, use the `event_options` callback.
+
+MCP's `before_send` gets each event's `options` in an `options` key of `PostHogCaptureEvent`.
+A hook that returns a new dict must copy them, or the event is sent without the anonymous `process_person_profile: False`.
+
+## Batching and size limits
+
+- An analytics event over 10 MiB is dropped and logged, because no capture request can carry it. 7.x dropped events over 900 KiB. Capture drops an event over its own per-event limit and reports it in `CaptureError.drops` as `event_too_big`.
+- An AI event over `capture_ai_max_event_bytes` is dropped and logged.
+- A batch stops before an event that would take it past 5 MiB. A larger event is sent alone.
+- `flush()` and `shutdown()` drain the analytics and AI queues at the same time.
+
+## OpenFeature provider
+
+`openfeature-provider-posthog` 0.2.0 works with posthog 7.x and 8.x.
+Older provider versions require posthog below 8.0, so upgrade the provider before or with posthog.
diff --git a/references/posthog-python-reference.md b/references/posthog-python-reference.md
new file mode 100644
index 000000000..fa798a96c
--- /dev/null
+++ b/references/posthog-python-reference.md
@@ -0,0 +1,4110 @@
+---
+title: "PostHog Python SDK"
+sidebar: Docs
+showTitle: true
+contentMaxWidthClass: max-w-full
+platformLogo: python
+tableOfContents:
+ - value: "Getting started"
+ url: getting-started
+ depth: 0
+ - value: "Setup"
+ url: setup
+ depth: 0
+ - value: "Capture"
+ url: capture
+ depth: 0
+ - value: "Identify"
+ url: identify
+ depth: 0
+ - value: "Traces"
+ url: traces
+ depth: 0
+ - value: "Alias"
+ url: alias
+ depth: 0
+ - value: "Capture AI"
+ url: capture-ai
+ depth: 0
+ - value: "Capture exception"
+ url: capture-exception
+ depth: 0
+ - value: "Emails"
+ url: emails
+ depth: 0
+ - value: "Flush"
+ url: flush
+ depth: 0
+ - value: "Get feature flag"
+ url: get-feature-flag
+ depth: 0
+ - value: "Get feature flag payload"
+ url: get-feature-flag-payload
+ depth: 0
+ - value: "Get feature flag result"
+ url: get-feature-flag-result
+ depth: 0
+ - value: "Get feature flags"
+ url: get-feature-flags
+ depth: 0
+ - value: "Get feature flags and payloads"
+ url: get-feature-flags-and-payloads
+ depth: 0
+ - value: "Evaluate flags"
+ url: evaluate-flags
+ depth: 0
+ - value: "Group identify"
+ url: group-identify
+ depth: 0
+ - value: "Is feature enabled"
+ url: is-feature-enabled
+ depth: 0
+ - value: "Shutdown"
+ url: shutdown
+ depth: 0
+ - value: "Flag definition loader"
+ url: flag-definition-loader
+ depth: 0
+ - value: "SDK utils"
+ url: sdk-utils
+ depth: 0
+ - value: "AsyncClient"
+ url: asyncclient
+ depth: 0
+ - value: "Module functions"
+ url: module-functions
+ depth: 0
+ - value: "Types"
+ url: types
+ depth: 0
+---
+
+## Getting started
+
+
+The Python SDK captures events, evaluates feature flags and reports errors from Python 3.10 or later.
+
+To send your first event, install the package, create a client, capture an event, and shut the client down, as the steps below show.
+
+### Install
+
+```bash
+pip install posthog
+```
+
+### Initialize
+
+Create one client for your app with your project token and host. Your project token and host are in your [project settings](https://app.posthog.com/project/settings). Keep the token in an environment variable rather than in code.
+
+```python
+from posthog import Posthog
+
+posthog = Posthog("", host="")
+```
+
+### Capture an event
+
+```python
+posthog.capture("user_signed_up", distinct_id="user_123", properties={"plan": "free"})
+```
+
+`capture` queues the event and returns right away. A background thread sends it.
+
+### Shut down
+
+Call `shutdown()` before your process exits, so queued events are sent.
+
+```python
+posthog.shutdown()
+```
+
+In an asyncio app, use `AsyncPosthog` as an async context manager instead. See [AsyncClient](#asyncclient).
+
+## Setup
+
+### `Client(...)`
+
+```python
+Client(project_api_key: str, host=None, debug=False, max_queue_size=10000, send=True, on_error=None, flush_at=100, flush_interval=5.0, gzip=False, max_retries=3, sync_mode=False, timeout: float = 15, thread=1, poll_interval=30, personal_api_key=None, disabled=False, disable_geoip=True, is_server=True, historical_migration=False, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries=1, super_properties=None, enable_exception_autocapture=False, log_captured_exceptions=False, project_root=None, privacy_mode=False, before_send=None, flag_fallback_cache_url=None, enable_local_evaluation=True, flag_definition_cache_provider: Optional[FlagDefinitionCacheProvider] = None, capture_exception_code_variables=False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: list[str] | None = None, enable_exception_autocapture_rate_limiting=False, exception_autocapture_bucket_size=ExceptionCapture.DEFAULT_BUCKET_SIZE, exception_autocapture_refill_rate=ExceptionCapture.DEFAULT_REFILL_RATE, exception_autocapture_refill_interval_seconds=ExceptionCapture.DEFAULT_REFILL_INTERVAL_SECONDS, capture_mode: Optional[Union[CaptureMode, str]] = None, capture_compression: Optional[Union[CaptureCompression, str]] = None, secret_key=None, metrics: Optional[dict] = None, enable_full_ai_capture=False, capture_trace_context=False, traces: Optional[dict] = None, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None)
+```
+
+Initialize a new PostHog client instance.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`project_api_key` | `str` | PostHog project API key/token. | *required*
+`host` | | PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as `https://us.posthog.com` are mapped to the corresponding ingestion host. | `None`
+`debug` | | Enable verbose SDK logging and re-raise errors from public API methods. | `False`
+`max_queue_size` | | Maximum number of events buffered before upload. | `10000`
+`send` | | If False, queueing succeeds but events are not sent. | `True`
+`on_error` | | Optional callback invoked by background consumers when an upload fails. Keep it short and non-blocking. Calling lifecycle methods directly is safe and deferred, but do not start another thread or task that calls `flush()`, `join()`, or `shutdown()` and then wait for it from the callback. | `None`
+`flush_at` | | Number of queued events that triggers a batch upload. | `100`
+`flush_interval` | | Maximum seconds a background consumer waits before flushing a partial batch. | `5.0`
+`gzip` | | Whether to gzip event upload payloads. | `False`
+`max_retries` | | Number of upload retries. Values below 0 are treated as 0. | `3`
+`sync_mode` | | If True, send each event synchronously instead of using background worker threads. This blocks the calling thread; in asyncio applications such as FastAPI, use `AsyncPosthog` instead. | `False`
+`timeout` | `float` | HTTP request timeout in seconds for event uploads. | `15`
+`thread` | | Number of background consumer threads. | `1`
+`poll_interval` | | Seconds between local feature flag definition refreshes. | `30`
+`secret_key` | | A Personal API Key or Project Secret API Key, used to authenticate local feature flag evaluation, remote config payloads, and decrypted flag payloads. For example, `posthog.Client(project_api_key, secret_key="phx_...")`. | `None`
+`personal_api_key` | | Deprecated alias for `secret_key`. Still honored for backwards compatibility; prefer `secret_key`, which also accepts a Project Secret API Key. | `None`
+`disabled` | | If True, disable captures and API requests. Useful in tests. | `False`
+`disable_geoip` | | Whether to disable server-side GeoIP enrichment. Defaults to True. | `True`
+`is_server` | | Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally. | `True`
+`historical_migration` | | Mark events as historical migration imports. | `False`
+`feature_flags_request_timeout_seconds` | `float` | Timeout in seconds for feature flag and remote config requests. | `3`
+`feature_flags_request_max_retries` | | Number of retries for feature flag requests after network, transport, or timeout failures. Defaults to 1. Set to 0 to disable retries. | `1`
+`app_host` | `Optional[str]` | Your PostHog app host, such as `https://posthog.example.com`. `emails` sends there. Needed only when `host` is not PostHog Cloud, for example a reverse proxy, which must not receive the secret key. | `None`
+`email_request_timeout_seconds` | `float` | Timeout in seconds for each email send request. Defaults to 15. | `15`
+`email_request_max_retries` | `int` | Number of retries for an email send after a network error, a rate limit, or an unavailable service. Defaults to 2. Set to 0 when a job runner already retries the send. | `2`
+`migrated_from` | `Optional[str]` | The email provider you moved from, such as `"resend"`. `emails` sends it with every request. | `None`
+`super_properties` | | Properties merged into every captured event. | `None`
+`enable_exception_autocapture` | | Automatically capture uncaught exceptions. | `False`
+`log_captured_exceptions` | | Also log exceptions captured by error tracking. | `False`
+`project_root` | | Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory. | `None`
+`privacy_mode` | | For AI observability, capture usage metadata without prompt inputs or outputs. | `False`
+`enable_full_ai_capture` | | Route PostHog AI wrapper events through the dedicated AI capture endpoint and capture full AI content: skips string truncation and passes media (base64/data URIs) through unredacted. `privacy_mode` always wins. Defaults to False. | `False`
+`before_send` | | Optional callback that can modify or drop events before upload. Return `None` to drop an event. | `None`
+`flag_fallback_cache_url` | | Optional feature flag fallback cache URL, such as `memory://local/?ttl=300&size=10000` or a Redis URL. | `None`
+`enable_local_evaluation` | | Whether to poll feature flag definitions for local evaluation when a personal API key is configured. | `True`
+`flag_definition_cache_provider` | `Optional[FlagDefinitionCacheProvider]` | Optional external cache provider for sharing feature flag definitions across workers. | `None`
+`capture_exception_code_variables` | | Capture local variable values on exception stack frames. | `False`
+`capture_trace_context` | | When OpenTelemetry is installed and a valid span is active at capture time, add its trace and span IDs as `$trace_id` and `$span_id` properties to events captured with `capture()` and `capture_ai()`, so they can be correlated with backend traces. Explicit `$trace_id`/`$span_id` values passed in `properties` win. Exception events (`capture_exception`) always attach these IDs regardless of this setting. Defaults to False. | `False`
+`traces` | `Optional[dict]` | Config dict for distributed tracing: `service_name`, `service_version`, `environment`, `resource_attributes`, `flush_interval` (5 s), `max_queue_size` (2048), `max_export_batch_size` (512), `max_live_spans` (10000), `max_span_age` (3600 s), `max_attributes_per_span` (128), `max_events_per_span` (128), `max_attribute_value_length` (8192). `before_span_send` is a callable, or a list run in order, that receives each finished span as a dict (`trace_id`, `span_id` and `parent_span_id` are read-only) and returns it, edited, or `None` to drop it; a hook that raises drops the span. Tracing is off until this is provided. Spans export on a background timer even with `sync_mode`; serverless handlers should call `flush()` before returning. Defaults to None. | `None`
+`code_variables_mask_patterns` | | Variable-name patterns to mask when capturing code variables. | `None`
+`code_variables_ignore_patterns` | | Variable-name patterns to omit when capturing code variables. | `None`
+`code_variables_mask_url_credentials` | | Scrub credentials embedded in URLs/DSNs (e.g. `user:pass@host`) from captured code variables, regardless of the surrounding variable name. Defaults to True. | `None`
+`code_variables_detect_secrets` | | Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True. | `None`
+`in_app_modules` | `list[str] \| None` | Module/package prefixes treated as in-app frames in captured exceptions. | `None`
+`enable_exception_autocapture_rate_limiting` | | Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default. | `False`
+`exception_autocapture_bucket_size` | | Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100). | `DEFAULT_BUCKET_SIZE`
+`exception_autocapture_refill_rate` | | Tokens restored per refill interval for each exception type's bucket. | `DEFAULT_REFILL_RATE`
+`exception_autocapture_refill_interval_seconds` | | Seconds between token refills for autocaptured exception rate limiting. | `DEFAULT_REFILL_INTERVAL_SECONDS`
+`capture_mode` | `Optional[Union[CaptureMode, str]]` | Capture wire protocol to use. Defaults to `CaptureMode.V0` (legacy `/batch/`). Set `CaptureMode.V1` (or pass the string `"v1"`) to opt into `/i/v1/analytics/events`. When omitted, the `POSTHOG_CAPTURE_MODE` env var is consulted, then `V0`. | `None`
+`capture_compression` | `Optional[Union[CaptureCompression, str]]` | Request-body compression for capture-v1 uploads (ignored in V0, which uses `gzip`). `CaptureCompression.GZIP` or `DEFLATE` (or the strings `"gzip"`/`"deflate"`). When omitted, the `POSTHOG_CAPTURE_COMPRESSION` env var is consulted, then the legacy `gzip` flag, then no compression. | `None`
+
+**Examples:**
+
+```python
+from posthog import Posthog
+
+posthog = Posthog('', host='')
+```
+
+## Capture
+
+### `Client.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to capture. | *required*
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to include with the event. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | A dictionary of group information. |
+`flags` | | A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. |
+`send_feature_flags` | | Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+# Anonymous event
+posthog.capture('some-anon-event')
+```
+```python
+# Context usage
+from posthog import identify_context, new_context
+with new_context():
+ identify_context('distinct_id_of_the_user')
+ posthog.capture('user_signed_up')
+ posthog.capture('user_logged_in')
+ posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')
+```
+```python
+# Set event properties
+posthog.capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+```python
+# Page view event
+posthog.capture('$pageview', distinct_id="distinct_id_of_the_user", properties={'$current_url': 'https://example.com'})
+```
+
+## Identify
+
+### `Client.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+# Set with distinct id
+posthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+### `Client.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a person profile only if they haven't been set before.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of properties to set once. |
+`timestamp` | | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Traces
+
+### `Client.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on
+the way out); or call `end()` yourself for a span that cannot wrap a
+block. Spans started inside the block nest under it automatically.
+Always returns a usable handle, even when tracing is off, so calling
+code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. A forked child starts with no active span; pass the parent span to continue a trace across a fork. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+posthog = Posthog("", traces={"service_name": "checkout-api"})
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `Client.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes
+it active; a span started manually is not. Use it to propagate the
+trace to the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+## Alias
+
+### `Client.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+Create an alias between two distinct IDs.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The previous distinct ID. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`distinct_id` | `Optional[str]` | The new distinct ID to alias to. Falls back to the context distinct ID; the call is dropped with a warning if neither is available. | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+
+**Examples:**
+
+```python
+posthog.alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Capture AI
+
+### `Client.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size
+cap, batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`:
+the event UUID, or None when the event was not admitted (disabled
+client, or dropped by `before_send`). The event is queued on an
+isolated AI lane with its own consumer pool and a higher per-event
+size cap, posting to the dedicated AI ingestion endpoint. The payload
+is sent as given — no redaction or truncation is applied here.
+
+## Capture exception
+
+### `Client.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg], **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception for error tracking.
+
+When OpenTelemetry is installed and a valid span is active, its trace and
+span IDs are added as `$trace_id` and `$span_id` event properties.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. | *required*
+`distinct_id` | | The distinct ID of the user. |
+`properties` | | A dictionary of additional properties. Overriding reserved exception properties is deprecated and will stop working in the next major version. |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. Attaches those exact flag values to the captured `$exception` event. |
+`send_feature_flags` | | Deprecated. Pass `flags` from `evaluate_flags()` instead. |
+`disable_geoip` | | Whether to disable GeoIP for this event. |
+
+**Examples:**
+
+```python
+try:
+ # Some code that might fail
+ pass
+except Exception as e:
+ posthog.capture_exception(e, distinct_id='user_distinct_id', properties=additional_properties)
+```
+
+## Emails
+
+### `Client.emails`
+
+```python
+emails: Emails
+```
+
+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 the `transactional_email:write`
+scope. Sends go to `app_host`, or to the PostHog Cloud app host of
+`host`. `email_request_timeout_seconds` and `email_request_max_retries`
+configure each send. A disabled or shut-down client sends nothing. See
+`posthog.emails` for setup.
+
+**Examples:**
+
+```python
+client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+)
+```
+
+## Flush
+
+### `Client.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events, ended spans and autocaptured metrics, keeping the client reusable.
+
+For a client shared across requests or serverless invocations (including
+the module-level client), call `flush()` before a short-lived invocation
+returns. Use `shutdown()` instead only for final process cleanup or when
+disposing of a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after
+a timeout or span export failure, and failed events may be dropped by the
+consumers. Calls made directly from SDK callbacks such as `on_error` are
+deferred rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently. The span exporter waits up to this many seconds for an in-flight flush, then uses a fresh drain budget once it acquires the lock. If the lock wait times out, the in-flight flush is left to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. Each span request is bounded by the client's `timeout` in seconds, and the last request is not cut short. This is therefore not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the shared client open.
+posthog.flush(timeout_seconds=10)
+```
+
+## Get feature flag
+
+### `Client.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get multivariate feature flag value for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag payload
+
+### `Client.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, *, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload for a feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`match_value` | `Optional[FlagValue]` | The specific flag value to get payload for. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Deprecated. Use get_feature_flag() instead if you need events. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This method returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Get feature flag result
+
+### `Client.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely
+depending on whether local evaluation is enabled and the flag can be locally evaluated.
+This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.
+When the flag was evaluated remotely and its config version 2 record is a complete experiment
+split (an experiment rule with a rule ID and a variant key), it also captures the
+`$experiment_exposure` event, once per distinct ID, groups, flag, rule and variant.
+
+**Examples:**
+
+```python
+flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')
+if flag_result and flag_result.get_value() == 'variant-key':
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = flag_result.payload
+```
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagResult]` | Optional[FeatureFlagResult]: The feature flag result or None if disabled/not found.
+
+## Get feature flags
+
+### `Client.get_feature_variants`
+
+```python
+get_feature_variants(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Union[bool, str]]
+```
+
+Get feature flag variants for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+### `Client.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> Optional[dict[str, Union[bool, str]]]
+```
+
+Get all feature flags for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags('distinct_id_of_your_user')
+```
+
+## Get feature flags and payloads
+
+### `Client.get_feature_flags_and_payloads`
+
+```python
+get_feature_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get feature flags and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+result = posthog.get_feature_flags_and_payloads('')
+```
+
+### `Client.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsAndPayloads
+```
+
+Get all feature flags and their payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+posthog.get_all_flags_and_payloads('distinct_id_of_your_user')
+```
+
+## Evaluate flags
+
+### `Client.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[List[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+Local evaluation is transparent: when the poller resolves a flag, the
+snapshot's `$feature_flag_called` events are tagged `locally_evaluated=True`
+and reason `"Evaluated locally"`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If True, never fall back to remote evaluation — flags that can't be evaluated locally are omitted from the snapshot and listed with a reason in its `unresolved_flags`. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[List[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is True. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagEvaluations` | A `FeatureFlagEvaluations` snapshot.
+
+**Examples:**
+
+```python
+flags = posthog.evaluate_flags(
+ "user_123",
+ person_properties={"plan": "enterprise"},
+)
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+## Group identify
+
+### `Client.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+Identify a group and set its properties.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | The type of group (e.g., 'company', 'team'). Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | The unique identifier for the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | A dictionary of properties to set on the group. | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | The timestamp of the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[Union[str, UUID]]` | A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this event. | `None`
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user performing the action. | `None`
+
+**Examples:**
+
+```python
+posthog.group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+Note: This method will not raise exceptions. Errors are logged.
+
+## Is feature enabled
+
+### `Client.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Check if a feature flag is enabled for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`only_evaluate_locally` | `bool` | Whether to only evaluate locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ # Do something differently for this user
+ # Optional: fetch the payload
+ matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+## Shutdown
+
+### `Client.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and end the consumer threads. Do not use directly, call `shutdown()` instead.
+
+Failed or undrainable events may be dropped and reported through logging
+or `on_error`; returning does not guarantee server receipt. Lifecycle
+cleanup is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+posthog.join()
+```
+
+### `Client.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the client.
+
+Call this for final process cleanup or when disposing of a client that
+will not be reused. It closes capture lanes, stops background workers and
+the feature flag poller, and tears down integrations. Do not call it at the
+end of each request or serverless invocation when the client is shared;
+call `flush()` before returning instead. A shut-down client cannot be
+reused; create a new client if needed.
+
+Normally this method blocks until queued events have been attempted and
+cleanup finishes. Failed or undrainable events may be dropped and
+reported through logging or `on_error`; returning does not guarantee
+server receipt. Event draining has no timeout. Queued spans get one final
+flush with up to 30 seconds waiting for an in-flight flush, then a fresh
+30-second drain budget; the last HTTP request is not cut short. Any spans
+it cannot send are discarded with a warning, as are spans still open.
+Lifecycle cleanup is attempted once, and cleanup failures
+are logged without retry. When called directly from an SDK callback such as
+`on_error`, shutdown is deferred to avoid blocking the worker that
+invoked the callback. If the callback must coordinate a blocking
+shutdown, have it signal an
+application-owned thread and return before that thread calls shutdown.
+Do not wait inside the callback for another thread or task that calls a
+lifecycle method.
+
+**Examples:**
+
+```python
+posthog.shutdown()
+```
+
+## Flag definition loader
+
+### `Client.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flags for local evaluation.
+
+**Examples:**
+
+```python
+posthog.load_feature_flags()
+```
+
+### `Client.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Return feature flag definitions loaded for local evaluation.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The currently loaded feature flag definitions, or `None` before local evaluation has loaded definitions.
+
+## SDK utils
+
+### `Client.queue`
+
+```python
+queue: Queue
+```
+
+The analytics lane's queue (kept for backwards compatibility).
+
+### `Client.consumers`
+
+```python
+consumers: Optional[List[Consumer]]
+```
+
+Flat list of the lanes' consumers, analytics first (kept for backwards compatibility).
+
+### `Client.new_context`
+
+```python
+new_context(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+with client.new_context():
+ client.identify_context('')
+ client.capture('event_name')
+```
+
+### `Client.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the wrapped function using this client.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to create a fresh context that doesn't inherit from parent. | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting. | `None`
+
+### `Client.tag`
+
+```python
+tag(name: str, value: Any) -> None
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key. | *required*
+`value` | `Any` | The tag value. | *required*
+
+### `Client.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context.
+
+### `Client.identify_context`
+
+```python
+identify_context(distinct_id: str) -> None
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_session`
+
+```python
+set_context_session(session_id: str) -> None
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children. | *required*
+
+### `Client.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str) -> None
+```
+
+Set the device ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children. | *required*
+
+### `Client.feature_flags`
+
+```python
+feature_flags
+```
+
+Get the local evaluation feature flags.
+
+### `Client.get_feature_payloads`
+
+```python
+get_feature_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> dict[str, Optional[str]]
+```
+
+Get feature flag payloads for a user, preserving valid serialized JSON.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The distinct ID of the user. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+payloads = posthog.get_feature_payloads('')
+```
+
+### `Client.get_flags_decision`
+
+```python
+get_flags_decision(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys_to_evaluate: Optional[list[str]] = None, device_id: Optional[str] = None) -> FlagsResponse
+```
+
+Get feature flags decision.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The distinct ID of the user. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | A dictionary of group information. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | A dictionary of person properties. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | A dictionary of group properties. | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP for this request. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance. | `None`
+`device_id` | `Optional[str]` | The device ID for this request. | `None`
+
+**Examples:**
+
+```python
+decision = posthog.get_flags_decision('user123')
+```
+
+### `Client.metrics`
+
+```python
+metrics: PostHogMetrics
+```
+
+The `posthog.metrics` API: a statsd-style pre-aggregating metrics client — alpha.
+
+Samples fold into per-series aggregates in memory and flush as one OTLP
+data point per series per window, so recording from hot paths is cheap.
+Configure via the `metrics` client option; pending metrics flush on
+`shutdown()`.
+
+**Examples:**
+
+```python
+client = Posthog("", metrics={"service_name": "billing-worker"})
+client.metrics.count("invoices.processed", 1, attributes={"plan": "pro"})
+client.metrics.gauge("queue.depth", 42)
+client.metrics.histogram("job.duration", 187, unit="ms")
+```
+
+### `Client.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The remote config feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag, or `None` if the client is disabled, no personal API key is configured, or the request fails. Encrypted payloads are decrypted by PostHog before being returned.
+
+
+Note
+
+Requires `secret_key` for authentication.
+
+
+
+### `Client.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[FeatureFlagEvaluationRuntime]` | The flag's evaluation runtime, or `None` when local evaluation has not loaded a definition for this key. A definition that carries no runtime reports `FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+runtime = posthog.get_feature_flag_evaluation_runtime("my-flag")
+if runtime is FeatureFlagEvaluationRuntime.SERVER:
+ ...
+```
+
+### `Client.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime,
+so it is returned for `CLIENT` and for `SERVER`, and asking for
+`ALL` returns every loaded flag. Use this to decide which flags to hand
+to a browser when a backend serves flags to its own frontend.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`evaluation_runtime` | `Union[FeatureFlagEvaluationRuntime, str]` | The runtime to match, as a `FeatureFlagEvaluationRuntime` or its string value. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`list[str]` | The matching flag keys, in the order local evaluation loaded them. Empty when no definitions are loaded.
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime
+
+client_keys = posthog.get_feature_flag_keys_by_evaluation_runtime(
+ FeatureFlagEvaluationRuntime.CLIENT
+)
+```
+
+### `posthog.integrations.django.PosthogContextMiddleware`
+
+```python
+PosthogContextMiddleware(get_response)
+```
+
+Middleware to automatically track Django requests.
+
+This middleware wraps all calls with a posthog context. It attempts to extract the following from the request:
+- Session ID, (extracted from `X-POSTHOG-SESSION-ID`)
+- Distinct ID, (extracted from `X-POSTHOG-DISTINCT-ID`, falling back to the authenticated request user ID)
+- Authenticated user email as `email`
+- Request URL as `$current_url`
+- Request method as `$request_method`
+- Request path as `$request_path`
+- Forwarded IP address as `$ip`
+- User agent as `$user_agent`
+
+Configure the integration with these Django settings:
+- `POSTHOG_MW_CLIENT`: client used for automatic exception capture, or the global client.
+ This does not redirect events explicitly captured through other clients.
+- `POSTHOG_MW_CAPTURE_EXCEPTIONS`: `False` enables context enrichment only;
+ `True` enables automatic exception capture; `None` inherits the effective client's
+ `enable_exception_autocapture`. When omitted, the legacy default is `True`.
+- `POSTHOG_MW_REQUEST_FILTER`: a callback receiving the request. Returning `False`
+ disables both enrichment and automatic exception capture for that request.
+- `POSTHOG_MW_EXTRA_PROPERTIES`: a callback returning additional event properties.
+- `POSTHOG_MW_CAPTURE_TRACING_HEADERS`: read PostHog identity and session headers
+ as request-scoped analytics context (default: `True`). Explicit capture IDs and
+ event properties take precedence. These values are never authentication or
+ authorization. Authenticated Django user identity remains the fallback when no
+ usable header ID is available or header capture is disabled.
+- `POSTHOG_MW_TRUST_TRACING_HEADERS`: deprecated alias for
+ `POSTHOG_MW_CAPTURE_TRACING_HEADERS`; the capture-named setting takes precedence.
+- `POSTHOG_MW_PROPERTIES_MAP`: an optional callback transforming request properties.
+
+The old `POSTHOG_MW_EXTRA_TAGS` and `POSTHOG_MW_TAG_MAP` settings remain aliases;
+the property-named settings take precedence when both are configured.
+
+Request properties are included on all events captured within the active context,
+including when automatic exception capture is disabled.
+See the context documentation for more information. The extracted distinct ID and session ID,
+if found, are used to associate all events captured in the middleware context with the same distinct ID
+and session as currently active on the frontend. See the documentation for `set_context_session`
+and `identify_context` for more details.
+
+This middleware is hybrid-capable: it supports both WSGI (sync) and ASGI (async) Django applications. The middleware
+detects at initialization whether the next middleware in the chain is async or sync, and adapts its behavior accordingly.
+This ensures compatibility with both pure sync and pure async middleware chains, as well as mixed chains in ASGI mode.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`aextract_properties` | Async version of extract_properties for use in async request handling.
+`aextract_request_user` | Async version of extract_request_user for use in async request handling.
+`aextract_tags` | Compatibility alias for `aextract_properties`.
+`extract_properties` | Extract event properties and identity from a synchronous request.
+`extract_request_user` | Extract user ID and email from request in sync context.
+`extract_tags` | Compatibility alias for `extract_properties`.
+`process_exception` | Process exceptions from views and downstream middleware.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`async_capable` | |
+`capture_exceptions` | `Optional[bool]` |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`extra_tags` | | Compatibility alias for `extra_properties`.
+`get_response` | |
+`properties_map` | |
+`request_filter` | |
+`sync_capable` | |
+`tag_map` | | Compatibility alias for `properties_map`.
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+Initialize the middleware with Django's next handler.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`get_response` | | The next middleware or view handler in Django's middleware chain. May be synchronous or asynchronous. |
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_properties`
+
+```python
+async aextract_properties(request)
+```
+
+Async version of extract_properties for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_request_user`
+
+```python
+async aextract_request_user(request)
+```
+
+Async version of extract_request_user for use in async request handling.
+
+Uses await request.auser() instead of request.user to avoid
+SynchronousOnlyOperation in async context.
+
+Follows Django's naming convention for async methods (auser, asave, etc.).
+
+#### `posthog.integrations.django.PosthogContextMiddleware.aextract_tags`
+
+```python
+async aextract_tags(request)
+```
+
+Compatibility alias for `aextract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.async_capable`
+
+```python
+async_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_exceptions`
+
+```python
+capture_exceptions: Optional[bool] = capture_exceptions if (capture_exceptions is None or isinstance(capture_exceptions, bool)) else True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers, canonical_name='POSTHOG_MW_CAPTURE_TRACING_HEADERS', deprecated_name='POSTHOG_MW_TRUST_TRACING_HEADERS')
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.client`
+
+```python
+client = cast('Optional[Client]', settings.POSTHOG_MW_CLIENT)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_properties`
+
+```python
+extra_properties = cast('Callable[[HttpRequest], Dict[str, Any]]', extra_properties) if callable(extra_properties) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extra_tags`
+
+```python
+extra_tags
+```
+
+Compatibility alias for `extra_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_properties`
+
+```python
+extract_properties(request)
+```
+
+Extract event properties and identity from a synchronous request.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_request_user`
+
+```python
+extract_request_user(request)
+```
+
+Extract user ID and email from request in sync context.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.extract_tags`
+
+```python
+extract_tags(request)
+```
+
+Compatibility alias for `extract_properties`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.get_response`
+
+```python
+get_response = get_response
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.process_exception`
+
+```python
+process_exception(request, exception)
+```
+
+Process exceptions from views and downstream middleware.
+
+Django calls this WHILE still inside the context created by __call__,
+so request tags have already been extracted and set. This method just
+needs to capture the exception directly.
+
+Django converts view exceptions into responses before they propagate through
+the middleware stack, so the context manager in __call__/__acall__ never sees them.
+
+Note: Django's process_exception is always synchronous, even for async views.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.properties_map`
+
+```python
+properties_map = cast('Callable[[Dict[str, Any]], Dict[str, Any]]', properties_map) if callable(properties_map) else None
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.request_filter`
+
+```python
+request_filter = cast('Optional[Callable[[HttpRequest], bool]]', settings.POSTHOG_MW_REQUEST_FILTER)
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.sync_capable`
+
+```python
+sync_capable = True
+```
+
+#### `posthog.integrations.django.PosthogContextMiddleware.tag_map`
+
+```python
+tag_map
+```
+
+Compatibility alias for `properties_map`.
+
+#### `posthog.integrations.django.PosthogContextMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.flask.PosthogFlaskIntegration`
+
+```python
+PosthogFlaskIntegration(app: Optional[Flask] = None, *, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[Callable[[Request], bool]] = None, extra_properties: Optional[Callable[[Request], Mapping[str, Any]]] = None, trust_tracing_headers: Optional[bool] = None, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog request context and exception tracking to a Flask app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `Optional[Flask]` | An optional Flask application. If omitted, call `init_app` later (the Flask application-factory pattern). | `None`
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions that reach Flask's unhandled exception machinery. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[Callable[[Request], bool]]` | Optional callback receiving Flask's request object. A false return value disables both context and exception capture for that request. | `None`
+`extra_properties` | `Optional[Callable[[Request], Mapping[str, Any]]]` | Optional callback returning additional event properties. This is useful for application-specific metadata such as an authenticated user's role. Values should not contain secrets or request bodies. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+The integration intentionally does not capture exceptions handled by an
+application error handler, expected HTTP exceptions, request or response
+bodies, query strings, cookies, authorization headers, or arbitrary headers.
+Call `capture_exception` explicitly from a custom error handler if a
+handled exception should be reported.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`init_app` | Register the integration with a Flask application once.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.init_app`
+
+```python
+init_app(app: Flask) -> None
+```
+
+Register the integration with a Flask application once.
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.flask.PosthogFlaskIntegration.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.asgi.PosthogASGIMiddleware`
+
+```python
+PosthogASGIMiddleware(app: _ASGIApp, client: Optional[Client] = None, capture_exceptions: Optional[bool] = None, request_filter: Optional[_RequestFilter] = None, extra_properties: Optional[_ExtraProperties] = None, trust_tracing_headers: Optional[bool] = None, *, capture_tracing_headers: Optional[bool] = None) -> None
+```
+
+Add PostHog context and automatic exception capture to an ASGI app.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`app` | `_ASGIApp` | The downstream ASGI application. | *required*
+`client` | `Optional[Client]` | Optional destination for automatically captured exceptions. The global client is used by default. Request context still enriches events captured through any client and does not redirect capture calls. | `None`
+`capture_exceptions` | `Optional[bool]` | Capture exceptions escaping the downstream app. If omitted, inherit the effective client's `enable_exception_autocapture` setting. Pass `True` or `False` to override it. | `None`
+`request_filter` | `Optional[_RequestFilter]` | Optional sync or async callback receiving the ASGI scope. Returning `False` bypasses all instrumentation for that scope. | `None`
+`extra_properties` | `Optional[_ExtraProperties]` | Optional sync or async callback receiving the ASGI scope and returning additional event properties. | `None`
+`capture_tracing_headers` | `Optional[bool]` | Read PostHog distinct and session ID headers as request-scoped analytics context. Defaults to True. Explicit capture IDs and event properties take precedence. Never use these values for security. | `None`
+`trust_tracing_headers` | `Optional[bool]` | Deprecated alias for `capture_tracing_headers`. The capture-named option takes precedence when both are supplied. | `None`
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`app` | |
+`capture_exceptions` | |
+`capture_tracing_headers` | |
+`client` | |
+`extra_properties` | |
+`request_filter` | |
+`trust_tracing_headers` | `bool` | Deprecated alias for `capture_tracing_headers`.
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.app`
+
+```python
+app = app
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.capture_tracing_headers`
+
+```python
+capture_tracing_headers = _resolve_capture_tracing_headers(capture_tracing_headers, trust_tracing_headers)
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.extra_properties`
+
+```python
+extra_properties = extra_properties
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.request_filter`
+
+```python
+request_filter = request_filter
+```
+
+#### `posthog.integrations.asgi.PosthogASGIMiddleware.trust_tracing_headers`
+
+```python
+trust_tracing_headers: bool
+```
+
+Deprecated alias for `capture_tracing_headers`.
+
+### `posthog.integrations.celery.PosthogCeleryIntegration`
+
+```python
+PosthogCeleryIntegration(client: Optional[Client] = None, capture_exceptions: bool = True, capture_task_lifecycle_events: bool = True, propagate_context: bool = True, task_filter: Optional[Callable[[Optional[str], dict[str, Any]], bool]] = None)
+```
+
+Celery integration that captures task lifecycle events and exceptions.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`client` | `Optional[Client]` | Optional `Client` instance. When provided, all events and exceptions are captured through this client rather than the global `posthog` module. Don't skip this if using a custom flag definition cache provider, and pass the custom `Client` instance here initialized with the custom provider so fork safety for that provider is handled correctly. | `None`
+`capture_exceptions` | `bool` | Whether to capture task exceptions via `capture_exception` (default `True`). | `True`
+`capture_task_lifecycle_events` | `bool` | Whether to emit lifecycle events of the task such as "started", "success", "failure" etc. (default `True`). | `True`
+`propagate_context` | `bool` | Whether to propagate PostHog context (distinct ID, session ID, tags) from the producer to the worker via task headers (default `True`). | `True`
+`task_filter` | `Optional[Callable[[Optional[str], dict[str, Any]], bool]]` | Optional callback `(task_name, task_properties) -> bool` expected to return `False` if a given task should not be tracked. | `None`
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`instrument` | Connect Celery signal handlers to capture task events and exceptions. Call this after initializing the PostHog client and this integration.
+`shutdown` | Disconnect all signal handlers registered by `instrument()`, flush all pending events and cleanly shutdown the integration.
+`uninstrument` | Disconnect Celery signal handlers and unregister exit cleanup.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_exceptions` | |
+`capture_task_lifecycle_events` | |
+`client` | |
+`propagate_context` | |
+`task_filter` | |
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_exceptions`
+
+```python
+capture_exceptions = capture_exceptions
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.capture_task_lifecycle_events`
+
+```python
+capture_task_lifecycle_events = capture_task_lifecycle_events
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.client`
+
+```python
+client = client
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.instrument`
+
+```python
+instrument() -> None
+```
+
+Connect Celery signal handlers to capture task events and exceptions.
+Call this after initializing the PostHog client and this integration.
+
+If Celery runs on a single host, reinstrumenting in worker children is
+not strictly necessary because the PostHog client and this integration
+are fork-safe. If Celery workers run across multiple hosts, each worker
+process must initialize PostHog, this integration, and call
+`instrument()`. Celery provides `worker_process_init` signal to help
+with this.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.propagate_context`
+
+```python
+propagate_context = propagate_context
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Disconnect all signal handlers registered by `instrument()`, flush all pending events
+and cleanly shutdown the integration.
+
+`shutdown()` is also registered on `worker_process_shutdown` and `atexit` signals,
+but there is no guarantee those will always be called, so we strongly recommend calling
+it manually when the integration is no longer needed to avoid data loss.
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.task_filter`
+
+```python
+task_filter = task_filter
+```
+
+#### `posthog.integrations.celery.PosthogCeleryIntegration.uninstrument`
+
+```python
+uninstrument() -> None
+```
+
+Disconnect Celery signal handlers and unregister exit cleanup.
+
+Do not use directly, call `shutdown()` instead.
+
+### `posthog.request.set_socket_options`
+
+```python
+set_socket_options(socket_options: Optional[SocketOptions]) -> None
+```
+
+Configure socket options for all SDK HTTP connections.
+
+Call this during initialization, before making API requests. Pass `None`
+to reset to the default socket behavior.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`socket_options` | `Optional[SocketOptions]` | A list of `(level, option, value)` tuples accepted by urllib3/`socket.setsockopt()`, or `None` to reset defaults. | *required*
+
+
+Example
+
+from posthog import set_socket_options
+set_socket_options([(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)])
+
+
+
+### `posthog.request.enable_keep_alive`
+
+```python
+enable_keep_alive() -> None
+```
+
+Enable TCP keepalive for SDK HTTP connections.
+
+This helps prevent idle pooled connections from being dropped by network
+infrastructure. Call during initialization, before making API requests.
+
+### `posthog.request.disable_connection_reuse`
+
+```python
+disable_connection_reuse() -> None
+```
+
+Disable HTTP connection reuse for SDK requests.
+
+Each request will create a fresh connection. This can avoid issues with
+environments that terminate pooled connections, but adds per-request
+overhead. Call during initialization, before making API requests.
+
+## AsyncClient
+
+Needs the `async` extra, `posthog[async]`.
+
+### `AsyncClient(...)`
+
+```python
+AsyncClient(project_api_key: str, host: Optional[str] = None, debug: bool = False, max_queue_size: int = 10000, send: bool = True, on_error=None, flush_at: int = 100, flush_interval: float = 5.0, gzip: bool = False, max_retries: int = 3, timeout: float = 15, thread: int = 1, disabled: bool = False, disable_geoip: bool = True, is_server: bool = True, historical_migration: bool = False, super_properties: Optional[dict[str, Any]] = None, before_send=None, log_captured_exceptions: bool = False, project_root: Optional[str] = None, capture_exception_code_variables: bool = False, code_variables_mask_patterns=None, code_variables_ignore_patterns=None, code_variables_mask_url_credentials=None, code_variables_detect_secrets=None, in_app_modules: Optional[list[str]] = None, capture_mode: Optional[Union[CaptureMode, str]] = None, capture_compression: Optional[Union[CaptureCompression, str]] = None, capture_trace_context: bool = False, secret_key: Optional[str] = None, personal_api_key: Optional[str] = None, feature_flags_request_timeout_seconds: float = 3, feature_flags_request_max_retries: int = 1, app_host: Optional[str] = None, email_request_timeout_seconds: float = 15, email_request_max_retries: int = 2, migrated_from: Optional[str] = None) -> None
+```
+
+### `AsyncClient.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Queue an event without blocking for network delivery.
+
+### `AsyncClient.capture_immediate`
+
+```python
+async capture_immediate(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture one event and wait until its delivery attempt completes.
+
+### `AsyncClient.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+### `AsyncClient.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: Optional[str], timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+### `AsyncClient.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an exception. This method never raises, including in debug mode.
+
+### `AsyncClient.emails`
+
+```python
+emails: AsyncEmails
+```
+
+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 the `transactional_email:write`
+scope, and `posthog[async]`. Sends go to `app_host`, or to the PostHog
+Cloud app host of `host`. `email_request_timeout_seconds` and
+`email_request_max_retries` configure each send. A disabled or shut-down
+client sends nothing. See `posthog.emails` for setup.
+
+**Examples:**
+
+```python
+await client.emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ distinct_id="user_123",
+)
+```
+
+### `AsyncClient.flush`
+
+```python
+async flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+### `AsyncClient.evaluate_flags`
+
+```python
+async evaluate_flags(distinct_id: Optional[ID_TYPES] = None, *, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate flags remotely without blocking the event loop.
+
+The returned snapshot has synchronous in-memory accessors. Pass it to
+`capture(flags=...)` to attach the exact values used for branching.
+This client does not evaluate flags locally, so the snapshot's
+`unresolved_flags` is always empty.
+
+### `AsyncClient.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime, str]] = None, uuid: Optional[Union[str, UUID]] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+### `AsyncClient.shutdown`
+
+```python
+async shutdown() -> None
+```
+
+### `AsyncClient.join`
+
+```python
+async join() -> None
+```
+
+### `AsyncClient.get_remote_config_payload`
+
+```python
+async get_remote_config_payload(key: str) -> Optional[Any]
+```
+
+Fetch and decrypt a remote-config payload without blocking the loop.
+
+## Module functions
+
+### `posthog.new_context`
+
+```python
+new_context(fresh: bool = False, capture_exceptions: Optional[bool] = None, client: Optional[Client] = None)
+```
+
+Create a new context scope that will be active for the duration of the with block.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | `bool` | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting. | `None`
+`client` | `Optional[Client]` | Optional Posthog client instance to use for this context (default: None) | `None`
+
+**Examples:**
+
+```python
+from posthog import new_context, tag, capture
+with new_context():
+ tag("request_id", "123")
+ capture("event_name", properties={"property": "value"})
+```
+
+### `posthog.scoped`
+
+```python
+scoped(fresh=False, capture_exceptions: Optional[bool] = None)
+```
+
+Decorator that creates a new context for the function.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`fresh` | | Whether to start with a fresh context (default: False) | `False`
+`capture_exceptions` | `Optional[bool]` | Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting. | `None`
+
+**Examples:**
+
+```python
+from posthog import scoped, tag, capture
+@scoped()
+def process_payment(payment_id):
+ tag("payment_id", payment_id)
+ capture("payment_started")
+```
+
+### `posthog.set_context_session`
+
+```python
+set_context_session(session_id: str)
+```
+
+Set the session ID for the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`session_id` | `str` | The session ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_session
+set_context_session("session_123")
+```
+
+### `posthog.set_context_device_id`
+
+```python
+set_context_device_id(device_id: str)
+```
+
+Set the device ID for the current context, associating all feature flag requests
+in this or child contexts with the given device ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`device_id` | `str` | The device ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import set_context_device_id
+set_context_device_id("device_123")
+```
+
+### `posthog.identify_context`
+
+```python
+identify_context(distinct_id: str)
+```
+
+Identify the current context with a distinct ID.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `str` | The distinct ID to associate with the current context and its children | *required*
+
+**Examples:**
+
+```python
+from posthog import identify_context
+identify_context("user_123")
+```
+
+### `posthog.set_capture_exception_code_variables_context`
+
+```python
+set_capture_exception_code_variables_context(enabled: bool)
+```
+
+Override code-variable capture for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`enabled` | `bool` | Whether exceptions captured in this context should include local variable values from stack frames. | *required*
+
+### `posthog.set_code_variables_mask_patterns_context`
+
+```python
+set_code_variables_mask_patterns_context(mask_patterns: list[str])
+```
+
+Override code-variable mask patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`mask_patterns` | `list[str]` | Variable-name patterns whose values should be replaced with `***` when code variables are captured. | *required*
+
+### `posthog.set_code_variables_ignore_patterns_context`
+
+```python
+set_code_variables_ignore_patterns_context(ignore_patterns: list[str])
+```
+
+Override code-variable ignore patterns for exceptions in the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`ignore_patterns` | `list[str]` | Variable-name patterns that should be omitted entirely when code variables are captured. | *required*
+
+### `posthog.set_code_variables_mask_url_credentials_context`
+
+```python
+set_code_variables_mask_url_credentials_context(enabled: bool)
+```
+
+Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from
+captured code variables for the current context.
+
+### `posthog.set_code_variables_detect_secrets_context`
+
+```python
+set_code_variables_detect_secrets_context(enabled: bool)
+```
+
+Whether to apply entropy-based secret detection as a last-resort redaction of
+high-entropy values (API keys, tokens, strong passwords) in captured code
+variables for the current context.
+
+### `posthog.tag`
+
+```python
+tag(name: str, value: Any)
+```
+
+Add a tag to the current context.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | The tag key | *required*
+`value` | `Any` | The tag value | *required*
+
+**Examples:**
+
+```python
+from posthog import tag
+tag("user_id", "123")
+```
+
+### `posthog.get_tags`
+
+```python
+get_tags() -> Dict[str, Any]
+```
+
+Get all tags from the current context.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Dict[str, Any]` | Dict of all tags in the current context
+
+### `posthog.capture`
+
+```python
+capture(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture anything a user does within your system.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name to specify the event | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional arguments including: distinct_id: Unique identifier for the user properties: Dict of event properties timestamp: When the event occurred. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this event. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. groups: Dict of group types and IDs flags: A FeatureFlagEvaluations snapshot from evaluate_flags(). The exact values from the snapshot are attached with no extra /flags request. send_feature_flags: Deprecated. Prefer flags=... from evaluate_flags(). When truthy, evaluates flags during capture and attaches them to the event. disable_geoip: Whether to disable GeoIP lookup | `{}`
+
+
+Details
+
+Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.
+
+
+
+**Examples:**
+
+```python
+# Context and capture usage
+from posthog import new_context, identify_context, tag, capture
+# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)
+with new_context():
+ # Associate this context with some user, by distinct_id
+ identify_context('some user')
+
+ # Capture an event, associated with the context-level distinct ID ('some user')
+ capture('movie started')
+
+ # Capture an event associated with some other user (overriding the context-level distinct ID)
+ capture('movie joined', distinct_id='some-other-user')
+
+ # Capture an event with some properties
+ capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})
+
+ # Capture an event with some properties
+ capture('purchase', properties={'product_id': '123', 'category': 'romcom'})
+ # Capture an event with some associated group
+ capture('purchase', groups={'company': 'id:5'})
+
+ # Adding a tag to the current context will cause it to appear on all subsequent events
+ tag('some-tag', 'some-value')
+
+ capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict
+```
+```python
+# Set event properties
+from posthog import capture
+capture(
+ "user_signed_up",
+ distinct_id="distinct_id_of_the_user",
+ properties={
+ "login_type": "email",
+ "is_free_trial": "true"
+ }
+)
+```
+
+### `posthog.capture_ai`
+
+```python
+capture_ai(event: str, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture an AI event on the dedicated AI capture endpoint.
+
+Beta: the signature is stable; operational limits (per-event size cap,
+batching, endpoint) may change without notice.
+
+Takes the same arguments and returns the same value as `capture()`: the
+event UUID, or None when the event was not admitted (disabled client, or
+dropped by `before_send`). The event is delivered on an isolated queue
+with its own consumer pool and a higher per-event size cap, posting to
+the dedicated AI ingestion endpoint. The payload is sent as given — no
+redaction or truncation is applied here.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`event` | `str` | The event name, normally one of the `$ai_*` event names. | *required*
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Same optional arguments as `capture()`. | `{}`
+
+**Examples:**
+
+```python
+from posthog import capture_ai
+
+uuid = capture_ai(
+ "$ai_generation",
+ distinct_id="user_123",
+ properties={"$ai_model": "gpt-5"},
+)
+```
+
+### `posthog.set`
+
+```python
+set(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).
+
+
+
+**Examples:**
+
+```python
+# Set person properties
+from posthog import set
+set(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})
+```
+
+### `posthog.set_once`
+
+```python
+set_once(**kwargs: Unpack[OptionalSetArgs]) -> Optional[str]
+```
+
+Set properties on a user record, only if they do not yet exist.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`**kwargs` | `Unpack[OptionalSetArgs]` | Optional arguments including: distinct_id: Unique identifier for the user. Falls back to the context distinct ID; if none exists, this call does nothing. properties: Dict of person properties to set only once. timestamp: When the properties were set. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. uuid: Unique identifier for this operation. If omitted, one is generated and returned. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. disable_geoip: Whether to disable GeoIP lookup. | `{}`
+
+
+Details
+
+This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.
+
+
+
+**Examples:**
+
+```python
+# Set property once
+from posthog import set_once
+set_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})
+
+```
+
+### `posthog.group_identify`
+
+```python
+group_identify(group_type: str, group_key: str, properties: Optional[Dict[str, Any]] = None, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None, distinct_id: Optional[ID_TYPES] = None) -> Optional[str]
+```
+
+Set properties on a group.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`group_type` | `str` | Type of your group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`group_key` | `str` | Unique identifier of the group. Required - the call is dropped with a warning if it is missing or empty. | *required*
+`properties` | `Optional[Dict[str, Any]]` | Properties to set on the group | `None`
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`distinct_id` | `Optional[ID_TYPES]` | Optional distinct ID of the user performing the action | `None`
+
+**Examples:**
+
+```python
+# Group identify
+from posthog import group_identify
+group_identify('company', 'company_id_in_your_db', {
+ 'name': 'Awesome Inc.',
+ 'employees': 11
+})
+```
+
+### `posthog.alias`
+
+```python
+alias(previous_id: ID_TYPES, distinct_id: str, timestamp: Optional[Union[datetime.datetime, str]] = None, uuid: Optional[str] = None, disable_geoip: Optional[bool] = None) -> Optional[str]
+```
+
+Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`previous_id` | `ID_TYPES` | The unique ID of the user before | *required*
+`distinct_id` | `str` | The current unique id | *required*
+`timestamp` | `Optional[Union[datetime, str]]` | Optional timestamp for the event. UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. | `None`
+`uuid` | `Optional[str]` | Optional UUID for the event | `None`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+
+
+Details
+
+To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.
+
+
+
+**Examples:**
+
+```python
+# Alias user
+from posthog import alias
+alias(previous_id='distinct_id', distinct_id='alias_id')
+```
+
+### `posthog.capture_exception`
+
+```python
+capture_exception(exception: Optional[ExceptionArg] = None, **kwargs: Unpack[OptionalCaptureArgs]) -> Optional[str]
+```
+
+Capture exceptions that happen in your code.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`exception` | `Optional[ExceptionArg]` | The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` | `None`
+`**kwargs` | `Unpack[OptionalCaptureArgs]` | Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip. Overriding reserved exception properties through `properties` is deprecated and will stop working in the next major version. | `{}`
+
+
+Details
+
+Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the "traceback"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError("Some Error"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.
+
+
+
+**Examples:**
+
+```python
+# Capture exception
+from posthog import capture_exception
+try:
+ risky_operation()
+except Exception as e:
+ capture_exception(e)
+```
+
+### `posthog.feature_enabled`
+
+```python
+feature_enabled(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[bool]
+```
+
+Use feature flags to enable or disable features for users.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.
+
+
+
+**Examples:**
+
+```python
+# Boolean feature flag
+from posthog import feature_enabled, get_feature_flag_payload
+is_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')
+if is_my_flag_enabled:
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag`
+
+```python
+get_feature_flag(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FlagValue]
+```
+
+Get feature flag variant for users. Used with experiments.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping from group type to group key | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties in format { group_type_name: { group_properties } } | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`send_feature_flag_events` | `bool` | Whether to send feature flag events | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+
+
+Details
+
+`groups` are a mapping from group type to group key. So, if you have a group type of "organization" and a group key of "5", you would pass groups={"organization": "5"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type "organization" and the group key "5", with the properties name, and employee count, you'll send these as: group_properties={"organization": {"name": "PostHog", "employees": 11}}.
+
+
+
+**Examples:**
+
+```python
+# Multivariate feature flag
+from posthog import get_feature_flag, get_feature_flag_payload
+enabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')
+if enabled_variant == 'variant-key':
+ matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
+```
+
+### `posthog.get_all_flags`
+
+```python
+get_all_flags(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> Optional[dict[str, FlagValue]]
+```
+
+Get all flags for a given user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Groups mapping | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate (evaluates all if None) | `None`
+
+
+Details
+
+Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.
+
+
+
+**Examples:**
+
+```python
+# All flags for user
+from posthog import get_all_flags
+get_all_flags('distinct_id_of_your_user')
+```
+
+### `posthog.get_feature_flag_result`
+
+```python
+get_feature_flag_result(key: str, distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[FeatureFlagResult]
+```
+
+Get a FeatureFlagResult object which contains the flag result and payload.
+
+This method evaluates a feature flag and returns a FeatureFlagResult object containing:
+- enabled: Whether the flag is enabled
+- variant: The variant value if the flag has variants
+- payload: The payload associated with the flag (automatically deserialized from JSON)
+- key: The flag key
+- reason: Why the flag was enabled/disabled
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+Example:
+```python
+result = posthog.get_feature_flag_result('beta-feature', 'distinct_id')
+if result and result.enabled:
+ # Use the variant and payload
+ print(f"Variant: {result.variant}")
+ print(f"Payload: {result.payload}")
+```
+
+### `posthog.get_feature_flag_payload`
+
+```python
+get_feature_flag_payload(key: str, distinct_id: ID_TYPES, match_value: Optional[FlagValue] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, send_feature_flag_events: bool = True, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None) -> Optional[object]
+```
+
+Get the payload associated with a feature flag value.
+
+Deprecated for new code. Prefer `evaluate_flags()` and
+`flags.get_flag_payload(key)` so flag evaluation happens once per request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`match_value` | `Optional[FlagValue]` | Optional flag value to use when selecting a payload. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`send_feature_flag_events` | `bool` | Whether to send a $feature_flag_called event. | `True`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Optional[object]` | The payload associated with the matched feature flag value, or None. This function returns the payload only, not the FeatureFlagResult wrapper used internally to compute it.
+
+### `posthog.get_remote_config_payload`
+
+```python
+get_remote_config_payload(key: str)
+```
+
+Get the payload for a remote config feature flag.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The key of the feature flag | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+ | The payload associated with the feature flag. If payload is encrypted, the return value will be decrypted
+
+
+Note
+
+Requires secret_key to be set for authentication
+
+
+
+### `posthog.get_all_flags_and_payloads`
+
+```python
+get_all_flags_and_payloads(distinct_id: ID_TYPES, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, device_id: Optional[str] = None, flag_keys_to_evaluate: Optional[list[str]] = None) -> FlagsAndPayloads
+```
+
+Get all feature flag values and payloads for a user.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `ID_TYPES` | The user's distinct ID. | *required*
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | Whether to evaluate only locally. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`device_id` | `Optional[str]` | Optional device ID override for experience-continuity flags. | `None`
+`flag_keys_to_evaluate` | `Optional[list[str]]` | Optional list of flag keys to evaluate. Evaluates all flags when omitted. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FlagsAndPayloads` | A dict with `featureFlags` and `featureFlagPayloads` entries.
+
+### `posthog.evaluate_flags`
+
+```python
+evaluate_flags(distinct_id: Optional[ID_TYPES] = None, groups: Optional[Mapping[str, Union[str, int]]] = None, person_properties: Optional[Dict[str, Any]] = None, group_properties: Optional[Dict[str, Dict[str, Any]]] = None, only_evaluate_locally: bool = False, disable_geoip: Optional[bool] = None, flag_keys: Optional[list[str]] = None, device_id: Optional[str] = None) -> FeatureFlagEvaluations
+```
+
+Evaluate all feature flags for a user in a single call and return a
+`FeatureFlagEvaluations` snapshot. Branch on `.is_enabled()` /
+`.get_flag()` and pass the same snapshot to `capture()` via the
+`flags` option so events carry the exact flag values the code branched on.
+
+Prefer this over repeated `get_feature_flag()` calls and over
+`capture(send_feature_flags=True)` — it consolidates flag evaluation into
+a single `/flags` request per incoming request.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | `Optional[ID_TYPES]` | The user's distinct ID. If `None`, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot. | `None`
+`groups` | `Optional[Mapping[str, Union[str, int]]]` | Mapping of group type to group key. | `None`
+`person_properties` | `Optional[Dict[str, Any]]` | Person properties to use for evaluation. | `None`
+`group_properties` | `Optional[Dict[str, Dict[str, Any]]]` | Group properties keyed by group type. | `None`
+`only_evaluate_locally` | `bool` | If `True`, never fall back to remote evaluation and omit flags that cannot be evaluated locally. The snapshot's `unresolved_flags` lists them with a reason. | `False`
+`disable_geoip` | `Optional[bool]` | Whether to disable GeoIP lookup. | `None`
+`flag_keys` | `Optional[list[str]]` | Optional list that scopes local evaluation, the underlying `/flags` request, and the returned snapshot. When omitted or `None`, all flags are evaluated. An empty list returns an empty snapshot without evaluating flags. A requested key absent from loaded local definitions is included in one remote fallback per `evaluate_flags` call unless `only_evaluate_locally` is `True`. If the server also does not know the key, it is omitted from the snapshot. | `None`
+`device_id` | `Optional[str]` | Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes. | `None`
+
+**Examples:**
+
+```python
+from posthog import evaluate_flags, capture
+flags = evaluate_flags("user_123", person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+capture("page_viewed", distinct_id="user_123", flags=flags)
+```
+
+### `posthog.feature_flag_definitions`
+
+```python
+feature_flag_definitions()
+```
+
+Returns loaded feature flags.
+
+
+Details
+
+Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.
+
+
+
+**Examples:**
+
+```python
+from posthog import feature_flag_definitions
+definitions = feature_flag_definitions()
+```
+
+### `posthog.get_feature_flag_evaluation_runtime`
+
+```python
+get_feature_flag_evaluation_runtime(key: str) -> Optional[FeatureFlagEvaluationRuntime]
+```
+
+Return where a locally loaded feature flag is meant to be evaluated.
+
+
+Details
+
+Reads the `evaluation_runtime` each flag definition carries, so no extra
+request is made. Returns `None` when local evaluation has not loaded a
+definition for this key. A definition that carries no runtime reports
+`FeatureFlagEvaluationRuntime.ALL`, the default PostHog applies.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_evaluation_runtime
+runtime = get_feature_flag_evaluation_runtime("my-flag")
+```
+
+### `posthog.get_feature_flag_keys_by_evaluation_runtime`
+
+```python
+get_feature_flag_keys_by_evaluation_runtime(evaluation_runtime: Union[FeatureFlagEvaluationRuntime, str]) -> list[str]
+```
+
+Return the keys of locally loaded flags that a runtime can evaluate.
+
+
+Details
+
+A flag set to `FeatureFlagEvaluationRuntime.ALL` suits either runtime, so
+it is returned for `CLIENT` and for `SERVER`. Use this to decide which
+flags to hand to a browser when a backend serves flags to its own
+frontend.
+
+
+
+**Examples:**
+
+```python
+from posthog import FeatureFlagEvaluationRuntime, get_feature_flag_keys_by_evaluation_runtime
+client_keys = get_feature_flag_keys_by_evaluation_runtime(FeatureFlagEvaluationRuntime.CLIENT)
+```
+
+### `posthog.load_feature_flags`
+
+```python
+load_feature_flags()
+```
+
+Load feature flag definitions from PostHog.
+
+**Examples:**
+
+```python
+from posthog import load_feature_flags
+load_feature_flags()
+```
+
+### `posthog.flush`
+
+```python
+flush(timeout_seconds: Optional[float] = 10) -> None
+```
+
+Attempt immediate delivery of queued events and ended spans, keeping the global client reusable.
+
+Call `flush()` before a short-lived request or serverless invocation returns
+when using the shared module-level client. Use `shutdown()` only for final
+process cleanup or a client that will not be reused. Flush does not stop the
+background workers or feature flag poller, and does not end open spans.
+
+Returning does not guarantee server receipt: pending work can remain after a
+timeout or span export failure, and failed events may be dropped by consumers.
+Calls made directly from SDK callbacks such as `on_error` are deferred
+rather than blocking the worker that invoked the callback.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`timeout_seconds` | `Optional[float]` | Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass `None` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently, waiting up to this many seconds for an in-flight flush before starting a fresh drain budget. A lock wait timeout leaves the in-flight flush to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. The last span request is not cut short and is bounded by the client's `timeout` in seconds, so this is not a strict wall-clock limit for the whole call. With `None`, a retriable span failure is left for a later flush rather than retried within this call. | `10`
+
+**Examples:**
+
+```python
+import posthog
+posthog.capture('event_name', distinct_id='user_id')
+# Before a serverless invocation returns; keep the global client open.
+posthog.flush(timeout_seconds=10)
+```
+
+### `posthog.join`
+
+```python
+join() -> None
+```
+
+Attempt to process queued events and stop the client's background workers. Use `shutdown()` directly in most cases.
+
+Failed or undrainable events may be dropped and reported through logging or
+`on_error`; returning does not guarantee server receipt. Lifecycle cleanup
+is attempted once, and cleanup failures are logged without retry.
+
+**Examples:**
+
+```python
+from posthog import join
+join()
+```
+
+### `posthog.start_span`
+
+```python
+start_span(name: str, *, kind: Optional[str] = None, attributes: Optional[Mapping[str, Any]] = None, parent: Union[Span, str, None] = None, tracestate: Optional[str] = None, start_time: Union[datetime.datetime, float, None] = None) -> Span
+```
+
+Start a span for distributed tracing. Alpha.
+
+Returns a span handle. Use it as a context manager to make it the active
+span for the block and end it on exit (recording a raised exception on the
+way out); or call `end()` yourself for a span that cannot wrap a block.
+Spans started inside the block nest under it automatically. Always returns
+a usable handle, even when tracing is off, so calling code never branches.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`name` | `str` | A low-cardinality operation name, e.g. `GET /users/:id`. Variable values belong in attributes, not the name. | *required*
+`kind` | `Optional[str]` | `internal` (default), `server`, `client`, `producer` or `consumer`. | `None`
+`attributes` | `Optional[Mapping[str, Any]]` | Initial attributes. | `None`
+`parent` | `Union[Span, str, None]` | A span handle, or an inbound W3C `traceparent` header value to continue a remote trace. Defaults to the active span. | `None`
+`tracestate` | `Optional[str]` | The inbound `tracestate` header accompanying a `traceparent` string `parent`; preserved and propagated. | `None`
+`start_time` | `Union[datetime, float, None]` | A `datetime` or epoch seconds, to backdate the span. | `None`
+
+**Examples:**
+
+```python
+import posthog
+posthog.traces = {"service_name": "checkout-api"}
+
+with posthog.start_span("POST /checkout", parent=request.headers.get("traceparent")) as span:
+ span.set_attribute("plan", user.plan)
+ with posthog.start_span("db.query", kind="client"):
+ ...
+ outgoing_headers = {"traceparent": span.traceparent()}
+```
+
+### `posthog.get_active_span`
+
+```python
+get_active_span() -> Optional[Span]
+```
+
+The span that is active in the current context, or `None`. Alpha.
+
+Only entering a span (`with posthog.start_span(...) as span:`) makes it
+active; a span started manually is not. Use it to propagate the trace to
+the next service: `span.traceparent()` is the header value.
+
+**Examples:**
+
+```python
+span = posthog.get_active_span()
+if span is not None:
+ headers["traceparent"] = span.traceparent()
+```
+
+### `posthog.shutdown`
+
+```python
+shutdown() -> None
+```
+
+Attempt final delivery and permanently shut down the global client.
+
+Call this for final process cleanup, not at the end of each request or
+serverless invocation that shares the module-level client. Use `flush()`
+before returning from those invocations instead. Shutdown closes capture
+lanes, stops background workers and the feature flag poller, and tears down
+integrations. The global client is not recreated automatically after shutdown.
+
+This normally blocks until queued events have been attempted and cleanup
+finishes. Failed or undrainable events may be dropped and reported through
+logging or `on_error`; returning does not guarantee server receipt. Event
+draining has no timeout. Queued spans get a final flush with up to 30 seconds
+waiting for an in-flight flush, then a fresh 30-second drain budget; the last
+HTTP request is not cut short. Unsent queued spans and still-open spans are
+discarded with a warning.
+Lifecycle cleanup is attempted once, and cleanup failures are logged without
+retry. Calls made directly from SDK callbacks such as `on_error` are deferred
+to avoid deadlocking the worker. If blocking completion is required, signal an application-owned
+thread, return from the callback, and call `shutdown()` from that thread.
+Do not wait inside a callback for another thread or task calling a lifecycle
+method.
+
+**Examples:**
+
+```python
+from posthog import shutdown
+shutdown()
+```
+
+### `posthog.setup`
+
+```python
+setup() -> Client
+```
+
+Create or return the global PostHog client configured by module settings.
+
+Most applications should either instantiate `Posthog` directly or set
+`posthog.api_key`/other module settings before calling top-level helpers.
+`setup()` is called automatically by global APIs such as `capture()`.
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Client` | The global `Client` instance. If both `api_key` and `project_api_key` are missing or blank, the client is disabled and module-level calls become no-ops.
+
+## Types
+
+### `OptionalCaptureArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the capture method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the person associated with this event. If not set, the context distinct_id is used, if available, otherwise a UUID is generated, and the event is marked as personless. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to track with the event |
+`timestamp` | | When the event occurred (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this specific event. If not provided, one is generated. The event UUID is returned, so you can correlate it with actions in your app (like showing users an error ID if you capture an exception). If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`groups` | | Group identifiers to associate with this event (format: {group_type: group_key}) |
+`flags` | | A `FeatureFlagEvaluations` snapshot from `evaluate_flags()`. The exact flag values from the snapshot are attached to the event with no additional network call — prefer this over `send_feature_flags`. |
+`send_feature_flags` | | Deprecated — prefer `flags` with a `FeatureFlagEvaluations` snapshot. Whether to include currently active feature flags in the event properties. Can be a boolean or a SendFeatureFlagsOptions object. Defaults to False. Fires a hidden `/flags` request on capture and may return different values than the ones the code branched on. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this event. Defaults to False. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`flags` | `NotRequired[Optional[FeatureFlagEvaluations]]` |
+`groups` | `NotRequired[Optional[Dict[str, str]]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`send_feature_flags` | `NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalCaptureArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.flags`
+
+```python
+flags: NotRequired[Optional[FeatureFlagEvaluations]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.groups`
+
+```python
+groups: NotRequired[Optional[Dict[str, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.send_feature_flags`
+
+```python
+send_feature_flags: NotRequired[Optional[Union[bool, SendFeatureFlagsOptions]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalCaptureArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `FeatureFlagEvaluations`
+
+```python
+FeatureFlagEvaluations(host: _FeatureFlagEvaluationsHost, distinct_id: str, flags: Dict[str, _EvaluatedFlagRecord], groups: Optional[Mapping[str, Union[str, int]]] = None, disable_geoip: Optional[bool] = None, request_id: Optional[str] = None, evaluated_at: Optional[int] = None, errors_while_computing: bool = False, quota_limited: bool = False, minimal_flag_called_events: bool = False, accessed: Optional[Set[str]] = None, unresolved_flags: Optional[Mapping[str, UnresolvedFlagReason]] = None) -> None
+```
+
+A point-in-time snapshot of feature flag evaluations for a single distinct_id.
+
+Returned by `Client.evaluate_flags` — branch on `is_enabled` /
+`get_flag` and pass the same object to `Client.capture` via the
+`flags` option so the captured event carries the exact flag values the code
+branched on.
+
+```python
+flags = posthog.evaluate_flags(distinct_id, person_properties={"plan": "enterprise"})
+if flags.is_enabled("new-dashboard"):
+ render_new_dashboard()
+posthog.capture("page_viewed", distinct_id=distinct_id, flags=flags)
+```
+
+To narrow the set of flags that get attached to a captured event, use the in-memory
+helpers `only` and `only_accessed`. To narrow the set of flags requested
+from the server in the first place, pass `flag_keys` to `Client.evaluate_flags`.
+
+Reading a flag sends `$feature_flag_called`, deduplicated as `is_enabled`
+describes. When the flag was evaluated remotely and its config version 2 record is
+a complete experiment split (an experiment rule with a rule ID and a variant key),
+the read also sends `$experiment_exposure`. The SDK sends one exposure per
+distinct ID, groups, flag, rule and variant. `send_feature_flag_events=False`
+suppresses both events.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`get_flag` | Return the flag value. Fires `$feature_flag_called` on first access.
+`get_flag_payload` | Return the payload associated with a flag.
+`is_enabled` | Return whether the flag is enabled. Fires `$feature_flag_called` on the first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+`only` | Return a filtered copy containing only flags with the given keys. Keys that are not present in the evaluation are dropped and logged as a warning.
+`only_accessed` | Return a filtered copy containing only flags accessed via `is_enabled` or `get_flag` before this call.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`keys` | `List[str]` | Return the flag keys that are part of this evaluation.
+`unresolved_flags` | `Mapping[str, UnresolvedFlagReason]` | Return a read-only mapping of flag key to the reason local evaluation left it without a value.
+
+Internal — instances are created by the SDK via `Client.evaluate_flags()`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag`
+
+```python
+get_flag(key: str, *, send_feature_flag_events: bool = True) -> Optional[FlagValue]
+```
+
+Return the flag value. Fires `$feature_flag_called` on first access.
+
+Returns the variant string for multivariate flags, `True` for enabled flags
+without a variant, `False` for disabled flags, and `None` for flags that
+were not returned by the evaluation.
+
+Pass `send_feature_flag_events=False` to skip the event for this read, as
+with `is_enabled`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.get_flag_payload`
+
+```python
+get_flag_payload(key: str) -> Optional[Any]
+```
+
+Return the payload associated with a flag.
+
+Does not count as an access for `only_accessed` and does not fire any event.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.is_enabled`
+
+```python
+is_enabled(key: str, default_value: bool = False, *, send_feature_flag_events: bool = True) -> bool
+```
+
+Return whether the flag is enabled. Fires `$feature_flag_called` on the
+first access per (distinct_id, flag, value) tuple, deduped via the SDK's cache.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The feature flag key. | *required*
+`default_value` | `bool` | Returned when the flag has no value in this evaluation — the key was not part of the evaluated set, or the evaluation itself came back empty (failed `/flags` request, quota limit, or no resolvable `distinct_id`). Defaults to `False`. | `False`
+`send_feature_flag_events` | `bool` | Whether this read sends `$feature_flag_called`. When `False`, no event is sent and the dedupe cache is left alone, but the key still counts as accessed for `only_accessed`. | `True`
+
+A flag that has a value always wins over `default_value`, including a
+disabled flag, which returns `False` even when `default_value=True`.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.keys`
+
+```python
+keys: List[str]
+```
+
+Return the flag keys that are part of this evaluation.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only`
+
+```python
+only(keys: List[str]) -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags with the given keys. Keys that
+are not present in the evaluation are dropped and logged as a warning.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.only_accessed`
+
+```python
+only_accessed() -> FeatureFlagEvaluations
+```
+
+Return a filtered copy containing only flags accessed via `is_enabled`
+or `get_flag` before this call.
+
+Order-dependent: if nothing has been accessed yet, the returned snapshot is
+empty. The method honors its name — pre-access if you want a populated result.
+
+#### `posthog.feature_flag_evaluations.FeatureFlagEvaluations.unresolved_flags`
+
+```python
+unresolved_flags: Mapping[str, UnresolvedFlagReason]
+```
+
+Return a read-only mapping of flag key to the reason local evaluation
+left it without a value.
+
+A flag is listed when it has a loaded local definition, was in the requested
+scope, was inconclusive locally, and no remote value filled the gap. Listed
+flags are not part of `keys`, and reading one reports the
+`local_evaluation_inconclusive` error instead of `flag_missing`. Reading
+this mapping does not count as an access and does not fire any event.
+Snapshots returned by `only` and `only_accessed`, and by
+`AsyncClient.evaluate_flags()`, which evaluates only remotely, carry no
+entries.
+
+### `FeatureFlagResult`
+
+```python
+FeatureFlagResult(key: str, enabled: bool, variant: Optional[str], payload: Optional[Any], reason: Optional[str]) -> None
+```
+
+The result of calling a feature flag which includes the flag result, variant, and payload.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | The unique identifier of the feature flag.
+`enabled` | `bool` | Whether the feature flag is enabled for the current context.
+`variant` | `Optional[str]` | The variant value if the flag is enabled and has variants, None otherwise.
+`payload` | `Optional[Any]` | Additional data associated with the feature flag, if any.
+`reason` | `Optional[str]` | A description of why the flag was enabled or disabled, if available.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_flag_details` | Create a FeatureFlagResult from a FeatureFlag object.
+`from_value_and_payload` | Creates a FeatureFlagResult from a flag value and payload.
+`get_value` | Returns the value of the flag. This is the variant if it exists, otherwise the enabled value. This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+#### `posthog.types.FeatureFlagResult.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlagResult.from_flag_details`
+
+```python
+from_flag_details(details: Union[FeatureFlag, None], override_match_value: Optional[FlagValue] = None) -> FeatureFlagResult | None
+```
+
+Create a FeatureFlagResult from a FeatureFlag object.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`details` | `Union[FeatureFlag, None]` | The FeatureFlag object to convert. | *required*
+`override_match_value` | `Optional[FlagValue]` | If provided, this value will be used to populate the enabled and variant fields instead of the values from the FeatureFlag. | `None`
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`FeatureFlagResult \| None` | FeatureFlagResult | None: A new FeatureFlagResult instance, or None if details is None.
+
+#### `posthog.types.FeatureFlagResult.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: Union[FlagValue, None], payload: Any) -> Union[FeatureFlagResult, None]
+```
+
+Creates a FeatureFlagResult from a flag value and payload.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`key` | `str` | The unique identifier of the feature flag. | *required*
+`value` | `Union[FlagValue, None]` | The value of the flag (string variant or boolean). | *required*
+`payload` | `Any` | Additional data associated with the feature flag. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`Union[FeatureFlagResult, None]` | Union[FeatureFlagResult, None]: A new FeatureFlagResult instance, or None if value is None.
+
+#### `posthog.types.FeatureFlagResult.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Returns the value of the flag. This is the variant if it exists, otherwise the enabled value.
+This is the value we report as `$feature_flag_response` in the `$feature_flag_called` event.
+
+**Returns:**
+
+Name | Type | Description
+---- | ---- | -----------
+`FlagValue` | `FlagValue` | Either a string variant or boolean value representing the flag's state.
+
+#### `posthog.types.FeatureFlagResult.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlagResult.payload`
+
+```python
+payload: Optional[Any]
+```
+
+#### `posthog.types.FeatureFlagResult.reason`
+
+```python
+reason: Optional[str]
+```
+
+#### `posthog.types.FeatureFlagResult.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FeatureFlag`
+
+```python
+FeatureFlag(key: str, enabled: bool, variant: Optional[str], reason: Optional[FlagReason], metadata: Union[FlagMetadata, LegacyFlagMetadata]) -> None
+```
+
+Detailed feature flag evaluation returned by the flags API.
+
+`enabled`, `variant` and `metadata.payload` are the value rendered the way
+responses before `/flags?v=4` carried it, which the legacy getters return.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`key` | `str` | Feature flag key.
+`enabled` | `bool` | Whether the flag is enabled for the evaluated user or group.
+`variant` | `Optional[str]` | Variant key for multivariate flags, otherwise `None`.
+`reason` | `Optional[FlagReason]` | Optional reason metadata explaining the result.
+`metadata` | `Union[FlagMetadata, LegacyFlagMetadata]` | Payload and other metadata returned by the API.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`from_json` | Parse one flag record of a `/flags` response.
+`from_value_and_payload` | Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+`get_value` | Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.enabled`
+
+```python
+enabled: bool
+```
+
+#### `posthog.types.FeatureFlag.from_json`
+
+```python
+from_json(resp: Any) -> FeatureFlag
+```
+
+Parse one flag record of a `/flags` response.
+
+A record with a `value` member is a `/flags?v=4` record. A record
+without one comes from an older server: its value is `variant`, or
+`enabled` when there is no variant, and its config version is `1`.
+
+#### `posthog.types.FeatureFlag.from_value_and_payload`
+
+```python
+from_value_and_payload(key: str, value: FlagValue, payload: Any) -> FeatureFlag
+```
+
+Build a flag from its value and payload. A string value is a variant, so the flag is enabled.
+
+#### `posthog.types.FeatureFlag.get_value`
+
+```python
+get_value() -> FlagValue
+```
+
+Return the variant for a multivariate flag, otherwise whether the flag is enabled.
+
+#### `posthog.types.FeatureFlag.key`
+
+```python
+key: str
+```
+
+#### `posthog.types.FeatureFlag.metadata`
+
+```python
+metadata: Union[FlagMetadata, LegacyFlagMetadata]
+```
+
+#### `posthog.types.FeatureFlag.reason`
+
+```python
+reason: Optional[FlagReason]
+```
+
+#### `posthog.types.FeatureFlag.variant`
+
+```python
+variant: Optional[str]
+```
+
+### `FlagsAndPayloads`
+
+Bases: `TypedDict`
+
+Feature flag values and payloads keyed by feature flag key.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`featureFlags` | `Optional[dict[str, FlagValue]]` | Each flag's value, keyed by flag key.
+`featureFlagPayloads` | `Optional[dict[str, Any]]` | Each flag's payload, keyed by flag key.
+
+#### `posthog.types.FlagsAndPayloads.featureFlagPayloads`
+
+```python
+featureFlagPayloads: Optional[dict[str, Any]]
+```
+
+#### `posthog.types.FlagsAndPayloads.featureFlags`
+
+```python
+featureFlags: Optional[dict[str, FlagValue]]
+```
+
+### `UnresolvedFlagReason`
+
+Bases: `str`, `Enum`
+
+Why local evaluation left a flag without a value.
+
+Reported by `FeatureFlagEvaluations.unresolved_flags`. Inheriting from
+`str` keeps the members directly comparable to their string values. When more
+than 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, 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.
+
+
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`EXPERIENCE_CONTINUITY` | |
+`MISSING_CONTEXT` | |
+`UNRESOLVED_DEPENDENCY` | |
+`UNSUPPORTED_DEFINITION` | |
+
+#### `posthog.types.UnresolvedFlagReason.EXPERIENCE_CONTINUITY`
+
+```python
+EXPERIENCE_CONTINUITY = 'experience_continuity'
+```
+
+#### `posthog.types.UnresolvedFlagReason.MISSING_CONTEXT`
+
+```python
+MISSING_CONTEXT = 'missing_context'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNRESOLVED_DEPENDENCY`
+
+```python
+UNRESOLVED_DEPENDENCY = 'unresolved_dependency'
+```
+
+#### `posthog.types.UnresolvedFlagReason.UNSUPPORTED_DEFINITION`
+
+```python
+UNSUPPORTED_DEFINITION = 'unsupported_definition'
+```
+
+### `InconclusiveMatchError`
+
+```python
+InconclusiveMatchError(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when local evaluation can't determine a flag's value. `reason` says
+why, as reported by `FeatureFlagEvaluations.unresolved_flags`.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why local evaluation couldn't resolve the flag.
+
+#### `posthog.feature_flags.InconclusiveMatchError.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `RequiresServerEvaluation`
+
+```python
+RequiresServerEvaluation(*args, reason: Optional[UnresolvedFlagReason] = None)
+```
+
+Bases: `Exception`
+
+Raised when feature flag evaluation requires server-side data that is not
+available locally (e.g., static cohorts).
+
+This error should propagate immediately to trigger API fallback, unlike
+InconclusiveMatchError which allows trying other conditions.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`reason` | `UnresolvedFlagReason` | Why the flag needs server-side evaluation.
+
+#### `posthog.feature_flags.RequiresServerEvaluation.reason`
+
+```python
+reason: UnresolvedFlagReason = UnresolvedFlagReason.UNSUPPORTED_DEFINITION
+```
+
+### `Span`
+
+A handle to a span.
+
+Every method is safe to call on any handle, including after `end()` and
+on the inert handles returned when tracing is off, so calling code never
+branches on whether tracing is running. Entering a handle (`with span:`)
+makes it the active span for the block and ends it on exit, recording an
+`Exception` raised inside it. A `BaseException` that is not an
+`Exception` (`GeneratorExit`, `CancelledError`, `KeyboardInterrupt`)
+still ends the span but is not recorded as a failure.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`add_event` | Add a timestamped event to the span. Ignored after `end()`.
+`end` | End the span and queue it for export. Idempotent.
+`record_exception` | Record an exception as an `exception` event and mark the span `error`.
+`set_attribute` | Set one attribute on the span; last write wins. Ignored after `end()`.
+`set_attributes` | Set several attributes at once; last write wins per key. Ignored after `end()`.
+`set_status` | Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+`traceparent` | The W3C `traceparent` header value to propagate, or `None`.
+`tracestate` | The W3C `tracestate` header value to propagate, or `None`.
+`update_name` | Rename the span, for a name only known after it started. Ignored after `end()`.
+
+#### `posthog.tracing.span.Span.add_event`
+
+```python
+add_event(name: str, attributes: Optional[Mapping[str, Any]] = None, timestamp: Union[datetime, float, None] = None) -> Span
+```
+
+Add a timestamped event to the span. Ignored after `end()`.
+
+`timestamp` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`. Returns the span, so calls
+chain.
+
+**Examples:**
+
+```python
+span.add_event("cache.miss", {"key": "user:42"})
+```
+
+#### `posthog.tracing.span.Span.end`
+
+```python
+end(end_time: Union[datetime, float, None] = None) -> None
+```
+
+End the span and queue it for export. Idempotent.
+
+`end_time` defaults to now; it accepts a `datetime`, or seconds
+since the epoch as a `float` or `int`, and is never earlier than
+the start. Later calls, and later mutations, no-op. `with span:`
+ends the span on exit, so call this only for spans started manually.
+
+**Examples:**
+
+```python
+span = posthog.start_span("job")
+try:
+ run_job()
+finally:
+ span.end()
+```
+
+#### `posthog.tracing.span.Span.record_exception`
+
+```python
+record_exception(exception: BaseException) -> Span
+```
+
+Record an exception as an `exception` event and mark the span `error`.
+
+Ignored after `end()`. The event carries `exception.type`,
+`exception.message` and, for a raised exception,
+`exception.stacktrace` (its last `max_attribute_value_length`
+characters, so a chained traceback keeps the outermost exception and
+may lose its cause). Returns the span, so calls chain. Inside
+`with span:` a raised `Exception` is recorded automatically, so
+this is for exceptions that are caught and handled.
+
+**Examples:**
+
+```python
+try:
+ charge(card)
+except PaymentError as e:
+ span.record_exception(e)
+```
+
+#### `posthog.tracing.span.Span.set_attribute`
+
+```python
+set_attribute(key: str, value: Any) -> Span
+```
+
+Set one attribute on the span; last write wins. Ignored after `end()`.
+
+Returns the span, so calls chain. Prefer primitive values: strings,
+booleans, integers and floats keep their type. Lists and mappings are
+sent as OTLP arrays and maps, but PostHog stores them as serialized
+strings. `None` removes the key; anything else is stringified.
+
+**Examples:**
+
+```python
+span.set_attribute("http.status_code", 200).set_attribute("cache.hit", True)
+```
+
+#### `posthog.tracing.span.Span.set_attributes`
+
+```python
+set_attributes(attributes: Mapping[str, Any]) -> Span
+```
+
+Set several attributes at once; last write wins per key. Ignored after `end()`.
+
+Returns the span, so calls chain. Same encoding as `set_attribute()`.
+
+**Examples:**
+
+```python
+span.set_attributes({"db.system": "postgresql", "db.rows": 12})
+```
+
+#### `posthog.tracing.span.Span.set_status`
+
+```python
+set_status(code: str, message: Optional[str] = None) -> Span
+```
+
+Set the span status to `"ok"` or `"error"`. Ignored after `end()`.
+
+Unset by default. Any other `code` is ignored. `ok` is final for the
+scoped form: an `Exception` raised inside `with span:` does not override
+it. Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span.set_status("error", "upstream timed out")
+```
+
+#### `posthog.tracing.span.Span.traceparent`
+
+```python
+traceparent() -> Optional[str]
+```
+
+The W3C `traceparent` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.tracestate`
+
+```python
+tracestate() -> Optional[str]
+```
+
+The W3C `tracestate` header value to propagate, or `None`.
+
+#### `posthog.tracing.span.Span.update_name`
+
+```python
+update_name(name: str) -> Span
+```
+
+Rename the span, for a name only known after it started. Ignored after `end()`.
+
+Returns the span, so calls chain.
+
+**Examples:**
+
+```python
+span = posthog.start_span("http.request")
+span.update_name(f"{request.method} {route.pattern}")
+```
+
+### `Emails`
+
+```python
+Emails(secret_key: Optional[str], *, host: Optional[str] = None, timeout: float = 15, max_retries: int = 2, disabled: bool = False, session: Optional[requests.Session] = None, migrated_from: Optional[str] = None) -> None
+```
+
+Bases: `_EmailsBase`
+
+Sends transactional email from PostHog email templates or from content in your code.
+
+`host` is your PostHog app host. PostHog Cloud ingestion hosts map to the
+app host, so `us.i.posthog.com` sends to `us.posthog.com`. Any other
+host is used as given.
+
+Each send retries network errors, rate limits and an unavailable service up
+to `max_retries` times, with the same idempotency key. Set
+`max_retries=0` when a job runner already retries the send. `timeout`
+is in seconds, per request. Pass `session` to send through your own
+`requests.Session`, for example a test double. `migrated_from`, such
+as `"resend"`, tells PostHog which provider your sends came from.
+
+**Functions:**
+
+Name | Description
+---- | -----------
+`close` | Close the HTTP connections this client opened. A `session` you passed in stays open.
+`get` | Read what happened to an email that `send` queued.
+`send` | Queue one email, from a template in PostHog or from content in your code.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disabled` | |
+`host` | |
+`max_retries` | |
+`migrated_from` | |
+`secret_key` | |
+`timeout` | |
+
+#### `posthog.emails.Emails.close`
+
+```python
+close() -> None
+```
+
+Close the HTTP connections this client opened. A `session` you passed in stays open.
+
+#### `posthog.emails.Emails.disabled`
+
+```python
+disabled = disabled
+```
+
+#### `posthog.emails.Emails.get`
+
+```python
+get(message_id: Union[str, UUID]) -> EmailStatus
+```
+
+Read what happened to an email that `send` queued.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`message_id` | `Union[str, UUID]` | The `id` of the `SendEmailResult` that `send` returned. | *required*
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`EmailStatus` | The email's latest status, for 30 days after the send.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not answer with a status. `code` is `not_found` for an unknown ID, an email older than 30 days, or for a few seconds after the send.
+`ValueError` | `message_id` is not a message ID.
+
+**Examples:**
+
+```python
+result = emails.send(to="user@example.com", template_id="...")
+status = emails.get(result.id)
+if status.status == "bounced":
+ print(status.reason)
+```
+
+#### `posthog.emails.Emails.host`
+
+```python
+host = determine_app_host(host)
+```
+
+#### `posthog.emails.Emails.max_retries`
+
+```python
+max_retries = max_retries
+```
+
+#### `posthog.emails.Emails.migrated_from`
+
+```python
+migrated_from = migrated_from
+```
+
+#### `posthog.emails.Emails.secret_key`
+
+```python
+secret_key = secret_key.strip() if isinstance(secret_key, str) else None
+```
+
+#### `posthog.emails.Emails.send`
+
+```python
+send(**kwargs: Any) -> SendEmailResult
+```
+
+Queue one email, from a template in PostHog or from content in your code.
+
+Pass exactly one form. The template form names a template made in
+PostHog with `template_id`. The code form names the email with
+`template_key` and passes `subject` and `html`, `text` or both:
+see `CodeEmailArgs`.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_id` | | The UUID of a template made transactional in PostHog. |
+`template_data` | | Values for the template's `{{ variables.* }}` placeholders. Values are encoded the way capture encodes properties. |
+`distinct_id` | | The recipient's distinct ID in your product. The email's events go to this person. Without it, they go to a person whose distinct ID is the email address. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. A send with a key that PostHog has already accepted queues nothing and returns the first send's result. Without it, the client makes a key that covers its own retries. Pass a key derived from what the email is for, such as `welcome:user_123`, to cover retries outside this call, too. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Returns:**
+
+Type | Description
+---- | -----------
+`SendEmailResult` | The queued email. A result means PostHog queued the email, not that it was delivered.
+
+**Raises:**
+
+Type | Description
+---- | -----------
+`EmailError` | PostHog did not queue the email, or the client could not tell whether it did.
+`(TypeError, ValueError)` | An argument has the wrong type or format.
+
+**Examples:**
+
+```python
+emails.send(
+ to="user@example.com",
+ template_id="0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b",
+ template_data={"name": "Ada"},
+ distinct_id="user_123",
+ idempotency_key="welcome:user_123",
+)
+emails.send(
+ to="user@example.com",
+ template_key="password-reset",
+ subject="Reset your password",
+ html=rendered_html,
+ distinct_id="user_123",
+)
+```
+
+#### `posthog.emails.Emails.timeout`
+
+```python
+timeout = timeout
+```
+
+### `EmailError`
+
+```python
+EmailError(*, name: str, code: str, message: str, status_code: Optional[int] = None, why: Optional[str] = None, fix: Optional[str] = None, docs_url: Optional[str] = None, field: Optional[str] = None, retry_after: Optional[float] = None) -> None
+```
+
+Bases: `Exception`
+
+PostHog did not queue the email, or the client could not tell whether it did.
+
+Branch on `code`, PostHog's stable error code, or on `name`, a coarse
+category of the failure. The message never contains the secret key or the
+request body.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`name` | | A coarse category of the failure.
+`code` | | PostHog's stable error code.
+`message` | | What went wrong. It never contains the secret key or the request body.
+`status_code` | | The HTTP status of the response, or `None` when none arrived.
+`why` | | PostHog's explanation of the failure, when it gave one.
+`fix` | | What to change to fix it, when PostHog said.
+`docs_url` | | A docs page about the error, when PostHog gave one.
+`field` | | The request field the error is about, when there is one.
+`retry_after` | | Seconds to wait before retrying, when PostHog said.
+
+#### `posthog.emails.EmailError.code`
+
+```python
+code = code
+```
+
+#### `posthog.emails.EmailError.docs_url`
+
+```python
+docs_url = docs_url
+```
+
+#### `posthog.emails.EmailError.field`
+
+```python
+field = field
+```
+
+#### `posthog.emails.EmailError.fix`
+
+```python
+fix = fix
+```
+
+#### `posthog.emails.EmailError.message`
+
+```python
+message = message
+```
+
+#### `posthog.emails.EmailError.name`
+
+```python
+name = name
+```
+
+#### `posthog.emails.EmailError.retry_after`
+
+```python
+retry_after = retry_after
+```
+
+#### `posthog.emails.EmailError.status_code`
+
+```python
+status_code = status_code
+```
+
+#### `posthog.emails.EmailError.why`
+
+```python
+why = why
+```
+
+### `SendEmailResult`
+
+```python
+SendEmailResult(id: str, replayed: bool = False, warnings: tuple[EmailWarning, ...] = ()) -> None
+```
+
+The queued email. `id` is its message ID.
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`id` | `str` | The email's message ID.
+`replayed` | `bool` | `True` when the response says PostHog replayed an earlier send for the same `idempotency_key` instead of sending again.
+`warnings` | `tuple[EmailWarning, ...]` | Warnings PostHog returned about the request.
+
+#### `posthog.emails.SendEmailResult.id`
+
+```python
+id: str
+```
+
+#### `posthog.emails.SendEmailResult.replayed`
+
+```python
+replayed: bool = False
+```
+
+#### `posthog.emails.SendEmailResult.warnings`
+
+```python
+warnings: tuple[EmailWarning, ...] = ()
+```
+
+### `OptionalSetArgs`
+
+Bases: `TypedDict`
+
+Optional arguments for the set method.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`distinct_id` | | Unique identifier for the user to set properties on. If not set, the context distinct_id is used, if available, otherwise this function does nothing. Setting context-level distinct_id's is recommended. |
+`properties` | | Dictionary of properties to set on the person |
+`timestamp` | | When the properties were set (defaults to current time). UTC is preferred; non-UTC datetimes and parseable ISO timestamp strings are converted to UTC. |
+`uuid` | | Unique identifier for this operation. If not provided, one is generated. This UUID is returned, so you can correlate it with actions in your app. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID. |
+`disable_geoip` | | Whether to disable GeoIP lookup for this operation. Defaults to False. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`disable_geoip` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[ID_TYPES]]` |
+`properties` | `NotRequired[Optional[Dict[str, Any]]]` |
+`timestamp` | `NotRequired[Optional[Union[datetime, str]]]` |
+`uuid` | `NotRequired[Optional[Union[str, UUID]]]` |
+
+#### `posthog.args.OptionalSetArgs.disable_geoip`
+
+```python
+disable_geoip: NotRequired[Optional[bool]]
+```
+
+#### `posthog.args.OptionalSetArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[ID_TYPES]]
+```
+
+#### `posthog.args.OptionalSetArgs.properties`
+
+```python
+properties: NotRequired[Optional[Dict[str, Any]]]
+```
+
+#### `posthog.args.OptionalSetArgs.timestamp`
+
+```python
+timestamp: NotRequired[Optional[Union[datetime, str]]]
+```
+
+#### `posthog.args.OptionalSetArgs.uuid`
+
+```python
+uuid: NotRequired[Optional[Union[str, UUID]]]
+```
+
+### `CodeEmailArgs`
+
+Bases: `_RecipientArgs`
+
+A send of email content that your code rendered for one recipient, named by a key.
+
+The content goes out as is. To send a React email, render it to HTML in
+your app first.
+
+An optional field passed as `None` counts as left out.
+
+**Parameters:**
+
+Name | Type | Description | Default
+---- | ---- | ----------- | -------
+`to` | | One recipient email address. |
+`template_key` | | Names the email, so its metrics, logs and status group under it. Letters, digits, `-` and `_`, at most 400. |
+`subject` | | The subject line. |
+`html` | | The HTML body. Give `html`, `text` or both. |
+`text` | | The plain-text body. Without it, PostHog derives it from `html`. HTML with no text in it, such as a single image, goes out without a plain-text part. |
+`from_` | | A verified sender, such as `"Acme "`. |
+`reply_to` | | One address or a list of addresses. An empty list sends no reply-to. |
+`capture_engagement` | | Capture the email's opens and clicks as events of the recipient. Defaults to `True`. A project whose admin turned engagement capture off captures nothing, whatever the send asks. A template made in PostHog follows the project's setting, so the template form doesn't take it. |
+`distinct_id` | | The recipient's distinct ID in your product. |
+`idempotency_key` | | 1 to 255 visible ASCII characters. Template sends and code sends share one set of keys: a key already used for another email, or for a `template_id` send, raises `idempotency_key_reused`. A retry with the same key returns the first send's result, also when its workflow was paused since. |
+`max_retries` | | Overrides the client's maximum number of retries for this send. `0` turns retries off. |
+
+**Attributes:**
+
+Name | Type | Description
+---- | ---- | -----------
+`capture_engagement` | `NotRequired[Optional[bool]]` |
+`distinct_id` | `NotRequired[Optional[str]]` |
+`from_` | `NotRequired[Optional[str]]` |
+`html` | `NotRequired[Optional[str]]` |
+`idempotency_key` | `NotRequired[Optional[str]]` |
+`max_retries` | `NotRequired[Optional[int]]` |
+`reply_to` | `NotRequired[Optional[Union[str, Sequence[str]]]]` |
+`subject` | `str` |
+`template_key` | `str` |
+`text` | `NotRequired[Optional[str]]` |
+`to` | `str` |
+
+#### `posthog.emails.CodeEmailArgs.capture_engagement`
+
+```python
+capture_engagement: NotRequired[Optional[bool]]
+```
+
+#### `posthog.emails.CodeEmailArgs.distinct_id`
+
+```python
+distinct_id: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.from_`
+
+```python
+from_: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.html`
+
+```python
+html: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.idempotency_key`
+
+```python
+idempotency_key: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.max_retries`
+
+```python
+max_retries: NotRequired[Optional[int]]
+```
+
+#### `posthog.emails.CodeEmailArgs.reply_to`
+
+```python
+reply_to: NotRequired[Optional[Union[str, Sequence[str]]]]
+```
+
+#### `posthog.emails.CodeEmailArgs.subject`
+
+```python
+subject: str
+```
+
+#### `posthog.emails.CodeEmailArgs.template_key`
+
+```python
+template_key: str
+```
+
+#### `posthog.emails.CodeEmailArgs.text`
+
+```python
+text: NotRequired[Optional[str]]
+```
+
+#### `posthog.emails.CodeEmailArgs.to`
+
+```python
+to: str
+```
diff --git a/references/posthog-python-references-6.7.10.json b/references/posthog-python-references-6.7.10.json
deleted file mode 100644
index 4fde4a5f9..000000000
--- a/references/posthog-python-references-6.7.10.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.7.10",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.7.11.json b/references/posthog-python-references-6.7.11.json
deleted file mode 100644
index 0ac5a7dc0..000000000
--- a/references/posthog-python-references-6.7.11.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.7.11",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.7.12.json b/references/posthog-python-references-6.7.12.json
deleted file mode 100644
index c4769c2eb..000000000
--- a/references/posthog-python-references-6.7.12.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.7.12",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.7.13.json b/references/posthog-python-references-6.7.13.json
deleted file mode 100644
index 6b0c973bf..000000000
--- a/references/posthog-python-references-6.7.13.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.7.13",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.7.7.json b/references/posthog-python-references-6.7.7.json
deleted file mode 100644
index 3c24b7463..000000000
--- a/references/posthog-python-references-6.7.7.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.7.7",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.8.0.json b/references/posthog-python-references-6.8.0.json
deleted file mode 100644
index 57c9ab156..000000000
--- a/references/posthog-python-references-6.8.0.json
+++ /dev/null
@@ -1,2343 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.8.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.9.0.json b/references/posthog-python-references-6.9.0.json
deleted file mode 100644
index 2b534b2d4..000000000
--- a/references/posthog-python-references-6.9.0.json
+++ /dev/null
@@ -1,2430 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.9.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.capture(\n 'event_name',\n distinct_id='user-distinct-id',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- },
- {
- "id": "example_2",
- "name": "Set using context",
- "code": "# Set using context\nfrom posthog import new_context, identify_context\nwith new_context():\n identify_context('user-distinct-id')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.9.1.json b/references/posthog-python-references-6.9.1.json
deleted file mode 100644
index eb26f3aec..000000000
--- a/references/posthog-python-references-6.9.1.json
+++ /dev/null
@@ -1,2425 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.9.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-6.9.2.json b/references/posthog-python-references-6.9.2.json
deleted file mode 100644
index f1a1625d6..000000000
--- a/references/posthog-python-references-6.9.2.json
+++ /dev/null
@@ -1,2425 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "6.9.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.0.0.json b/references/posthog-python-references-7.0.0.json
deleted file mode 100644
index 53d2ccdb2..000000000
--- a/references/posthog-python-references-7.0.0.json
+++ /dev/null
@@ -1,2425 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.0.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.0.1.json b/references/posthog-python-references-7.0.1.json
deleted file mode 100644
index fc608f585..000000000
--- a/references/posthog-python-references-7.0.1.json
+++ /dev/null
@@ -1,2425 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.0.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user by calling decide.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.14.0.json b/references/posthog-python-references-7.14.0.json
deleted file mode 100644
index 955b57dd4..000000000
--- a/references/posthog-python-references-7.14.0.json
+++ /dev/null
@@ -1,2725 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.14.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.14.1.json b/references/posthog-python-references-7.14.1.json
deleted file mode 100644
index 2dd4000c1..000000000
--- a/references/posthog-python-references-7.14.1.json
+++ /dev/null
@@ -1,2725 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.14.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.15.0.json b/references/posthog-python-references-7.15.0.json
deleted file mode 100644
index 988ba4105..000000000
--- a/references/posthog-python-references-7.15.0.json
+++ /dev/null
@@ -1,2725 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.15.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "The project API key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "The host to use for the client.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Whether to enable debug mode.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()`",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled Example: ```python result = posthog.get_feature_flag_result('beta-feature', 'distinct_id') if result and result.enabled: # Use the variant and payload print(f\"Variant: {result.variant}\") print(f\"Payload: {result.payload}\") ```",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Set whether code variables are captured for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Variable names matching these patterns will be ignored completely when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "ignore_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Variable names matching these patterns will be masked with *** when capturing code variables.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "mask_patterns",
- "description": "",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import capture\ncapture(\n 'distinct_id',\n event='event_name',\n properties={\n '$set': {'name': 'Max Hedgehog'},\n '$set_once': {'initial_url': '/blog'}\n }\n)"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.15.1.json b/references/posthog-python-references-7.15.1.json
deleted file mode 100644
index 0977aaa79..000000000
--- a/references/posthog-python-references-7.15.1.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.15.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. Raises: ValueError: If ``api_key`` has not been configured.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.15.3.json b/references/posthog-python-references-7.15.3.json
deleted file mode 100644
index e75be17ec..000000000
--- a/references/posthog-python-references-7.15.3.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.15.3",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. Raises: ValueError: If ``api_key`` has not been configured.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.15.4.json b/references/posthog-python-references-7.15.4.json
deleted file mode 100644
index a659d92e1..000000000
--- a/references/posthog-python-references-7.15.4.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.15.4",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. Raises: ValueError: If ``api_key`` has not been configured.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.16.0.json b/references/posthog-python-references-7.16.0.json
deleted file mode 100644
index b56a23512..000000000
--- a/references/posthog-python-references-7.16.0.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.16.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. Raises: ValueError: If ``api_key`` has not been configured.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.16.1.json b/references/posthog-python-references-7.16.1.json
deleted file mode 100644
index 62220ced4..000000000
--- a/references/posthog-python-references-7.16.1.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.16.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. Raises: ValueError: If ``api_key`` has not been configured.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.16.2.json b/references/posthog-python-references-7.16.2.json
deleted file mode 100644
index 2fc1c0bbe..000000000
--- a/references/posthog-python-references-7.16.2.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.16.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.16.3.json b/references/posthog-python-references-7.16.3.json
deleted file mode 100644
index 48408c622..000000000
--- a/references/posthog-python-references-7.16.3.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.16.3",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.16.4.json b/references/posthog-python-references-7.16.4.json
deleted file mode 100644
index fea4c0708..000000000
--- a/references/posthog-python-references-7.16.4.json
+++ /dev/null
@@ -1,2912 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.16.4",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.17.0.json b/references/posthog-python-references-7.17.0.json
deleted file mode 100644
index 18b1d67ff..000000000
--- a/references/posthog-python-references-7.17.0.json
+++ /dev/null
@@ -1,2918 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.17.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.18.0.json b/references/posthog-python-references-7.18.0.json
deleted file mode 100644
index 9f690ab24..000000000
--- a/references/posthog-python-references-7.18.0.json
+++ /dev/null
@@ -1,2918 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.18.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.18.1.json b/references/posthog-python-references-7.18.1.json
deleted file mode 100644
index 3e6ffe884..000000000
--- a/references/posthog-python-references-7.18.1.json
+++ /dev/null
@@ -1,2924 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.18.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.18.2.json b/references/posthog-python-references-7.18.2.json
deleted file mode 100644
index 3f06fd7e3..000000000
--- a/references/posthog-python-references-7.18.2.json
+++ /dev/null
@@ -1,2924 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.18.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.18.3.json b/references/posthog-python-references-7.18.3.json
deleted file mode 100644
index e3e8c526a..000000000
--- a/references/posthog-python-references-7.18.3.json
+++ /dev/null
@@ -1,2924 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.18.3",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.19.0.json b/references/posthog-python-references-7.19.0.json
deleted file mode 100644
index efe2ea4bc..000000000
--- a/references/posthog-python-references-7.19.0.json
+++ /dev/null
@@ -1,2948 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.19.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.19.1.json b/references/posthog-python-references-7.19.1.json
deleted file mode 100644
index 153a5a63d..000000000
--- a/references/posthog-python-references-7.19.1.json
+++ /dev/null
@@ -1,2948 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.19.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.19.2.json b/references/posthog-python-references-7.19.2.json
deleted file mode 100644
index d7130b76f..000000000
--- a/references/posthog-python-references-7.19.2.json
+++ /dev/null
@@ -1,2948 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.19.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Optional[str]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context.",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with posthog.new_context():\n identify_context('')\n posthog.capture('event_name')"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context (default: True)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking (default: True)",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.0.json b/references/posthog-python-references-7.20.0.json
deleted file mode 100644
index e192cb541..000000000
--- a/references/posthog-python-references-7.20.0.json
+++ /dev/null
@@ -1,3093 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.1.json b/references/posthog-python-references-7.20.1.json
deleted file mode 100644
index b1e79399d..000000000
--- a/references/posthog-python-references-7.20.1.json
+++ /dev/null
@@ -1,3093 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "dict[str, str]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "dict"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, FeatureFlag]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlag]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "any"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.2.json b/references/posthog-python-references-7.20.2.json
deleted file mode 100644
index 289a7a6b2..000000000
--- a/references/posthog-python-references-7.20.2.json
+++ /dev/null
@@ -1,3120 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.3.json b/references/posthog-python-references-7.20.3.json
deleted file mode 100644
index 428eace96..000000000
--- a/references/posthog-python-references-7.20.3.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.3",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.4.json b/references/posthog-python-references-7.20.4.json
deleted file mode 100644
index b27b6d731..000000000
--- a/references/posthog-python-references-7.20.4.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.4",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.20.5.json b/references/posthog-python-references-7.20.5.json
deleted file mode 100644
index 0c562d176..000000000
--- a/references/posthog-python-references-7.20.5.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.20.5",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.21.0.json b/references/posthog-python-references-7.21.0.json
deleted file mode 100644
index 426559d05..000000000
--- a/references/posthog-python-references-7.21.0.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.21.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.21.1.json b/references/posthog-python-references-7.21.1.json
deleted file mode 100644
index 7225b2655..000000000
--- a/references/posthog-python-references-7.21.1.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.21.1",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.21.2.json b/references/posthog-python-references-7.21.2.json
deleted file mode 100644
index 0c13d2ee4..000000000
--- a/references/posthog-python-references-7.21.2.json
+++ /dev/null
@@ -1,3147 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.21.2",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Personal API key used for local feature flag evaluation and remote config payloads.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='')"
- }
- ]
- },
- {
- "id": "alias",
- "title": "alias",
- "description": "Create an alias between two distinct IDs.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The previous distinct ID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The new distinct ID to alias to.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.alias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Captures an event manually. [Learn about capture best practices](https://posthog.com/docs/product-analytics/capture-events)",
- "details": "",
- "category": "Capture",
- "params": [
- {
- "name": "event",
- "description": "The event name to capture.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Anonymous event",
- "code": "# Anonymous event\nposthog.capture('some-anon-event')"
- },
- {
- "id": "example_2",
- "name": "Context usage",
- "code": "# Context usage\nfrom posthog import identify_context, new_context\nwith new_context():\n identify_context('distinct_id_of_the_user')\n posthog.capture('user_signed_up')\n posthog.capture('user_logged_in')\n posthog.capture('some-custom-action', distinct_id='distinct_id_of_the_user')"
- },
- {
- "id": "example_3",
- "name": "Set event properties",
- "code": "# Set event properties\nposthog.capture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- },
- {
- "id": "example_4",
- "name": "Page view event",
- "code": "# Page view event\nposthog.capture('$pageview', distinct_id=\"distinct_id_of_the_user\", properties={'$current_url': 'https://example.com'})"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture an exception for error tracking.",
- "details": "",
- "category": "Error Tracking",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture.",
- "isOptional": true,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "try:\n # Some code that might fail\n pass\nexcept Exception as e:\n posthog.capture_exception(e, 'user_distinct_id', properties=additional_properties)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to :meth:`capture` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request. Local evaluation is transparent: when the poller resolves a flag, the snapshot's ``$feature_flag_called`` events are tagged ``locally_evaluated=True`` and reason ``\"Evaluated locally\"``.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If True, never fall back to remote evaluation \u2014 flags that can't be evaluated locally are simply omitted from the snapshot.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys to scope the underlying ``/flags`` request to a subset.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flags = posthog.evaluate_flags(\n \"user_123\",\n person_properties={\"plan\": \"enterprise\"},\n)\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\nposthog.capture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Check if a feature flag is enabled for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Return feature flag definitions loaded for local evaluation. Returns: The currently loaded feature flag definitions, or ``None`` before local evaluation has loaded definitions.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.capture('event_name')\nposthog.flush() # Ensures the event is sent immediately"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all feature flags for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flags and their payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.get_all_flags_and_payloads('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get multivariate feature flag value for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "enabled_variant = posthog.get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload for a feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "The specific flag value to get payload for.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Deprecated. Use get_feature_flag() instead if you need events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "is_my_flag_enabled = posthog.feature_enabled('flag-key', 'distinct_id_of_your_user')\n\nif is_my_flag_enabled:\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = posthog.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely depending on whether local evaluation is enabled and the flag can be locally evaluated. This also captures the `$feature_flag_called` event unless `send_feature_flag_events` is `False`.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to only evaluate locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "flag_result = posthog.get_feature_flag_result('flag-key', 'distinct_id_of_your_user')\nif flag_result and flag_result.get_value() == 'variant-key':\n # Do something differently for this user\n # Optional: fetch the payload\n matched_flag_payload = flag_result.payload"
- }
- ]
- },
- {
- "id": "get_feature_flags_and_payloads",
- "title": "get_feature_flags_and_payloads",
- "description": "Get feature flags and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "result = posthog.get_feature_flags_and_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_payloads",
- "title": "get_feature_payloads",
- "description": "Get feature flag payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "payloads = posthog.get_feature_payloads('')"
- }
- ]
- },
- {
- "id": "get_feature_variants",
- "title": "get_feature_variants",
- "description": "Get feature flag variants for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Union[bool, str]]"
- }
- },
- {
- "id": "get_flags_decision",
- "title": "get_flags_decision",
- "description": "Get feature flags decision.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "A dictionary of group information.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "A dictionary of person properties.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "A dictionary of group properties.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this request.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "A list of specific flag keys to evaluate. If provided, only these flags will be evaluated, improving performance.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "The device ID for this request.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsResponse"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "decision = posthog.get_flags_decision('user123')"
- }
- ]
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The remote config feature flag key.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Identify a group and set its properties.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "The type of group (e.g., 'company', 'team').",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "The unique identifier for the group.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "A dictionary of properties to set on the group.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "The timestamp of the event.",
- "isOptional": false,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "A unique identifier for the event. If provided, it must be a valid UUID string or uuid.UUID instance; invalid values are ignored and replaced with a newly generated UUID.",
- "isOptional": false,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP for this event.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "The distinct ID of the user performing the action.",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.group_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "join",
- "title": "join",
- "description": "End the consumer thread once the queue is empty. Do not use directly, call `shutdown()` instead.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.join()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flags for local evaluation.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.load_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context for managing shared state. Learn more about [contexts](/docs/libraries/python#contexts).",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "with client.new_context():\n client.identify_context('')\n client.capture('event_name')"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the wrapped function using this client.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to create a fresh context that doesn't inherit from parent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to automatically capture exceptions in this context. If omitted, defaults to this client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a person profile.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set with distinct id",
- "code": "# Set with distinct id\nposthog.set(distinct_id='user123', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a person profile only if they haven't been set before.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.set_once(distinct_id='user123', properties={'initial_signup_date': '2024-01-01'})"
- }
- ]
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss.",
- "details": "",
- "category": null,
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "posthog.shutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value.",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- }
- }
- ]
- },
- {
- "id": "PostHogModule",
- "title": "PostHog Module Functions",
- "description": "Global functions available in the PostHog module",
- "functions": [
- {
- "id": "alias",
- "title": "alias",
- "description": "Associate user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "details": "To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like \"Which marketing channels leads to users churning after a month?\" or \"What do users do on our website before signing up?\". Particularly useful for associating user behaviour before and after they e.g. register, login, or perform some other identifying action.",
- "category": "Identification",
- "params": [
- {
- "name": "previous_id",
- "description": "The unique ID of the user before",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The current unique id",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Alias user",
- "code": "# Alias user\nfrom posthog import alias\nalias(previous_id='distinct_id', distinct_id='alias_id')"
- }
- ]
- },
- {
- "id": "capture",
- "title": "capture",
- "description": "Capture anything a user does within your system.",
- "details": "Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. A capture call requires an event name to specify the event. We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. Capture takes a number of optional arguments, which are defined by the `OptionalCaptureArgs` type.",
- "category": "Events",
- "params": [
- {
- "name": "event",
- "description": "The event name to specify the event **kwargs: Optional arguments including:",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Context and capture usage",
- "code": "# Context and capture usage\nfrom posthog import new_context, identify_context, tag_context, capture\n# Enter a new context (e.g. a request/response cycle, an instance of a background job, etc)\nwith new_context():\n # Associate this context with some user, by distinct_id\n identify_context('some user')\n\n # Capture an event, associated with the context-level distinct ID ('some user')\n capture('movie started')\n\n # Capture an event associated with some other user (overriding the context-level distinct ID)\n capture('movie joined', distinct_id='some-other-user')\n\n # Capture an event with some properties\n capture('movie played', properties={'movie_id': '123', 'category': 'romcom'})\n\n # Capture an event with some properties\n capture('purchase', properties={'product_id': '123', 'category': 'romcom'})\n # Capture an event with some associated group\n capture('purchase', groups={'company': 'id:5'})\n\n # Adding a tag to the current context will cause it to appear on all subsequent events\n tag_context('some-tag', 'some-value')\n\n capture('another-event') # Will be captured with `'some-tag': 'some-value'` in the properties dict"
- },
- {
- "id": "example_2",
- "name": "Set event properties",
- "code": "# Set event properties\nfrom posthog import capture\ncapture(\n \"user_signed_up\",\n distinct_id=\"distinct_id_of_the_user\",\n properties={\n \"login_type\": \"email\",\n \"is_free_trial\": \"true\"\n }\n)"
- }
- ]
- },
- {
- "id": "capture_exception",
- "title": "capture_exception",
- "description": "Capture exceptions that happen in your code.",
- "details": "Capture exception is idempotent - if it is called twice with the same exception instance, only a occurrence will be tracked in posthog. This is because, generally, contexts will cause exceptions to be captured automatically. However, to ensure you track an exception, if you catch and do not re-raise it, capturing it manually is recommended, unless you are certain it will have crossed a context boundary (e.g. by existing a `with posthog.new_context():` block already). If the passed exception was raised and caught, the captured stack trace will consist of every frame between where the exception was raised and the point at which it is captured (the \"traceback\"). If the passed exception was never raised, e.g. if you call `posthog.capture_exception(ValueError(\"Some Error\"))`, the stack trace captured will be the full stack trace at the moment the exception was captured. Note that heavy use of contexts will lead to truncated stack traces, as the exception will be captured by the context entered most recently, which may not be the point you catch the exception for the final time in your code. It's recommended to use contexts sparingly, for this reason. `capture_exception` takes the same set of optional arguments as `capture`.",
- "category": "Events",
- "params": [
- {
- "name": "exception",
- "description": "The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.",
- "isOptional": false,
- "type": "BaseException"
- },
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalCaptureArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Capture exception",
- "code": "# Capture exception\nfrom posthog import capture_exception\ntry:\n risky_operation()\nexcept Exception as e:\n capture_exception(e)"
- }
- ]
- },
- {
- "id": "evaluate_flags",
- "title": "evaluate_flags",
- "description": "Evaluate all feature flags for a user in a single call and return a :class:`FeatureFlagEvaluations` snapshot. Branch on ``.is_enabled()`` / ``.get_flag()`` and pass the same snapshot to ``capture()`` via the ``flags`` option so events carry the exact flag values the code branched on. Prefer this over repeated ``get_feature_flag()`` calls and over ``capture(send_feature_flags=True)`` \u2014 it consolidates flag evaluation into a single ``/flags`` request per incoming request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID. If ``None``, falls back to the context distinct_id. If still unresolvable, returns an empty snapshot.",
- "isOptional": false,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "If ``True``, never fall back to remote evaluation.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "flag_keys",
- "description": "Optional list of flag keys. When provided, only these flags are evaluated \u2014 the underlying ``/flags`` request asks the server for just this subset, which makes the response smaller and the request cheaper. Use this when you only need a handful of flags out of many.",
- "isOptional": true,
- "type": "list[str]"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override. If not provided, falls back to the context device_id (which may be set via tracing headers). Used by experience-continuity flags to match users across distinct_id changes.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FeatureFlagEvaluations"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import evaluate_flags, capture\nflags = evaluate_flags(\"user_123\", person_properties={\"plan\": \"enterprise\"})\nif flags.is_enabled(\"new-dashboard\"):\n render_new_dashboard()\ncapture(\"page_viewed\", distinct_id=\"user_123\", flags=flags)"
- }
- ]
- },
- {
- "id": "feature_enabled",
- "title": "feature_enabled",
- "description": "Use feature flags to enable or disable features for users.",
- "details": "You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[bool]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Boolean feature flag",
- "code": "# Boolean feature flag\nfrom posthog import feature_enabled, get_feature_flag_payload\nis_my_flag_enabled = feature_enabled('flag-key', 'distinct_id_of_your_user')\nif is_my_flag_enabled:\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "feature_flag_definitions",
- "title": "feature_flag_definitions",
- "description": "Returns loaded feature flags.",
- "details": "Returns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import feature_flag_definitions\ndefinitions = feature_flag_definitions()"
- }
- ]
- },
- {
- "id": "flush",
- "title": "flush",
- "description": "Tell the client to flush all queued events.",
- "details": "",
- "category": "Client management",
- "params": [
- {
- "name": "timeout_seconds",
- "description": "Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.",
- "isOptional": true,
- "type": "float"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import flush\nflush()"
- }
- ]
- },
- {
- "id": "get_all_flags",
- "title": "get_all_flags",
- "description": "Get all flags for a given user.",
- "details": "Flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate (evaluates all if None)",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[dict[str, Union[bool, str]]]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "All flags for user",
- "code": "# All flags for user\nfrom posthog import get_all_flags\nget_all_flags('distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_all_flags_and_payloads",
- "title": "get_all_flags_and_payloads",
- "description": "Get all feature flag values and payloads for a user.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "flag_keys_to_evaluate",
- "description": "Optional list of flag keys to evaluate. Evaluates all flags when omitted.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "FlagsAndPayloads"
- }
- },
- {
- "id": "get_feature_flag",
- "title": "get_feature_flag",
- "description": "Get feature flag variant for users. Used with experiments.",
- "details": "`groups` are a mapping from group type to group key. So, if you have a group type of \"organization\" and a group key of \"5\", you would pass groups={\"organization\": \"5\"}. `group_properties` take the format: { group_type_name: { group_properties } }. So, for example, if you have the group type \"organization\" and the group key \"5\", with the properties name, and employee count, you'll send these as: group_properties={\"organization\": {\"name\": \"PostHog\", \"employees\": 11}}.",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Groups mapping from group type to group key",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties in format { group_type_name: { group_properties } }",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send feature flag events",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Union[bool, str, any]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Multivariate feature flag",
- "code": "# Multivariate feature flag\nfrom posthog import get_feature_flag, get_feature_flag_payload\nenabled_variant = get_feature_flag('flag-key', 'distinct_id_of_your_user')\nif enabled_variant == 'variant-key':\n matched_flag_payload = get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')"
- }
- ]
- },
- {
- "id": "get_feature_flag_payload",
- "title": "get_feature_flag_payload",
- "description": "Get the payload associated with a feature flag value. Deprecated for new code. Prefer ``evaluate_flags()`` and ``flags.get_flag_payload(key)`` so flag evaluation happens once per request.",
- "details": "",
- "category": "Feature flags",
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "match_value",
- "description": "Optional flag value to use when selecting a payload.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[object]"
- }
- },
- {
- "id": "get_feature_flag_result",
- "title": "get_feature_flag_result",
- "description": "Get a FeatureFlagResult object which contains the flag result and payload. This method evaluates a feature flag and returns a FeatureFlagResult object containing: - enabled: Whether the flag is enabled - variant: The variant value if the flag has variants - payload: The payload associated with the flag (automatically deserialized from JSON) - key: The flag key - reason: Why the flag was enabled/disabled",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The feature flag key.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "distinct_id",
- "description": "The user's distinct ID.",
- "isOptional": true,
- "type": "Number"
- },
- {
- "name": "groups",
- "description": "Mapping of group type to group key.",
- "isOptional": true,
- "type": "Mapping[str, Union[str, int]]"
- },
- {
- "name": "person_properties",
- "description": "Person properties to use for evaluation.",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "group_properties",
- "description": "Group properties keyed by group type.",
- "isOptional": true,
- "type": "dict[str, dict[str, Any]]"
- },
- {
- "name": "only_evaluate_locally",
- "description": "Whether to evaluate only locally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "send_feature_flag_events",
- "description": "Whether to send a $feature_flag_called event.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "device_id",
- "description": "Optional device ID override for experience-continuity flags.",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[FeatureFlagResult]"
- }
- },
- {
- "id": "get_remote_config_payload",
- "title": "get_remote_config_payload",
- "description": "Get the payload for a remote config feature flag.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "key",
- "description": "The key of the feature flag",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "get_tags",
- "title": "get_tags",
- "description": "Get all tags from the current context. Returns: Dict of all tags in the current context",
- "details": "",
- "category": "Contexts",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "dict[str, Any]"
- }
- },
- {
- "id": "group_identify",
- "title": "group_identify",
- "description": "Set properties on a group.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "group_type",
- "description": "Type of your group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "group_key",
- "description": "Unique identifier of the group",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "properties",
- "description": "Properties to set on the group",
- "isOptional": true,
- "type": "dict[str, Any]"
- },
- {
- "name": "timestamp",
- "description": "Optional timestamp for the event",
- "isOptional": true,
- "type": "datetime"
- },
- {
- "name": "uuid",
- "description": "Optional UUID for the event",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable GeoIP lookup",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "distinct_id",
- "description": "Optional distinct ID of the user performing the action",
- "isOptional": false,
- "type": "Number"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Group identify",
- "code": "# Group identify\nfrom posthog import group_identify\ngroup_identify('company', 'company_id_in_your_db', {\n 'name': 'Awesome Inc.',\n 'employees': 11\n})"
- }
- ]
- },
- {
- "id": "identify_context",
- "title": "identify_context",
- "description": "Identify the current context with a distinct ID.",
- "details": "",
- "category": "Identification",
- "params": [
- {
- "name": "distinct_id",
- "description": "The distinct ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import identify_context\nidentify_context(\"user_123\")"
- }
- ]
- },
- {
- "id": "join",
- "title": "join",
- "description": "Block program until the client clears the queue. Used during program shutdown. You should use `shutdown()` directly in most cases.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import join\njoin()"
- }
- ]
- },
- {
- "id": "load_feature_flags",
- "title": "load_feature_flags",
- "description": "Load feature flag definitions from PostHog.",
- "details": "",
- "category": "Feature flags",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import load_feature_flags\nload_feature_flags()"
- }
- ]
- },
- {
- "id": "new_context",
- "title": "new_context",
- "description": "Create a new context scope that will be active for the duration of the with block.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture exceptions raised within the context. If omitted, defaults to the relevant client's exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- },
- {
- "name": "client",
- "description": "Optional Posthog client instance to use for this context (default: None)",
- "isOptional": true,
- "type": "Client"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import new_context, tag, capture\nwith new_context():\n tag(\"request_id\", \"123\")\n capture(\"event_name\", properties={\"property\": \"value\"})"
- }
- ]
- },
- {
- "id": "scoped",
- "title": "scoped",
- "description": "Decorator that creates a new context for the function.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "fresh",
- "description": "Whether to start with a fresh context (default: False)",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "capture_exceptions",
- "description": "Whether to capture and track exceptions with posthog error tracking. If omitted, defaults to the global exception autocapture setting.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import scoped, tag, capture\n@scoped()\ndef process_payment(payment_id):\n tag(\"payment_id\", payment_id)\n capture(\"payment_started\")"
- }
- ]
- },
- {
- "id": "set",
- "title": "set",
- "description": "Set properties on a user record.",
- "details": "This will overwrite previous people property values. Generally operates similar to `capture`, with distinct_id being an optional argument, defaulting to the current context's distinct ID. If there is no context-level distinct ID, and no override distinct_id is passed, this function will do nothing. Context tags are folded into $set properties, so tagging the current context and then calling `set` will cause those tags to be set on the user (unlike capture, which causes them to just be set on the event).",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set person properties",
- "code": "# Set person properties\nfrom posthog import set\nset(distinct_id='distinct_id', properties={'name': 'Max Hedgehog'})"
- }
- ]
- },
- {
- "id": "set_capture_exception_code_variables_context",
- "title": "set_capture_exception_code_variables_context",
- "description": "Override code-variable capture for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "Whether exceptions captured in this context should include local variable values from stack frames.",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_detect_secrets_context",
- "title": "set_code_variables_detect_secrets_context",
- "description": "Whether to apply entropy-based secret detection as a last-resort redaction of high-entropy values (API keys, tokens, strong passwords) in captured code variables for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_ignore_patterns_context",
- "title": "set_code_variables_ignore_patterns_context",
- "description": "Override code-variable ignore patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "ignore_patterns",
- "description": "Variable-name patterns that should be omitted entirely when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_patterns_context",
- "title": "set_code_variables_mask_patterns_context",
- "description": "Override code-variable mask patterns for exceptions in the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "mask_patterns",
- "description": "Variable-name patterns whose values should be replaced with ``***`` when code variables are captured.",
- "isOptional": true,
- "type": "list[str]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_code_variables_mask_url_credentials_context",
- "title": "set_code_variables_mask_url_credentials_context",
- "description": "Whether to scrub credentials embedded in URLs/DSNs (e.g. user:pass@host) from captured code variables for the current context.",
- "details": "",
- "category": null,
- "params": [
- {
- "name": "enabled",
- "description": "",
- "isOptional": true,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- }
- },
- {
- "id": "set_context_device_id",
- "title": "set_context_device_id",
- "description": "Set the device ID for the current context, associating all feature flag requests in this or child contexts with the given device ID.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "device_id",
- "description": "The device ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_device_id\nset_context_device_id(\"device_123\")"
- }
- ]
- },
- {
- "id": "set_context_session",
- "title": "set_context_session",
- "description": "Set the session ID for the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "session_id",
- "description": "The session ID to associate with the current context and its children",
- "isOptional": true,
- "type": "str"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import set_context_session\nset_context_session(\"session_123\")"
- }
- ]
- },
- {
- "id": "set_once",
- "title": "set_once",
- "description": "Set properties on a user record, only if they do not yet exist.",
- "details": "This will not overwrite previous people property values, unlike `set`. Otherwise, operates in an identical manner to `set`.",
- "category": "Identification",
- "params": [
- {
- "name": "kwargs",
- "description": "",
- "isOptional": true,
- "type": "Unpack[OptionalSetArgs]"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Optional[str]"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Set property once",
- "code": "# Set property once\nfrom posthog import set_once\nset_once(distinct_id='distinct_id', properties={'initial_url': '/blog'})"
- }
- ]
- },
- {
- "id": "setup",
- "title": "setup",
- "description": "Create or return the global PostHog client configured by module settings. Most applications should either instantiate ``Posthog`` directly or set ``posthog.api_key``/other module settings before calling top-level helpers. ``setup()`` is called automatically by global APIs such as ``capture()``. Returns: The global ``Client`` instance. If ``api_key`` is missing or blank, the client is disabled and module-level calls become no-ops.",
- "details": "",
- "category": "Initialization",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "Client"
- }
- },
- {
- "id": "shutdown",
- "title": "shutdown",
- "description": "Flush all messages and cleanly shutdown the client.",
- "details": "",
- "category": "Client management",
- "params": [],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "any"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import shutdown\nshutdown()"
- }
- ]
- },
- {
- "id": "tag",
- "title": "tag",
- "description": "Add a tag to the current context.",
- "details": "",
- "category": "Contexts",
- "params": [
- {
- "name": "name",
- "description": "The tag key",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "value",
- "description": "The tag value",
- "isOptional": true,
- "type": "Any"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import tag\ntag(\"user_id\", \"123\")"
- }
- ]
- }
- ]
- }
- ],
- "categories": [
- "Initialization",
- "Identification",
- "Capture",
- "Error Tracking",
- "Feature flags",
- "Contexts",
- "Events",
- "Client management"
- ]
-}
\ No newline at end of file
diff --git a/references/posthog-python-references-7.22.0.json b/references/posthog-python-references-7.22.0.json
deleted file mode 100644
index 984f0031a..000000000
--- a/references/posthog-python-references-7.22.0.json
+++ /dev/null
@@ -1,3171 +0,0 @@
-{
- "id": "posthog-python",
- "hogRef": "0.3",
- "info": {
- "version": "7.22.0",
- "id": "posthog-python",
- "title": "PostHog Python SDK",
- "description": "Integrate PostHog into any python application.",
- "slugPrefix": "posthog-python",
- "specUrl": "https://github.com/PostHog/posthog-python"
- },
- "types": [
- {
- "id": "FeatureFlag",
- "name": "FeatureFlag",
- "path": "posthog.types.FeatureFlag",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "reason",
- "type": "Optional[FlagReason]",
- "description": "Field: reason"
- },
- {
- "name": "metadata",
- "type": "Union[FlagMetadata, LegacyFlagMetadata]",
- "description": "Field: metadata"
- }
- ],
- "example": ""
- },
- {
- "id": "FeatureFlagResult",
- "name": "FeatureFlagResult",
- "path": "posthog.types.FeatureFlagResult",
- "properties": [
- {
- "name": "key",
- "type": "str",
- "description": "Field: key"
- },
- {
- "name": "enabled",
- "type": "bool",
- "description": "Field: enabled"
- },
- {
- "name": "variant",
- "type": "Optional[str]",
- "description": "Field: variant"
- },
- {
- "name": "payload",
- "type": "Optional[Any]",
- "description": "Field: payload"
- },
- {
- "name": "reason",
- "type": "Optional[str]",
- "description": "Field: reason"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagMetadata",
- "name": "FlagMetadata",
- "path": "posthog.types.FlagMetadata",
- "properties": [
- {
- "name": "id",
- "type": "int",
- "description": "Field: id"
- },
- {
- "name": "payload",
- "type": "Optional[str]",
- "description": "Field: payload"
- },
- {
- "name": "version",
- "type": "int",
- "description": "Field: version"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagReason",
- "name": "FlagReason",
- "path": "posthog.types.FlagReason",
- "properties": [
- {
- "name": "code",
- "type": "str",
- "description": "Field: code"
- },
- {
- "name": "condition_index",
- "type": "Optional[int]",
- "description": "Field: condition_index"
- },
- {
- "name": "description",
- "type": "str",
- "description": "Field: description"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsAndPayloads",
- "name": "FlagsAndPayloads",
- "path": "posthog.types.FlagsAndPayloads",
- "properties": [
- {
- "name": "featureFlags",
- "type": "Optional[dict[str, Union[bool, str]]]",
- "description": "Field: featureFlags"
- },
- {
- "name": "featureFlagPayloads",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: featureFlagPayloads"
- }
- ],
- "example": ""
- },
- {
- "id": "FlagsResponse",
- "name": "FlagsResponse",
- "path": "posthog.types.FlagsResponse",
- "properties": [
- {
- "name": "flags",
- "type": "dict[str, FeatureFlag]",
- "description": "Field: flags"
- },
- {
- "name": "errorsWhileComputingFlags",
- "type": "bool",
- "description": "Field: errorsWhileComputingFlags"
- },
- {
- "name": "requestId",
- "type": "str",
- "description": "Field: requestId"
- },
- {
- "name": "quotaLimit",
- "type": "Optional[list[str]]",
- "description": "Field: quotaLimit"
- },
- {
- "name": "evaluatedAt",
- "type": "Optional[int]",
- "description": "Field: evaluatedAt"
- }
- ],
- "example": ""
- },
- {
- "id": "LegacyFlagMetadata",
- "name": "LegacyFlagMetadata",
- "path": "posthog.types.LegacyFlagMetadata",
- "properties": [
- {
- "name": "payload",
- "type": "Any",
- "description": "Field: payload"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalCaptureArgs",
- "name": "OptionalCaptureArgs",
- "path": "posthog.args.OptionalCaptureArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "groups",
- "type": "NotRequired[Optional[dict[str, str]]]",
- "description": "Field: groups"
- },
- {
- "name": "flags",
- "type": "NotRequired[Optional[ForwardRef('FeatureFlagEvaluations')]]",
- "description": "Field: flags"
- },
- {
- "name": "send_feature_flags",
- "type": "NotRequired[Union[bool, SendFeatureFlagsOptions, any]]",
- "description": "Field: send_feature_flags"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "OptionalSetArgs",
- "name": "OptionalSetArgs",
- "path": "posthog.args.OptionalSetArgs",
- "properties": [
- {
- "name": "distinct_id",
- "type": "NotRequired[Union[Number, str, UUID, int, any]]",
- "description": "Field: distinct_id"
- },
- {
- "name": "properties",
- "type": "NotRequired[Optional[dict[str, Any]]]",
- "description": "Field: properties"
- },
- {
- "name": "timestamp",
- "type": "NotRequired[Union[datetime, str, any]]",
- "description": "Field: timestamp"
- },
- {
- "name": "uuid",
- "type": "NotRequired[Union[str, UUID, any]]",
- "description": "Field: uuid"
- },
- {
- "name": "disable_geoip",
- "type": "NotRequired[Optional[bool]]",
- "description": "Field: disable_geoip"
- }
- ],
- "example": ""
- },
- {
- "id": "SendFeatureFlagsOptions",
- "name": "SendFeatureFlagsOptions",
- "path": "posthog.types.SendFeatureFlagsOptions",
- "properties": [
- {
- "name": "should_send",
- "type": "bool",
- "description": "Field: should_send"
- },
- {
- "name": "only_evaluate_locally",
- "type": "Optional[bool]",
- "description": "Field: only_evaluate_locally"
- },
- {
- "name": "person_properties",
- "type": "Optional[dict[str, Any]]",
- "description": "Field: person_properties"
- },
- {
- "name": "group_properties",
- "type": "Optional[dict[str, dict[str, Any]]]",
- "description": "Field: group_properties"
- },
- {
- "name": "flag_keys_filter",
- "type": "Optional[list[str]]",
- "description": "Field: flag_keys_filter"
- }
- ],
- "example": ""
- }
- ],
- "classes": [
- {
- "id": "PostHog",
- "title": "PostHog",
- "description": "This is the SDK reference for the PostHog Python SDK. You can learn more about example usage in the [Python SDK documentation](/docs/libraries/python). You can also follow [Flask](/docs/libraries/flask) and [Django](/docs/libraries/django) guides to integrate PostHog into your project. For long-running applications, create one client during application startup and reuse it for the lifetime of the process. This keeps background queues predictable and makes shutdown flushing straightforward. Multiple clients are still supported for intentional multi-project or multi-host setups.",
- "functions": [
- {
- "id": "__init__",
- "title": "Client",
- "description": "Initialize a new PostHog client instance.",
- "details": "",
- "category": "Initialization",
- "params": [
- {
- "name": "project_api_key",
- "description": "PostHog project API key/token.",
- "isOptional": true,
- "type": "str"
- },
- {
- "name": "host",
- "description": "PostHog host. Defaults to the US ingestion endpoint when not set. App hosts such as ``https://us.posthog.com`` are mapped to the corresponding ingestion host.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "debug",
- "description": "Enable verbose SDK logging and re-raise errors from public API methods.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_queue_size",
- "description": "Maximum number of events buffered before upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "send",
- "description": "If False, queueing succeeds but events are not sent.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "on_error",
- "description": "Optional callback invoked by background consumers when an upload fails.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flush_at",
- "description": "Number of queued events that triggers a batch upload.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "flush_interval",
- "description": "Maximum seconds a background consumer waits before flushing a partial batch.",
- "isOptional": false,
- "type": "float"
- },
- {
- "name": "gzip",
- "description": "Whether to gzip event upload payloads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "max_retries",
- "description": "Number of upload retries for background consumers.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "sync_mode",
- "description": "If True, send each event synchronously instead of using background worker threads.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "timeout",
- "description": "HTTP request timeout in seconds for event uploads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "thread",
- "description": "Number of background consumer threads.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "poll_interval",
- "description": "Seconds between local feature flag definition refreshes.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "personal_api_key",
- "description": "Deprecated alias for ``secret_key``. Still honored for backwards compatibility; prefer ``secret_key``, which also accepts a Project Secret API Key.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "disabled",
- "description": "If True, disable captures and API requests. Useful in tests.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "disable_geoip",
- "description": "Whether to disable server-side GeoIP enrichment. Defaults to True.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "is_server",
- "description": "Whether events are emitted from a server-side runtime. Defaults to True; set to False when using the SDK as a client/CLI so the device OS is attributed to the person normally.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "historical_migration",
- "description": "Mark events as historical migration imports.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "feature_flags_request_timeout_seconds",
- "description": "Timeout in seconds for feature flag and remote config requests.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "feature_flags_request_max_retries",
- "description": "Number of retries for feature flag requests after network, transport, or timeout failures. Defaults to 1. Set to 0 to disable retries.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "super_properties",
- "description": "Properties merged into every captured event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_exception_autocapture",
- "description": "Automatically capture uncaught exceptions.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "log_captured_exceptions",
- "description": "Also log exceptions captured by error tracking.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "project_root",
- "description": "Root path used to determine in-app stack frames for captured exceptions. Defaults to the current working directory.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "privacy_mode",
- "description": "For AI observability, capture usage metadata without prompt inputs or outputs.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "before_send",
- "description": "Optional callback that can modify or drop events before upload. Return ``None`` to drop an event.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "flag_fallback_cache_url",
- "description": "Optional feature flag fallback cache URL, such as ``memory://local/?ttl=300&size=10000`` or a Redis URL.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "enable_local_evaluation",
- "description": "Whether to poll feature flag definitions for local evaluation when a personal API key is configured.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "flag_definition_cache_provider",
- "description": "Optional external cache provider for sharing feature flag definitions across workers.",
- "isOptional": true,
- "type": "FlagDefinitionCacheProvider"
- },
- {
- "name": "capture_exception_code_variables",
- "description": "Capture local variable values on exception stack frames.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "code_variables_mask_patterns",
- "description": "Variable-name patterns to mask when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_ignore_patterns",
- "description": "Variable-name patterns to omit when capturing code variables.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_mask_url_credentials",
- "description": "Scrub credentials embedded in URLs/DSNs (e.g. ``user:pass@host``) from captured code variables, regardless of the surrounding variable name. Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "code_variables_detect_secrets",
- "description": "Last-resort entropy-based detection that redacts high-entropy secret-looking values (API keys, tokens, strong passwords) sitting in innocuously-named variables, after the name and URL checks. Skips structured ids (UUIDs, ObjectIds, hashes). Defaults to True.",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "in_app_modules",
- "description": "Module/package prefixes treated as in-app frames in captured exceptions.",
- "isOptional": false,
- "type": "UnionType[list[str], any]"
- },
- {
- "name": "enable_exception_autocapture_rate_limiting",
- "description": "Rate limit autocaptured exceptions client-side with a token bucket per exception type. Disabled by default.",
- "isOptional": false,
- "type": "bool"
- },
- {
- "name": "exception_autocapture_bucket_size",
- "description": "Maximum burst of autocaptured exceptions allowed per exception type (token bucket size, clamped to 0-100).",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_rate",
- "description": "Tokens restored per refill interval for each exception type's bucket.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "exception_autocapture_refill_interval_seconds",
- "description": "Seconds between token refills for autocaptured exception rate limiting.",
- "isOptional": false,
- "type": "int"
- },
- {
- "name": "capture_mode",
- "description": "Capture wire protocol to use. Defaults to ``CaptureMode.V0`` (legacy ``/batch/``). Set ``CaptureMode.V1`` (or pass the string ``\"v1\"``) to opt into ``/i/v1/analytics/events``. When omitted, the ``POSTHOG_CAPTURE_MODE`` env var is consulted, then ``V0``.",
- "isOptional": false,
- "type": "CaptureMode"
- },
- {
- "name": "capture_compression",
- "description": "Request-body compression for capture-v1 uploads (ignored in V0, which uses ``gzip``). ``CaptureCompression.GZIP`` or ``DEFLATE`` (or the strings ``\"gzip\"``/``\"deflate\"``). When omitted, the ``POSTHOG_CAPTURE_COMPRESSION`` env var is consulted, then the legacy ``gzip`` flag, then no compression.",
- "isOptional": false,
- "type": "CaptureCompression"
- },
- {
- "name": "secret_key",
- "description": "A Personal API Key or Project Secret API Key, used to authenticate local feature flag evaluation, remote config payloads, and decrypted flag payloads. Example:: posthog.Client(project_api_key, secret_key=\"phx_...\")",
- "isOptional": false,
- "type": "any"
- },
- {
- "name": "_dedicated_ai_endpoint",
- "description": "",
- "isOptional": false,
- "type": "bool"
- }
- ],
- "showDocs": true,
- "releaseTag": "public",
- "returnType": {
- "id": "return_type",
- "name": "None"
- },
- "examples": [
- {
- "id": "example_1",
- "name": "Example 1",
- "code": "from posthog import Posthog\n\nposthog = Posthog('', host='