- Remove Posthog = Insights alias from __init__.py - Remove PosthogContextMiddleware alias from django.py - Remove PostHogTracingProcessor alias from processor.py - Change $lib from "posthog-python" to "insights-python" - Change ingestion URLs from posthog.com to insights.hanzo.ai - Rename all posthog_* kwargs to insights_* across AI wrappers - Rename __posthog_exception_captured to __insights_exception_captured - Rename posthog_context_stack contextvar to insights_context_stack - Rename posthog🎏 Redis prefix to insights🎏 - Rename $$_posthog_redacted_* sentinels to $$_insights_redacted_* - Remove POSTHOG_MW_* Django settings fallback, X-POSTHOG-* headers - Rename Prompts(posthog=) param to Prompts(client=) - Update APP_ENDPOINT to us.insights.hanzo.ai - Update all tests, examples, docs, mypy config
PostHog Python SDK Test Adapter
This adapter wraps the posthog-python SDK for compliance testing with the PostHog SDK Test Harness.
What is This?
This is a simple Flask app that:
- Wraps the posthog-python SDK
- Exposes a REST API for the test harness to control
- Tracks internal SDK state for test assertions
Running Tests
Tests run automatically in CI via GitHub Actions. See the test harness repo for details.
Locally with Docker Compose
# From the posthog-python/sdk_compliance_adapter directory
docker-compose up --build --abort-on-container-exit
This will:
- Build the Python SDK adapter
- Pull the test harness image
- Run all compliance tests
- Show results
Manually with Docker
# Create network
docker network create test-network
# Build and run adapter
docker build -f sdk_compliance_adapter/Dockerfile -t posthog-python-adapter .
docker run -d --name sdk-adapter --network test-network -p 8080:8080 posthog-python-adapter
# Run test harness
docker run --rm \
--name test-harness \
--network test-network \
ghcr.io/posthog/sdk-test-harness:latest \
run --adapter-url http://sdk-adapter:8080 --mock-url http://test-harness:8081
# Cleanup
docker stop sdk-adapter && docker rm sdk-adapter
docker network rm test-network
Adapter Implementation
See adapter.py for the implementation.
The adapter implements the standard SDK adapter interface defined in the test harness CONTRACT:
GET /health- Return SDK informationPOST /init- Initialize SDK with configPOST /capture- Capture an eventPOST /flush- Flush pending eventsGET /state- Return internal statePOST /reset- Reset SDK state
Key Implementation Details
Request Tracking: The adapter monkey-patches batch_post to track all HTTP requests made by the SDK, including retries.
State Management: Thread-safe state tracking for events captured vs sent, retry attempts, and errors.
UUID Tracking: Extracts and tracks UUIDs from batches to verify deduplication.
Documentation
For complete documentation on the test harness and how to implement adapters, see: