Python
import os, sys
import django
PROJECTPATH = 'absolute/path/to/project'
sys.path.insert(0, PROJECTPATH)
print(os.getcwd())
# strangely you can only run this once
# if you run it with the wrong setting, restart your kernel
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "relative.path.to.settings")
print(os.environ["DJANGO_SETTINGS_MODULE"])
# https://docs.djangoproject.com/en/5.0/topics/async/#async-safety
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
os.chdir(PROJECTPATH)
django.setup()
Python
from django.conf import settings
print(settings.DATABASES)