- Notifications
You must be signed in to change notification settings - Fork31
Send usage data from your Python code to PostHog.
License
PostHog/posthog-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Please see thePython integration docs for details.
- Run
python3 -m venv env
(creates virtual environment called "env")- or
uv venv env
- or
- Run
source env/bin/activate
(activates the virtual environment) - Run
python3 -m pip install -e ".[test]"
(installs the package in develop mode, along with test dependencies)- or
uv pip install -e ".[test]"
- or
- Run
make test
- To run a specific test do
pytest -k test_no_api_key
Assuming you have alocal version of PostHog running, you can runpython3 example.py
to see the library in action.
There's a sample Django project included, calledsentry_django_example
, which explains how to use PostHog with Sentry.
There's 2 places of importance (Changes required are all marked with TODO in the sample project directory)
Settings.py
- Input your Sentry DSN
- Input your Sentry Org and ProjectID details into
PosthogIntegration()
- Add
POSTHOG_DJANGO
to settings.py. This allows thePosthogDistinctIdMiddleware
to get the distinct_ids
urls.py
- This includes the
sentry-debug/
endpoint, which generates an exception
- This includes the
To run things:make django_example
. This installs the posthog-python library with the sentry-sdk add-on, and then runs the django app.Also start the PostHog app locally.Then navigate tohttp://127.0.0.1:8080/sentry-debug/
and you should get an event in both Sentry and PostHog, with links to each other.
Updated are released using GitHub Actions: after bumpingversion.py
inmaster
and adding toCHANGELOG.md
, go toour release workflow's page and dispatch it manually, using workflow frommaster
.
About
Send usage data from your Python code to PostHog.