Skip to main content

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 poetry 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_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.
  • POSTHOG_MAX_RETRIES - Numbers of time requests to PostHog should be retried after failing.

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

mitol-django-olposthog-2024.5.14.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file mitol-django-olposthog-2024.5.14.tar.gz.

File metadata

File hashes

Hashes for mitol-django-olposthog-2024.5.14.tar.gz
Algorithm Hash digest
SHA256 089b31d4606b1ef4484f999cf29229f8f0988df41531dd165a7706fc000f4140
MD5 b1945ade727e93b63ff1cbdec352e6c3
BLAKE2b-256 3fbf7a0dc7ec03591a9971907ff5c8a638f4b8f6a63ce9b18fbc5c3005589e6f

See more details on using hashes here.

File details

Details for the file mitol_django_olposthog-2024.5.14-py3-none-any.whl.

File metadata

File hashes

Hashes for mitol_django_olposthog-2024.5.14-py3-none-any.whl
Algorithm Hash digest
SHA256 e3637eb695816e17a8ff1af18c623a21866ecfe8733d9d4d73303ea3391023c1
MD5 ae12ae50d65dbcad63da707ae65cba78
BLAKE2b-256 ed548c6e61982cee16d6cac2261d9b5514861d0c2e106d29ed5b9722c388f5de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page