: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
"""Typed field registry for firmographic enrichment.
The single source of truth every enrichment writer imports, so the Postgres record,
the ClickHouse group-property projection, and the at-signup snapshot stay in lockstep.
Provider-agnostic: providers transform their responses into this shape. The ICP score is
deliberately not a field here: it is derived rather than provider-reported, and the writer
takes it separately so it stays out of the `fields_filled` launch signal.
Precedent: ee/billing/salesforce_enrichment/usage_signals.py (UsageSignals).
"""
import dataclasses
from typing import Any, Optional
# Prefix for the `enrichment_*` ClickHouse group properties written via group_identify.
ENRICHMENT_PROPERTY_PREFIX = "enrichment_"
# Fields whose provider source matches what already populates the icp_* group properties
# (Harmonic-first in the incumbent waterfall), so we write the same keys and consumers
# never migrate. Source-changing fields stay on the parallel `enrichment_*` namespace
# until they pass their own comparison.
SAME_KEY_GROUP_PROPERTIES: dict[str, str] = {
"headcount": "icp_employees",
"country": "icp_country",
}
@dataclasses.dataclass
class EnrichmentFields:
"""Firmographic enrichment values for one organization."""
company_type: Optional[str] = None
headcount: Optional[int] = None
headcount_engineering: Optional[int] = None
web_traffic: Optional[int] = None
industry: Optional[str] = None
country: Optional[str] = None
founded_year: Optional[int] = None
funding_stage: Optional[str] = None
total_raised: Optional[int] = None
last_round_size: Optional[int] = None
last_round_date: Optional[str] = None
investors: Optional[list[str]] = None
is_yc_company: Optional[bool] = None
is_ai_native: Optional[bool] = None
work_email: Optional[bool] = None
ownership_status: Optional[str] = None
parent_company: Optional[str] = None
parent_company_domain: Optional[str] = None
customer_type: Optional[str] = None
funding_status: Optional[str] = None
def to_dict(self) -> dict[str, Any]:
"""Return set (non-None) fields keyed by registry name."""
return {
field.name: value for field in dataclasses.fields(self) if (value := getattr(self, field.name)) is not None
}
def to_group_properties(self) -> dict[str, Any]:
"""Return the ClickHouse group properties: takeover fields on their icp_* keys, the rest as `enrichment_*`."""
return {
SAME_KEY_GROUP_PROPERTIES.get(name, f"{ENRICHMENT_PROPERTY_PREFIX}{name}"): value
for name, value in self.to_dict().items()
}