posthog5.3.0
Published
Integrate PostHog into any python application.
pip install posthog
Package Downloads
Authors
Project URLs
Requires Python
>=3.9
Dependencies
- requests
<3.0,>=2.7
- six
>=1.5
- python-dateutil
>=2.2
- backoff
>=1.10.0
- distro
>=1.5.0
- langchain
>=0.2.0; extra == "langchain"
- django-stubs
; extra == "dev"
- lxml
; extra == "dev"
- mypy
; extra == "dev"
- mypy-baseline
; extra == "dev"
- types-mock
; extra == "dev"
- types-python-dateutil
; extra == "dev"
- types-requests
; extra == "dev"
- types-setuptools
; extra == "dev"
- types-six
; extra == "dev"
- pre-commit
; extra == "dev"
- pydantic
; extra == "dev"
- ruff
; extra == "dev"
- setuptools
; extra == "dev"
- packaging
; extra == "dev"
- wheel
; extra == "dev"
- twine
; extra == "dev"
- tomli
; extra == "dev"
- tomli_w
; extra == "dev"
- mock
>=2.0.0; extra == "test"
- freezegun
==1.5.1; extra == "test"
- coverage
; extra == "test"
- pytest
; extra == "test"
- pytest-timeout
; extra == "test"
- pytest-asyncio
; extra == "test"
- django
; extra == "test"
- openai
; extra == "test"
- anthropic
; extra == "test"
- langgraph
>=0.4.8; extra == "test"
- langchain-core
>=0.3.65; extra == "test"
- langchain-community
>=0.3.25; extra == "test"
- langchain-openai
>=0.3.22; extra == "test"
- langchain-anthropic
>=0.3.15; extra == "test"
- google-genai
; extra == "test"
- pydantic
; extra == "test"
- parameterized
>=0.8.1; extra == "test"
PostHog Python
Please see the Python integration docs for details.
Development
Testing Locally
We recommend using uv. It's super fast.
- Run
uv venv env
(creates virtual environment called "env")- or
python3 -m venv env
- or
- Run
source env/bin/activate
(activates the virtual environment) - Run
uv sync --extra dev --extra test
(installs the package in develop mode, along with test dependencies)- or
pip install -e ".[dev,test]"
- or
- you have to run
pre-commit install
to have auto linting pre commit - Run
make test
- To run a specific test do
pytest -k test_no_api_key
PostHog recommends uv
so...
uv python install 3.9.19
uv python pin 3.9.19
uv venv env
source env/bin/activate
uv sync --extra dev --extra test
pre-commit install
make test
Running Locally
Assuming you have a local version of PostHog running, you can run python3 example.py
to see the library in action.
Releasing Versions
Updates are released using GitHub Actions: after bumping version.py
in master
and adding to CHANGELOG.md
, go to our release workflow's page and dispatch it manually, using workflow from master
.
Testing changes locally with the PostHog app
You can run make prep_local
, and it'll create a new folder alongside the SDK repo one called posthog-python-local
, which you can then import into the posthog project by changing pyproject.toml to look like this:
dependencies = [
...
"posthoganalytics" #NOTE: no version number
...
]
...
[tools.uv.sources]
posthoganalytics = { path = "../posthog-python-local" }
This'll let you build and test SDK changes fully locally, incorporating them into your local posthog app stack. It mainly takes care of the posthog -> posthoganalytics
module renaming. You'll need to re-run make prep_local
each time you make a change, and re-run uv sync --active
in the posthog app project.