Python feature flags installation

Terminal
pip install posthog
Upgrading to v6

Version 6.x of the PostHog Python SDK introduces a new contexts API and breaking changes. If you're upgrading from 5.x to 6.x, read the migration guide first to learn more.

In your app, import the posthog library and set your project API key and host before making any calls.

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

Note: As a rule of thumb, we do not recommend having API keys in plaintext. Setting it as an environment variable is best.

You can find your project API key and instance address in the project settings page in PostHog.

Next steps

ResourceDescription
Adding feature flag codeHow to check flags in your code for all platforms
Framework-specific guidesSetup guides for React Native, Next.js, Flutter, and other frameworks
How to do a phased rolloutGradually roll out features to minimize risk
More tutorialsOther real-world examples and use cases

Community questions

Was this page useful?

Questions about this page? or post a community question.