repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
posthog | posthog/personhog_client/__init__.py | .py | from typing import Literal
from posthog.personhog_client.proto import CONSISTENCY_LEVEL_EVENTUAL, CONSISTENCY_LEVEL_STRONG, ReadOptions
ReadConsistency = Literal["strong", "eventual"]
def consistency_to_read_options(consistency: ReadConsistency) -> ReadOptions:
level = CONSISTENCY_LEVEL_STRONG if consistency ==... | 11 | 404 |
posthog | posthog/personhog_client/fake_client.py | .py | """Fake PersonHogClient for tests.
Usage in tests::
from posthog.personhog_client.fake_client import fake_personhog_client
def test_something(self):
with fake_personhog_client() as fake:
fake.add_group_type_mapping(project_id=1, group_type="org", group_type_index=0)
# code und... | 803 | 38,151 |
posthog | posthog/personhog_client/interceptor.py | .py | from __future__ import annotations
import time
import random
from collections import namedtuple
from collections.abc import Sequence
from typing import Any
import grpc
import structlog
from prometheus_client import Counter, Histogram
from posthog.personhog_client.caller_tag import current_caller_tag
from posthog.per... | 220 | 8,043 |
posthog | posthog/personhog_client/client.py | .py | from __future__ import annotations
import time
import threading
from collections.abc import Callable
from typing import Optional, TypeVar
from django.conf import settings
import grpc
import structlog
from prometheus_client import Counter, Enum, Histogram
from posthog.personhog_client.interceptor import (
Client... | 463 | 19,258 |
posthog | posthog/personhog_client/test_interceptor.py | .py | from __future__ import annotations
from posthog.test.base import BaseTest
import grpc
from parameterized import parameterized
from posthog.personhog_client.interceptor import (
ClientNameInterceptor,
ConsistencyHeaderInterceptor,
_MutableClientCallDetails,
_with_metadata,
)
from posthog.personhog_cli... | 144 | 4,657 |
posthog | posthog/personhog_client/metrics.py | .py | from __future__ import annotations
from django.conf import settings
from prometheus_client import Counter
def get_client_name() -> str:
return getattr(settings, "OTEL_SERVICE_NAME", None) or "posthog-django"
PERSONHOG_ROUTING_TOTAL = Counter(
"personhog_routing_total",
"Tracks which data source was us... | 47 | 1,410 |
posthog | posthog/personhog_client/caller_tag.py | .py | from collections.abc import Iterator
from contextlib import contextmanager
from contextvars import ContextVar
# Ambient caller tag sent as the x-caller-tag gRPC header so the personhog router can attribute
# traffic to the originating call site (it is "unknown" otherwise). Follows the fleet convention
# of "{area}/{op... | 23 | 790 |
posthog | posthog/personhog_client/test_channel_state_monitor.py | .py | from __future__ import annotations
from unittest.mock import MagicMock, patch
import grpc
@patch("posthog.personhog_client.client.PERSONHOG_DJANGO_CHANNEL_STATE")
@patch("posthog.personhog_client.client.PERSONHOG_DJANGO_CHANNEL_STATE_TRANSITIONS_TOTAL")
@patch("posthog.personhog_client.client.PERSONHOG_DJANGO_CONNE... | 76 | 3,196 |
posthog | posthog/personhog_client/converters.py | .py | from __future__ import annotations
import json
import uuid as uuid_mod
from dataclasses import dataclass
from datetime import UTC, datetime
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from posthog.models.group.group import Group
from posthog.models.person import Person
from posthog.personhog_c... | 125 | 5,161 |
posthog | posthog/personhog_client/test_retry_interceptor.py | .py | from __future__ import annotations
import pytest
from unittest.mock import MagicMock, patch
import grpc
from parameterized import parameterized
from posthog.personhog_client.interceptor import RetryInterceptor, _MutableClientCallDetails
def _make_call_details(
method: str = "/personhog.service.v1.PersonHogServ... | 183 | 7,962 |
posthog | posthog/personhog_client/test_helpers.py | .py | """Shared test helpers for personhog tests.
Provides PersonhogTestMixin with helper methods for tests that exercise
personhog-backed reads. The global conftest fixture activates the fake for
every test, so the mixin no longer manages its own client lifecycle.
"""
from __future__ import annotations
from typing impor... | 63 | 2,296 |
posthog | posthog/personhog_client/test_fake_client.py | .py | import json
import pytest
from posthog.personhog_client.fake_client import FakePersonHogClient, fake_personhog_client
from posthog.personhog_client.proto.generated.personhog.types.v1 import cohort_pb2, common_pb2, group_pb2, person_pb2
class TestFakePersonHogClientPersons:
def setup_method(self):
self.c... | 472 | 20,071 |
posthog | posthog/personhog_client/proto/__init__.py | .py | # ruff: noqa: F401
# isort: skip_file
# common_pb2 must be imported before any proto that depends on common.proto
# (cohort, group, person all reference it in their serialized descriptors)
from posthog.personhog_client.proto.generated.personhog.types.v1.common_pb2 import (
CONSISTENCY_LEVEL_EVENTUAL,
CONSISTENC... | 97 | 3,315 |
posthog | posthog/personhog_client/proto/generated/personhog/service/v1/service_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
from ....personhog.types.v1 import (
cohort_pb2 as personhog_dot_types_dot_v1_dot_cohort__pb2,
feature_flag_pb2 as personhog_dot_types_dot_v1_dot_feature__flag__pb2,
group_pb2 as personhog_dot_types_dot_v1_dot_group__p... | 2,141 | 89,963 |
posthog | posthog/personhog_client/proto/generated/personhog/service/v1/service_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 32 | 7,552 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/cohort_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
GRPC_GENERATED_VERSION = "1.71.2"
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_G... | 22 | 819 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/common_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
GRPC_GENERATED_VERSION = "1.71.2"
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_G... | 22 | 819 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/feature_flag_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 41 | 3,337 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/feature_flag_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
GRPC_GENERATED_VERSION = "1.71.2"
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_G... | 22 | 825 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/group_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
GRPC_GENERATED_VERSION = "1.71.2"
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_G... | 22 | 818 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/common_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 33 | 2,042 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/group_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 95 | 12,631 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/person_pb2_grpc.py | .py | """Client and server classes corresponding to protobuf-defined services."""
import grpc
GRPC_GENERATED_VERSION = "1.71.2"
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_G... | 22 | 819 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/person_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 113 | 14,654 |
posthog | posthog/personhog_client/proto/generated/personhog/types/v1/cohort_pb2.py | .py | """Generated protocol buffer code."""
from google.protobuf import (
descriptor as _descriptor,
descriptor_pool as _descriptor_pool,
runtime_version as _runtime_version,
symbol_database as _symbol_database,
)
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRunt... | 51 | 4,349 |
posthog | posthog/api/cimd_verification_token.py | .py | from typing import Any
from urllib.parse import urlparse
from django.core.cache import cache
from django.views.decorators.debug import sensitive_variables
from drf_spectacular.utils import extend_schema
from rest_framework import mixins, serializers, viewsets
from rest_framework.response import Response
from posthog... | 298 | 12,740 |
posthog | posthog/api/team.py | .py | import re
import json
import secrets
from datetime import timedelta
from functools import cached_property
from typing import Any, Literal, cast
from django.conf import settings
from django.db import transaction
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.utils.dateparse... | 2,735 | 123,342 |
posthog | posthog/api/csp_reporting.py | .py | import openai
from rest_framework import request, response, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from posthog.api.csp import CSP_REPORT_TYPES_MAPPING_TABLE
from posthog.api.documentation import _FallbackSerializer
from posthog.api.routing import T... | 60 | 2,907 |
posthog | posthog/api/property_value_metrics.py | .py | from prometheus_client import Histogram
PROPERTY_VALUES_DURATION = Histogram(
"posthog_property_values_request_duration_seconds",
"Duration of property value lookup requests",
labelnames=["endpoint_type"],
buckets=(0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0),
)
| 9 | 290 |
posthog | posthog/api/project_secret_api_key.py | .py | from typing import cast
from django.db import IntegrityError
from django.db.models import QuerySet
from django.utils import timezone
import posthoganalytics
from rest_framework import response, serializers, status, viewsets
from rest_framework.exceptions import ValidationError
from posthog.api.documentation import e... | 205 | 8,851 |
posthog | posthog/api/email_verification.py | .py | from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from rest_framework import exceptions
from posthog.exceptions_capture import capture_exception
from posthog.models.user import User
from posthog.ph_client import feature_enabled_or_false
from pos... | 60 | 2,730 |
posthog | posthog/api/user.py | .py | import os
import re
import json
import time
import secrets
import urllib.parse
from base64 import b32encode
from binascii import unhexlify
from datetime import UTC, datetime, timedelta
from typing import Any, Optional, cast
from django.conf import settings
from django.contrib.auth import login, update_session_auth_has... | 1,988 | 86,799 |
posthog | posthog/api/sharing.py | .py | import json
from collections.abc import Callable
from datetime import timedelta
from typing import Any, Optional, cast
from urllib.parse import urlparse, urlunparse
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Model, Q
f... | 1,553 | 72,492 |
posthog | posthog/api/forbid_destroy_model.py | .py | from drf_spectacular.utils import extend_schema
from rest_framework import status
from rest_framework.response import Response
class ForbidDestroyModel:
@extend_schema(
responses={
405: None,
},
description='Hard delete of this model is not allowed. Use a patch API call to set ... | 15 | 474 |
posthog | posthog/api/welcome.py | .py | import hashlib
from datetime import UTC, datetime, timedelta
from typing import Any, cast
from django.core.cache import cache
from django.db.models import F
from django.utils import timezone
import structlog
from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework import serializers, views... | 594 | 24,861 |
posthog | posthog/api/web_experiment.py | .py | import re
from typing import Any
from django.http import HttpResponse, JsonResponse
from django.utils.text import slugify
from django.views.decorators.csrf import csrf_exempt
from nanoid import generate
from rest_framework import serializers, status, viewsets
from rest_framework.decorators import action
from rest_fra... | 312 | 12,829 |
posthog | posthog/api/instance_status.py | .py | from typing import Any, Union
from django.conf import settings
from django.db import connection
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
import posthoganalytics
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
f... | 246 | 9,211 |
posthog | posthog/api/my_notifications.py | .py | from datetime import datetime
from typing import Any, Optional
from django.db.models import Q
from drf_spectacular.utils import extend_schema
from rest_framework import serializers, status, viewsets
from rest_framework.exceptions import ValidationError
from rest_framework.request import Request
from rest_framework.re... | 279 | 12,043 |
posthog | posthog/api/instance_settings.py | .py | import re
import json
from typing import Any, Optional, Union, cast, get_args, get_origin
import structlog
from rest_framework import exceptions, mixins, permissions, serializers, viewsets
from rest_framework.request import Request
from posthog.cloud_utils import is_cloud
from posthog.email import is_email_available
... | 241 | 8,642 |
posthog | posthog/api/event_schema.py | .py | from rest_framework import mixins, serializers, viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.schema_property_group import SchemaPropertyGroupSerializer
from posthog.api.scoped_related_fields import TeamScopedPrimaryKeyRelatedField
from posthog.models import EventDefinition, EventSch... | 92 | 3,550 |
posthog | posthog/api/posthog_connection.py | .py | """Forward arbitrary API requests to another PostHog project through a `posthog` connection.
A `posthog` integration (see `posthog.models.integration`) holds a user-consented, refreshable OAuth
grant against another PostHog project, in another region or your own. This viewset lets the connecting
user replay any reques... | 369 | 18,804 |
posthog | posthog/api/utils.py | .py | import re
import json
import time
import socket
import urllib.parse
from enum import Enum, auto
from functools import wraps
from ipaddress import ip_address
from typing import Any, Optional, Union, cast
from urllib.parse import urlparse
from uuid import UUID
from django.core.exceptions import RequestDataTooBig
from dj... | 809 | 29,913 |
posthog | posthog/api/fields.py | .py | """Reusable DRF serializer fields shared across the API.
Add generic, endpoint-agnostic serializer field types here so viewsets can
reuse them instead of redefining local copies.
"""
import json
from typing import Any
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
clas... | 103 | 3,912 |
posthog | posthog/api/monitoring.py | .py | from collections.abc import Callable
from enum import StrEnum
from functools import wraps
from prometheus_client import Counter
from posthog.clickhouse.query_tagging import tag_queries
# Keep values in sync with `posthog.clickhouse.query_tagging.Feature` β pydantic validates
# the `feature` field on `QueryTags` aga... | 56 | 1,536 |
posthog | posthog/api/report_buffer.py | .py | """Bounded in-process buffer for the CSP report capture-forward.
The /report/ endpoint forwards every accepted report to capture-rs. Doing that
synchronously ties request-worker hold time to capture-rs latency (including its
retry budget), which starves bounded worker pools when capture-rs degrades. This
buffer decoup... | 303 | 13,393 |
posthog | posthog/api/resource_transfer.py | .py | from typing import Any, cast
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from rest_framework import exceptions, serializers, status, viewsets
from rest_framework.request import Request
from rest_framework.response import Response
from posthog.api.documentation import _Fallbac... | 407 | 16,055 |
posthog | posthog/api/materialized_column_slot.py | .py | from django.db import IntegrityError, transaction
import structlog
from rest_framework import (
response,
serializers,
status as http_status,
viewsets,
)
from rest_framework.decorators import action
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.helpers.impersonation import is_imp... | 341 | 13,968 |
posthog | posthog/api/data_color_theme.py | .py | from django.db.models import Q
from drf_spectacular.utils import extend_schema, extend_schema_field
from rest_framework import serializers, viewsets
from rest_framework.permissions import SAFE_METHODS, BasePermission
from rest_framework.response import Response
from posthog.api.routing import TeamAndOrgViewSetMixin
f... | 97 | 3,640 |
posthog | posthog/api/core_event.py | .py | from rest_framework import serializers, viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.models.core_event import CoreEvent
class CoreEventSerializer(serializers.ModelSerializer):
class Meta:
model = CoreEvent
fields = [
"id",
"name",
... | 37 | 1,057 |
posthog | posthog/api/authentication.py | .py | import re
import json
import time
import random
import datetime
import unicodedata
from typing import Any, TypedDict, cast
from urllib.parse import urlencode
from uuid import uuid4
from django.conf import settings
from django.contrib.auth import (
authenticate,
login,
logout as auth_logout,
)
from django.c... | 1,382 | 59,312 |
posthog | posthog/api/app_metrics2.py | .py | from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from typing import Any, Optional, cast
from drf_spectacular.utils import extend_schema
from rest_framework import serializers, viewsets
from rest_framework.exceptions import ValidationError
from rest_framework.request import Request
from r... | 389 | 14,353 |
posthog | posthog/api/embedding_worker.py | .py | from dataclasses import dataclass
from datetime import datetime
from typing import Optional
from django.utils.timezone import now
import httpx
import structlog
from posthog.kafka_client.client import ProduceResult
from posthog.kafka_client.routing import get_producer
from posthog.kafka_client.topics import KAFKA_DOC... | 233 | 8,410 |
posthog | posthog/api/llm_prompt_serializers.py | .py | import re
import json
from typing import Any
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from posthog.api.shared import UserBasicSerializer
from posthog.llm_prompt import normalize_prompt_to_string
from products.ai_observability.backend.activity_logging import prompt_... | 612 | 23,356 |
posthog | posthog/api/organization_invite.py | .py | import concurrent.futures
from datetime import timedelta
from typing import Any, Optional, cast
from uuid import UUID
from django.db import transaction
from django.db.models import Q, QuerySet
from django.utils import timezone
import structlog
import posthoganalytics
from drf_spectacular.utils import extend_schema
fr... | 737 | 33,518 |
posthog | posthog/api/hog_invocation_results.py | .py | import gzip
import json
import base64
import dataclasses
from datetime import UTC, datetime
from typing import Any, Optional, cast
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from rest_framework_dataclasses.serializers impo... | 272 | 9,702 |
posthog | posthog/api/organization.py | .py | from collections.abc import Callable
from functools import cached_property
from typing import Any, Literal, Union, cast
from django.db import transaction
from django.db.models import Model, QuerySet
from django.shortcuts import get_object_or_404
import posthoganalytics
from drf_spectacular.utils import extend_schema,... | 748 | 34,495 |
posthog | posthog/api/user_home_settings.py | .py | from collections.abc import Iterable
from typing import Any, Optional, cast
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import exceptions, serializers, viewsets
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from posthog.... | 244 | 9,556 |
posthog | posthog/api/__init__.py | .py | import importlib
import importlib.util
from typing import TYPE_CHECKING, Any
# The API route aggregator (the DRF router build + ~200 viewset imports) lives in
# `posthog.api.rest_router`, imported lazily β only when a name it defines or re-exports
# (the router objects, view modules like `dashboard`) is first accessed... | 37 | 1,664 |
posthog | posthog/api/hog_invocation_rerun.py | .py | """
Rerun endpoint serializers shared by `HogFunctionViewSet` and `HogFlowViewSet`.
These define the request/response shape for `POST .../{kind}/{id}/rerun`. The
view validates input, then proxies through to the Node CDP worker via
`rerun_hog_invocations` in `posthog.plugins.plugin_server_api`. The worker
reads matchi... | 113 | 4,973 |
posthog | posthog/api/leaked_key.py | .py | from hashlib import sha256
import posthoganalytics
from drf_spectacular.utils import OpenApiResponse
from rest_framework import serializers
from rest_framework.parsers import JSONParser
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView... | 125 | 5,843 |
posthog | posthog/api/metalytics.py | .py | from typing import Any
from rest_framework import request, response, serializers, viewsets
from rest_framework.serializers import BaseSerializer
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.kafka_client.routing import get_producer
from posthog.kafka_client.topics import KAFKA_APP_METRICS2
from ... | 44 | 1,701 |
posthog | posthog/api/shared.py | .py | """
This module contains serializers that are used across other serializers for nested representations.
"""
import copy
from functools import cached_property
from typing import Any, Optional
from uuid import UUID
from drf_spectacular.utils import extend_schema_field
from opentelemetry import trace
from rest_framework... | 315 | 12,161 |
posthog | posthog/api/organization_member.py | .py | from typing import Any, cast
from django.db.models import F, Model, Prefetch, QuerySet
from django.shortcuts import get_object_or_404
from django_otp.plugins.otp_totp.models import TOTPDevice
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schem... | 343 | 15,157 |
posthog | posthog/api/debug_ch_queries.py | .py | import re
import json
import logging
from datetime import UTC, datetime, timedelta
from typing import Any, Optional
from django.db.models import Count
from django.utils.timezone import now
from dateutil.relativedelta import relativedelta
from drf_spectacular.utils import extend_schema
from loginas.utils import is_imp... | 1,184 | 56,255 |
posthog | posthog/api/user_push_token.py | .py | """`/api/users/@me/push_tokens/` β register and unregister mobile push tokens.
The mobile app uploads its Expo push token after the user grants notification
permission. The backend fans out push notifications to every stored token
belonging to a user when something relevant happens (e.g. a PostHog Desktop task
run fin... | 170 | 7,508 |
posthog | posthog/api/js_snippet.py | .py | from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema
from rest_framework import serializers, status
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.viewsets import GenericVi... | 96 | 3,749 |
posthog | posthog/api/person.py | .py | import json
import uuid
import builtins
import dataclasses
from datetime import UTC, datetime
from typing import Any, Optional, Union, cast # noqa: UP035
import structlog
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import (
OpenApiExample,
OpenApiParameter,
extend_schema,
... | 1,560 | 68,305 |
posthog | posthog/api/event_filter_config.py | .py | from typing import cast
from drf_spectacular.openapi import AutoSchema
from drf_spectacular.utils import extend_schema
from rest_framework import serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.request import Request
f... | 164 | 6,837 |
posthog | posthog/api/openapi_parameters.py | .py | """
Shared OpenAPI parameter factories for endpoints that accept the
`variables_override` / `filters_override` query params.
Three semantics are easy to miss without reading posthog/utils.py and
posthog/api/insight_variable.py, so they're documented once here:
1. Each variable entry needs `code_name` to match β `ma... | 71 | 3,415 |
posthog | posthog/api/webauthn.py | .py | import json
import uuid
from typing import Any, cast
from django.contrib.auth import authenticate, login
from django.contrib.auth.signals import user_login_failed
from django.http.response import JsonResponse
import structlog
from axes.exceptions import AxesBackendPermissionDenied
from axes.handlers.proxy import Axes... | 781 | 31,896 |
posthog | posthog/api/column_configuration.py | .py | from typing import Any
from django.core.exceptions import PermissionDenied as DjangoPermissionDenied
from django.db import IntegrityError
from django.db.models import Q, QuerySet
from django.http import Http404
import structlog
from drf_spectacular.utils import extend_schema
from rest_framework import serializers, vi... | 201 | 8,757 |
posthog | posthog/api/id_jag.py | .py | """
ID-JAG (XAA) implementation. See https://xaa.dev for more information.
TLDR: ID-JAG is a protocol where IdP's issue JWT tokens to their users
which they can send to us to issue a short-lived JWT token which can be
used to access our API. This eliminates the need for the user to oauth
to us, or get a personal API t... | 502 | 20,193 |
posthog | posthog/api/llm_prompt.py | .py | import json
from typing import Any, cast
from django.conf import settings
from django.db import IntegrityError
from django.db.models import Func, IntegerField, Q, QuerySet, TextField
from django.db.models.functions import Cast
from drf_spectacular.utils import extend_schema
from rest_framework import mixins, serializ... | 601 | 25,005 |
posthog | posthog/api/organization_personal_api_key.py | .py | from typing import Any
from django.db.models import QuerySet
from drf_spectacular.utils import extend_schema, extend_schema_field
from rest_framework import mixins, serializers, viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.constants import AvailableFeature
from posthog.models.personal... | 100 | 4,643 |
posthog | posthog/api/comments.py | .py | from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, cast
from django.core import exceptions as django_exceptions
from django.db import transaction
from django.db.models import Q, QuerySet
from django.utils import timezone
import structlog
import posthoganalytics
from drf_spectacular.utils ... | 1,206 | 57,868 |
posthog | posthog/api/scoped_related_fields.py | .py | from django.db.models import Manager, QuerySet
from rest_framework import serializers
class TeamScopedPrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField):
"""Auto-filters queryset by context['team_id']. Fails safe to .none()."""
scope_field = "team_id"
def get_queryset(self):
queryset = ... | 40 | 1,338 |
posthog | posthog/api/async_migration.py | .py | import structlog
from rest_framework import response, serializers, viewsets
from rest_framework.permissions import IsAuthenticated
from semantic_version.base import Version
from posthog.api.utils import action
from posthog.async_migrations.runner import MAX_CONCURRENT_ASYNC_MIGRATIONS, is_posthog_version_compatible
fr... | 213 | 7,906 |
posthog | posthog/api/site_app.py | .py | import json
from django.http import HttpRequest, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status
from statshog.defaults.django import statsd
from posthog.exceptions import generate_exception_response
from posthog.exceptions_capture import capture_exception
from pos... | 40 | 1,642 |
posthog | posthog/api/organization_domain.py | .py | import re
from typing import Any, cast
from django.db.models import Q, QuerySet
import django_filters
import posthoganalytics
from drf_spectacular.utils import extend_schema
from rest_framework import exceptions, request, response, serializers
from rest_framework.pagination import PageNumberPagination
from rest_frame... | 320 | 13,487 |
posthog | posthog/api/project.py | .py | import math
from functools import cached_property
from typing import Any, Optional, cast
from django.conf import settings
from django.db import transaction
from django.db.models import Model
from django.db.models.functions import Trim
from django.shortcuts import get_object_or_404
from django.utils import timezone
fro... | 1,941 | 91,891 |
posthog | posthog/api/role_external_reference.py | .py | from typing import Any
from django.db import IntegrityError
from django.db.models import Q, QuerySet
from drf_spectacular.utils import extend_schema
from rest_framework import mixins, serializers, viewsets
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.resp... | 166 | 7,364 |
posthog | posthog/api/event.py | .py | import json
import time
import uuid
import random
import urllib
import builtins
import dataclasses
from datetime import UTC, datetime
from typing import Any, Iterator, List, Optional, Union, cast # noqa: UP035
from django.conf import settings
from django.utils import timezone
from drf_spectacular.types import OpenAp... | 721 | 30,928 |
posthog | posthog/api/playwright_setup.py | .py | """Test setup API endpoint for Playwright tests."""
from django.conf import settings
from django.http import Http404
from pydantic import BaseModel
from rest_framework import status
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
from rest_framework.r... | 50 | 1,886 |
posthog | posthog/api/element.py | .py | import re
import json
from datetime import datetime
from typing import Literal, cast
from django.conf import settings
from drf_spectacular.utils import OpenApiParameter, extend_schema
from opentelemetry import trace
from prometheus_client import Histogram
from rest_framework import request, response, serializers, vie... | 403 | 18,861 |
posthog | posthog/api/csp.py | .py | import re
import json
from datetime import UTC, datetime, timedelta
from typing import Optional
from urllib.parse import urlsplit, urlunsplit
from django.conf import settings
from django.http import HttpResponse
from django.utils.html import escape
import structlog
from prometheus_client import Counter
from rest_fram... | 375 | 16,410 |
posthog | posthog/api/sdk_health.py | .py | import json
from dataclasses import asdict
from typing import Any, cast
import structlog
from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework import serializers, viewsets
from rest_framework.decorators import action, api_view, permission_classes
from rest_framework.permissions import I... | 329 | 14,618 |
posthog | posthog/api/dead_letter_queue.py | .py | import datetime as dt
from typing import Any, Optional, Union
from zoneinfo import ZoneInfo
from rest_framework import mixins, permissions, serializers, viewsets
from posthog.clickhouse.client import sync_execute
from posthog.permissions import IsStaffUser
from posthog.utils import relative_date_parse
# keep in sync... | 335 | 12,012 |
posthog | posthog/api/search.py | .py | import re
from collections import defaultdict
from typing import Any, Literal, TypedDict, cast
from django.db.models import BigIntegerField, CharField, F, Model, QuerySet, Value
from django.db.models.functions import Cast, JSONObject
from django.http import HttpResponse
from drf_spectacular.utils import extend_schema... | 321 | 11,914 |
posthog | posthog/api/tagged_item.py | .py | import dataclasses
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Optional, cast
from django.db import models
from django.db.models import Prefetch, Q, QuerySet, prefetch_related_objects
from drf_spectacular.utils import extend_schema
from rest_framework import response, serializers, stat... | 404 | 15,999 |
posthog | posthog/api/cohort.py | .py | import csv
import json
import time
import uuid
import hashlib
from collections.abc import Iterator
from copy import deepcopy
from typing import Annotated, Any, ClassVar, Literal, Optional, Union, cast
from django.db.models import OuterRef, QuerySet, Subquery
from django.utils import timezone
import requests
import st... | 2,290 | 102,875 |
posthog | posthog/api/sharing_publish_gate.py | .py | """Publish-time access gate for public sharing.
Shared links execute without warehouse access control (the publish act is the access
decision - see SharedLinkUser), so the gate moves to the moment of publishing: the member
enabling a share must be able to run every query it exposes. Otherwise sharing would be an
escal... | 164 | 7,518 |
posthog | posthog/api/ingestion_warnings_v2.py | .py | import json
from datetime import timedelta
from zoneinfo import ZoneInfo
from django.utils.timezone import now
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema, extend_schema_field
from rest_framework import serializers, viewsets
from rest_framework.request import Request... | 281 | 12,189 |
posthog | posthog/api/session.py | .py | import json
from opentelemetry import trace
from rest_framework import request, response, viewsets
from rest_framework.exceptions import ValidationError
from posthog.schema import SessionTableVersion
from posthog.hogql.database.schema.sessions_v1 import (
get_lazy_session_table_properties_v1,
get_lazy_sessio... | 114 | 4,530 |
posthog | posthog/api/documentation.py | .py | import os
import re
from typing import Any, get_args
from django.core.exceptions import ImproperlyConfigured
from drf_spectacular.drainage import warn as spectacular_warn
from drf_spectacular.extensions import OpenApiAuthenticationExtension
from drf_spectacular.openapi import AutoSchema
from drf_spectacular.plumbing ... | 1,268 | 55,257 |
posthog | posthog/api/schema_property_group.py | .py | import logging
from django.db import IntegrityError, transaction
from drf_spectacular.utils import extend_schema_field
from rest_framework import mixins, serializers, viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
from posthog.models import SchemaPr... | 174 | 7,250 |
posthog | posthog/api/mixins.py | .py | from collections.abc import Callable
from functools import wraps
from typing import Any, Generic, TypeVar, cast
from django.conf import settings
import structlog
from drf_spectacular.utils import OpenApiResponse, extend_schema
from pydantic import BaseModel, ValidationError
from rest_framework import serializers
from... | 278 | 12,368 |
posthog | posthog/api/event_definition.py | .py | from __future__ import annotations
import uuid
from collections import defaultdict
from typing import Any, Literal, Optional, cast
from django.core.cache import cache
from django.db import IntegrityError, transaction
from django.db.models import Manager, Prefetch
from django.http import Http404
from django.utils impo... | 919 | 39,060 |
posthog | posthog/api/data_management.py | .py | from rest_framework import request, viewsets
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.utils import action
from posthog.models.activity_logging.activity_log import load_all_activity
from posthog.models.activity_logging.activity_page import activity_page_response
class DataManagementView... | 25 | 993 |
posthog | posthog/api/cli_auth.py | .py | """
CLI Authentication API using OAuth2 Device Flow
This implements the device authorization flow (RFC 8628) for the PostHog CLI.
Users can authenticate without copying/pasting API keys.
Flow:
1. CLI requests device code
2. User opens browser and authorizes
3. CLI polls for completion
4. Returns Personal API Key
"""
... | 369 | 14,328 |
posthog | posthog/api/rest_router.py | .py | from rest_framework import decorators, exceptions
# Preload to work around circular imports in `ee.hogai.{core.agent_modes,chat_agent,tools}`.
import posthog.temporal.ai # noqa: F401
from posthog.api import data_color_theme, metalytics, my_notifications, project, user_integration, user_push_token
from posthog.api.csp... | 582 | 19,415 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.