|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for coding agents working in `posthog-python`. |
| 4 | + |
| 5 | +## Repo context |
| 6 | + |
| 7 | +- This repository contains the PostHog Python SDK, published as `posthog`. |
| 8 | +- The main runtime package is `posthog/`; tests live under `posthog/test/`. |
| 9 | +- The project uses `uv` for local development. See `CONTRIBUTING.md` for setup. |
| 10 | +- Keep edits targeted and follow existing patterns. Prefer adding or updating tests near the behavior you change. |
| 11 | + |
| 12 | +## Validation |
| 13 | + |
| 14 | +Useful checks: |
| 15 | + |
| 16 | +```bash |
| 17 | +uv run ruff format --check . |
| 18 | +uv run ruff check . |
| 19 | +uv run mypy --no-site-packages --config-file mypy.ini . | uv run mypy-baseline filter |
| 20 | +uv run pytest --verbose --timeout=30 |
| 21 | +uv run python -W error -c "import posthog" |
| 22 | +``` |
| 23 | + |
| 24 | +For focused changes, run the smallest relevant `uv run pytest ...` command first. |
| 25 | + |
| 26 | +If public API surface changes, update/check `references/public_api_snapshot.txt` with: |
| 27 | + |
| 28 | +```bash |
| 29 | +make public_api_snapshot |
| 30 | +make public_api_check |
| 31 | +``` |
| 32 | + |
| 33 | +## `posthoganalytics` mirror package |
| 34 | + |
| 35 | +This repo also publishes `posthoganalytics`, a generated mirror of `posthog` used by the PostHog app. The mirror is created by copying `posthog/` to `posthoganalytics/` and rewriting absolute imports such as `from posthog.foo import ...` to `from posthoganalytics.foo import ...`. |
| 36 | + |
| 37 | +Important when editing SDK-internal code: |
| 38 | + |
| 39 | +- Prefer relative imports for imports within the SDK package, especially in runtime modules under `posthog/`. |
| 40 | + - Good: `from .client import Client`, `from .exception_utils import extract_exception_properties` |
| 41 | + - Risky: `from posthog.client import Client` |
| 42 | +- Absolute `posthog...` imports inside SDK modules can break the `posthoganalytics` mirror when it is imported inside an application that also has its own `posthog` package/module on `sys.path`. |
| 43 | +- Test mirror-sensitive changes by running the normal focused tests and, when relevant, `make prep_local` to generate a local `posthoganalytics` copy for testing in the PostHog app. |
| 44 | +- Do not commit generated `posthoganalytics/` directories; they are build/local artifacts. |
| 45 | + |
| 46 | +## Release/build notes |
| 47 | + |
| 48 | +- `make build_release` builds the `posthog` distribution. |
| 49 | +- `make build_release_analytics` builds the `posthoganalytics` distribution and temporarily rewrites/copies package files; ensure the working tree is clean before and after running it. |
| 50 | +- Release flow publishes both packages; see `RELEASING.md`. |
0 commit comments