feat: Add asyncio capture client#719
Conversation
posthog-python Compliance ReportDate: 2026-07-02 14:11:02 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
|
8816f29 to
cfe5d0f
Compare
cfe5d0f to
3b1a554
Compare
|
Addressed the Greptile shutdown feedback in 43e6275 — async shutdown now offloads the inherited blocking cleanup path ( |
|
related PRs for early feedback @dustinbyrne |
💡 Motivation and Context
Starts the stacked implementation for #103 by adding an asyncio-native client for event capture. This introduces
AsyncClient/AsyncPosthog, async HTTP helpers, and an asyncio queue/consumer pipeline so async applications can enqueue and flush events without daemon threads.This first PR intentionally focuses on the capture lifecycle and API shape. Async feature flag evaluation is stacked in the next PR. Review feedback was addressed by removing sensitive request/response payloads from async debug logs, running temporary sync flag fallback calls off the event loop, and parameterizing identify-method enqueue coverage.
💚 How did you test it?
uv run ruff check posthog/async_client.py posthog/test/test_async_client.pyuv run ruff check posthog/async_request.py posthog/test/test_async_request.pyuv run --extra test pytest posthog/test/test_async_client.py posthog/test/test_async_request.py --verbose --timeout=30uv run python -W error -c "import posthog; from posthog import AsyncPosthog"uv run --extra dev python .github/scripts/check_public_api.py📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with pi. The stack is split so reviewers can first inspect the async capture/queue/request foundation, then the async feature flag layer, then docs.
httpxis added as an optionalposthog[async]dependency and imported lazily so normalimport posthogstill works without the extra.