Django Supabase
Professional, production-ready Supabase integration for Django.
Features
- 🔐 Authentication: Seamless Supabase Auth + Django User model sync
- 💾 Database: Direct PostgreSQL connection with Django ORM
- 📦 Storage: Django storage backends for Supabase Storage
- 🚀 Production-Ready: Connection pooling, caching, error handling
- 🔧 Django-Native: Uses Django's ecosystem and patterns
Installation
pip install django-supabase
Quick Setup
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'django_supabase',
'django_supabase.auth',
]
Configure Settings
SUPABASE_URL = 'https://your-project.supabase.co'
SUPABASE_KEY = 'your-publishable-or-anon-key'
SUPABASE_SECRET_KEY = 'your-secret-or-service-role-key' # server-side only
# Recommended default: ask Supabase Auth to validate bearer tokens.
SUPABASE_JWT_VERIFICATION = 'auth_server'
# Optional for projects using asymmetric JWT signing keys:
# SUPABASE_JWT_VERIFICATION = 'jwks'
# SUPABASE_JWT_ALGORITHMS = ['RS256', 'ES256']
# Legacy/local-only fallback for HS256 shared-secret verification:
# SUPABASE_JWT_VERIFICATION = 'jwt_secret'
# SUPABASE_JWT_SECRET = 'your-jwt-secret'
AUTH_USER_MODEL = 'supabase_auth.SupabaseUser'
AUTHENTICATION_BACKENDS = [
'django_supabase.auth.backends.SupabaseAuthBackend',
'django.contrib.auth.backends.ModelBackend',
]
DATABASES = {
'default': {
'ENGINE': 'django_supabase.db.engine.SupabasePostgreSQLEngine',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'your-password',
'HOST': 'db.your-project.supabase.co',
'PORT': 5432,
}
}
STORAGES = {
'default': {
'BACKEND': 'django_supabase.storage.backends.SupabaseMediaStorage',
},
'staticfiles': {
'BACKEND': 'django_supabase.storage.backends.SupabaseStaticStorage',
},
}
Run Migrations
python manage.py migrate
python manage.py create_storage_buckets
Usage Example
Authentication
from django.contrib.auth import authenticate
# Email/Password login
user = authenticate(email='user@example.com', password='password')
# JWT Token authentication (in views)
# Token automatically extracted from Authorization: Bearer <token>
Frontend OAuth
Use Supabase Auth in the frontend with a publishable key. After OAuth login, send the Supabase session access token to Django:
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: { redirectTo: 'https://your-frontend.example.com/auth/callback' },
})
const { data: sessionData } = await supabase.auth.getSession()
await fetch('/api/me/', {
headers: {
Authorization: `Bearer ${sessionData.session.access_token}`,
},
})
Django validates the bearer token through SupabaseAuthMiddleware and syncs the
local user by Supabase sub / user.id, not by email alone.
File Upload
from django_supabase.storage.utils import upload_file_to_supabase
file = ...
url = upload_file_to_supabase(file, 'media', path='uploads/')
Direct Supabase Queries
from django_supabase.db.client import get_supabase_client
supabase = get_supabase_client()
response = supabase.table('posts').select('*').execute()
Test
# supabase_integration/tests.py
from django.test import TestCase
from django.contrib.auth import get_user_model
from django_supabase.db.client import get_supabase_client
User = get_user_model()
class SupabaseIntegrationTestCase(TestCase):
"""Base test case with Supabase utilities"""
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.supabase = get_supabase_client()
def create_test_user(self, email='test@example.com'):
"""Helper to create test users"""
return User.objects.create_user(
username=email,
email=email,
password='testpass123'
)
Metadata
Release files for django-supabase 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_supabase-1.0.0.tar.gz | 14.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_supabase-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.3 kB
Release files / django_supabase-1.0.0.tar.gz
| Download URL | django_supabase-1.0.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07a96a24837c405c550d7b99fea529ffff20fc840fa69a94575378ed87147144
|
|
BLAKE2b-256 checksum How to use checksums |
a62b4f21d5af64bb9ede791d8a64e623203dc05231577d6066d94329c0367830
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / django_supabase-1.0.0-py3-none-any.whl
| Download URL | django_supabase-1.0.0-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2f482d422a1dd7eb7ebd5415bf96adbd4a4c6d92781739528abaebfe49f4047
|
|
BLAKE2b-256 checksum How to use checksums |
d6e736c74676f406ab653e0fba6ffbbd82da696d7b3d3e6cba2d2e13d894d462
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|