Skip to content

: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.

4.6 KB
Raw Blame
# 1. TODO: copy this file to `products/warehouse_sources/sources/{your_source}/source.py` and add an empty
#       `__init__.py` next to it (and `tests/__init__.py` once you add tests). the loader finds the
#       directory on its own, so there is no import list to edit
# 2. TODO: set SOURCE_KEY below to your source key: a PascalCase string such as "AcmeCrm". lowercased it
#       must equal the directory name without underscores (`AcmeCrm` -> `acme_crm/`). do NOT add an
#       ExternalDataSourceType member and do not run migrations; a new source has no enum member
# 3. TODO: change the name of your source class from TemplateSource
# 4. TODO: update get_source_config(). set `category` to the closest DataWarehouseSourceCategory bucket
#       (required, it groups the source in the new-source wizard catalog) and optionally `keywords`
#       (search aliases). add any config fields users will need to connect the source
# 5. TODO: run `pnpm run generate:source-configs`. it writes the config class for your source to
#       `products/warehouse_sources/sources/{your_source}/_config.py`
# 6. TODO: update all the references to `Config` in this file to the generated source config class
# 7. TODO: implement the logic for your source or mark it as unreleased by setting
#       unreleasedSource=True in the SourceConfig constructor
# 8. TODO: put a PNG icon at `products/warehouse_sources/sources/{your_source}/icon.png` and set
#       iconPath to "/static/warehouse-sources/{your_source}/icon.png"
# 9. TODO: rerun `pnpm run generate:source-configs` every time you change the source's fields
# 10. TODO: check `git status`: every change is under `products/warehouse_sources/sources/{your_source}/`.
#       no `hogli build:openapi` run, no SOURCES.md line and no file in frontend/public are needed
# 11. TODO: phew! you're done. just delete these TODOs before you PR

from typing import Optional, cast

from products.warehouse_sources.sources.sdk import (
    Config,
    DataWarehouseSourceCategory,
    FieldType,
    SimpleSource,
    SourceConfig,
    SourceInputs,
    SourceKey,
    SourceRegistry,
    SourceResponse,
    SourceSchema,
    source_key,
)

SOURCE_KEY = "Template"  # replace with your source key


@SourceRegistry.register
class TemplateSource(SimpleSource[Config]):  # rename this class and replace `Config` with the generated config
    # TODO: vendor API version metadata (see the implementing-warehouse-sources skill, "Vendor API version metadata").
    #   api_docs_url = "https://..."           # https vendor API docs/changelog page (always set this)
    #   supported_versions = ("v3",)           # only if the vendor exposes a real version token; pin what the code calls
    #   default_version = "v3"                 # must equal the single supported_versions entry

    @property
    def source_type(self) -> SourceKey:
        return source_key(SOURCE_KEY)

    @property
    def get_source_config(self) -> SourceConfig:
        return SourceConfig(
            name=self.source_type,
            category=DataWarehouseSourceCategory.DATABASES,  # TODO: pick the closest catalog bucket (groups this source in the new-source wizard)
            keywords=[],  # TODO (optional): lowercase search terms — acronyms/alt spellings (e.g. ["ga4", "ga"])
            iconPath="/static/warehouse-sources/template/icon.png",  # the icon.png in your source directory
            label="Template",  # only needed if the readable name is complex
            caption=None,  # only needed if you wanna inline docs
            docsUrl=None,  # link to the docs in the website, full path including https://
            fields=cast(list[FieldType], []),  # add source config fields here
        )

    def validate_credentials(
        self, config: Config, team_id: int, schema_name: Optional[str] = None
    ) -> tuple[bool, str | None]:  # replace `Config` with the generated class
        return (
            True,
            None,
        )  # implement logic to validate the credentials of your source, e.g. check the validity of API keys. return a tuple of whether the credentials are valid, and if not, return an error message to return to the user

    def get_schemas(
        self, config: Config, team_id: int, with_counts: bool = False, names: list[str] | None = None, force_refresh: bool = False
    ) -> list[SourceSchema]:  # replace `Config` with the generated class
        return []  # implement your source logic

    def source_for_pipeline(
        self, config: Config, inputs: SourceInputs
    ) -> SourceResponse:  # replace `Config` with the generated class
        raise NotImplementedError()  # implement your source logic