mirror of
https://github.com/hanzoai/insights-python.git
synced 2026-10-30 18:33:17 +00:00
2.4 KiB
2.4 KiB
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: