Skip to main content

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 - True in order to enable Posthog feature flags in the application. False to 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 when POSTHOG_PERSONAL_API_KEY is 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_KEY is 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()

Metadata

Release files for mitol-django-olposthog 2026.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mitol-django-olposthog 2026.4.2
File Size Uploaded
mitol_django_olposthog-2026.4.2.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mitol-django-olposthog 2026.4.2
File Interpreter ABI Platform
mitol_django_olposthog-2026.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / mitol_django_olposthog-2026.4.2.tar.gz

Download URL mitol_django_olposthog-2026.4.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1d2b7b9323470160081ef49bcea8d6a925d2af124d41c49e3f41e159e41316a6
BLAKE2b-256 checksum
How to use checksums
41505864b3b8560e2befa318f06caa8a3e53adf1655a3329e765c07052cae7b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / mitol_django_olposthog-2026.4.2-py3-none-any.whl

Download URL mitol_django_olposthog-2026.4.2-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c205d5f438a1c28e6a1931b919af573b7605c751183f985926d50030e53344c9
BLAKE2b-256 checksum
How to use checksums
1a55b68b3c9fab230f306871e8bd6d157c59988e02b7d72e7e2a05a7b58eaba6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

2026.4.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page