:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
#!/usr/bin/env bash
set -e
# Generate schema.py from schema.json
datamodel-codegen \
--class-name='SchemaRoot' --collapse-root-models --target-python-version 3.12 --disable-timestamp \
--use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \
--use-union-operator --use-standard-collections \
--input frontend/src/queries/schema.json --input-file-type jsonschema \
--output posthog/schema.py --output-model-type pydantic_v2.BaseModel \
--custom-file-header $'# mypy: disable-error-code="assignment,valid-type"\n# DO NOT EDIT THIS FILE DIRECTLY.\n# INSTEAD, edit frontend/src/types.ts or frontend/src/queries/schema/*.ts\n# THEN RUN hogli build:schema TO REBUILD' \
--set-default-enum-member --capitalise-enum-members \
--wrap-string-literal
# Re-apply discriminator keywords to array items dropped by datamodel-code-generator
python3 bin/patch-schema-array-discriminators.py
# Route the AnyPropertyFilter union on `type` via a legacy-tolerant callable discriminator
python3 bin/patch-schema-property-filter-discriminator.py
# Move enum classes to posthog/schema_enums.py (importable without the pydantic model cost)
python3 bin/split-schema-enums.py
# Format and lint
ruff format posthog/schema.py posthog/schema_enums.py
ruff check --fix posthog/schema.py posthog/schema_enums.py