Skip to Content
FeaturesModulesCloudflare D1User Sync

User Sync

django_cf automatically mirrors Django users into a Cloudflare D1 users table. This makes user data available at the edge for low-latency lookups, analytics, and integrations.


Sync Flow

The signal fires on every save — creates and updates. The RQ task runs asynchronously, so the HTTP response is never delayed.


Automatic Sync

Enabled by default when sync_users=True (the default). No extra configuration needed.

To disable:

cloudflare: CloudflareConfig = CloudflareConfig( enabled=True, # ... sync_users=False, )

Bulk Sync

To sync all existing users (e.g. after first setup or after enabling the module on an existing project):

python manage.py cf_sync_users

Options:

# Sync in batches of 100 instead of default 500 python manage.py cf_sync_users --batch-size 100 # Dry run — show counts without writing to D1 python manage.py cf_sync_users --dry-run

full_sync_users() iterates all CustomUser records, batches them by sync_batch_size, and upserts each batch to D1.


Users Table Schema

ColumnTypeDescription
idTEXTDjango user UUID (primary key)
api_urlTEXTProject API URL (composite PK)
emailTEXTUser email
usernameTEXTUsername
first_nameTEXTFirst name
last_nameTEXTLast name
is_activeINTEGER0 / 1
is_staffINTEGER0 / 1
date_joinedTEXTISO 8601
updated_atTEXTISO 8601 — last sync time

Public API

from django_cfg.modules.django_cf import get_service from django_cfg.modules.django_cf.users.types import UserSyncData service = get_service() # Push a single user data = UserSyncData.from_user(user, api_url="https://api.example.com") service.push_user(data) # Bulk sync all users service.full_sync_users(api_url="https://api.example.com", batch_size=500)

See Also

  • Configurationsync_users, sync_batch_size
  • Overview — Architecture and BaseD1Service
  • D1Q — SQL factory used by UserSyncService

TAGS: django_cf, user-sync, cloudflare-d1, rq DEPENDS_ON: [django-cf/overview]

Last updated on