MIT Open Learning django app extensions for Posthog.
Project description
mitol-django-olposthog
This is the Open Learning OlPosthog app. It provides an API to interact with Posthog in order to check feature flags.
Installation and setup
Add the OlPosthog app:
docker-compose run -u root --rm web uv add mitol-django-olposthog
Add the following to the ready() method for your App.
from mitol.olposthog.features import configure
configure()
Common Django settings
HOSTNAME- The website's hostname.
OlPosthog app settings
All settings for the mitol-django-olposthog app are prefaced with 'POSTHOG'.
POSTHOG_ENABLED-Truein order to enable Posthog feature flags in the application.Falseto disable Posthog feature flags.POSTHOG_PROJECT_API_KEY- Required if POSTHOG_ENABLED is True. Private API key to communicate with PostHog.POSTHOG_PERSONAL_API_KEY- Optional. Personal API key for local flag evaluation. When set, the PostHog SDK evaluates flags locally without making a per-request HTTP call. Recommended for production to reduce latency and cost.POSTHOG_API_HOST- Required if POSTHOG_ENABLED is True. Host URL for the PostHog API.POSTHOG_FEATURE_FLAG_REQUEST_TIMEOUT_MS- Timeout (ms) for PostHog feature flag requests. Default:3000.POSTHOG_MAX_RETRIES- Number of times requests to PostHog should be retried after failing. Default:3.POSTHOG_POLL_INTERVAL- Seconds between PostHog flag config polling. Only relevant whenPOSTHOG_PERSONAL_API_KEYis set for local evaluation. Default:300.
Circuit breaker
The circuit breaker protects your application when PostHog is slow or unreachable. If a PostHog request takes longer than the trip threshold, the circuit opens and subsequent calls return immediately from settings.FEATURES (your local fallback) until the cooldown expires.
POSTHOG_CIRCUIT_BREAKER_TRIP_THRESHOLD_SECONDS- How long a PostHog request can take before the circuit trips. Default:6.POSTHOG_CIRCUIT_BREAKER_COOLDOWN_SECONDS- How long the circuit stays open before PostHog is retried. Default:60.
The circuit breaker applies to both is_enabled() and get_all_feature_flags().
Note: The circuit breaker is most relevant when
POSTHOG_PERSONAL_API_KEYis not set (remote evaluation). With local evaluation enabled, flag checks are served from an in-process cache populated by a background polling thread, so per-request HTTP calls — and therefore circuit-breaker trips — are rare.
Cache table creation
Add the following cache defintion to your CACHES in the settings.py file of your Django application.
CACHES = {
"durable": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "durable_cache",
},
}
You must create the cache included in this library. This can be done by running the following command from within the Django application that this library is being added to: ./manage.py createcachetable.
Usage
Check single feature flag value
You can check the value of a feature flag on Posthog with the following code:
from mitol.olposthog.features import is_enabled
is_enabled(<FEATURE_FLAG_NAME>)
This will return a boolean value based on whether the Posthog feature flag is True or False.
Retrieve all feature flags from Posthog
You can retrieve all the feature flags from Posthog using:
from mitol.olposthog.features import get_all_feature_flags
get_all_feature_flags()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mitol_django_olposthog-2026.4.2.tar.gz.
File metadata
- Download URL: mitol_django_olposthog-2026.4.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d2b7b9323470160081ef49bcea8d6a925d2af124d41c49e3f41e159e41316a6
|
|
| MD5 |
15b2f8daccdb7750a36a134b9d3a4553
|
|
| BLAKE2b-256 |
41505864b3b8560e2befa318f06caa8a3e53adf1655a3329e765c07052cae7b8
|
File details
Details for the file mitol_django_olposthog-2026.4.2-py3-none-any.whl.
File metadata
- Download URL: mitol_django_olposthog-2026.4.2-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c205d5f438a1c28e6a1931b919af573b7605c751183f985926d50030e53344c9
|
|
| MD5 |
cc74ab019dac9fcb53ac1dab586ad867
|
|
| BLAKE2b-256 |
1a55b68b3c9fab230f306871e8bd6d157c59988e02b7d72e7e2a05a7b58eaba6
|