Python product analytics installation

  1. Install the package

    Required

    Install the PostHog Python library using pip:

    Terminal
    pip install posthog
  2. Initialize PostHog

    Required

    Initialize the PostHog client with your project API key and host from your project settings:

    Python
    from posthog import Posthog
    posthog = Posthog(
    project_api_key='<ph_project_api_key>',
    host='https://us.i.posthog.com'
    )
    Django integration

    If you're using Django, check out our Django integration for automatic request tracking.

  3. Send events

    Optional

    Once installed, PostHog will automatically start capturing events. You can also manually send events to test your integration:

    Capture custom events by calling the capture method with an event name and properties:

    Python
    import posthog
    posthog.capture('user_signed_up', properties={'example_property': 'example_value'})

    By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event.

    If you want to disable person profile processing for certain events, send the event with the following property:

    Python
    "$process_person_profile": False
  4. Next steps

    Recommended
    ResourceDescription
    Capturing eventsLearn how to capture custom events beyond autocapture
    Identifying usersAssociate events with specific users
    Creating insightsBuild trends, funnels, and retention charts
    Group analyticsTrack events at the company or account level

Community questions

Was this page useful?

Questions about this page? or post a community question.