Backend sync engine for pulse-rn
Project description
Django Pulse
Backend engine for the pulse-rn React Native library.
Quick Start
- Install:
pip install django-pulse - Add to
INSTALLED_APPS:INSTALLED_APPS = [ ..., 'channels', 'django_pulse', ]
Model Inheritance
To enable synchronization for your models, inherit from SyncModel instead of models.Model:
from django_pulse.models import SyncModel
from django.db import models
class Task(SyncModel):
title = models.CharField(max_length=200)
description = models.TextField(blank=True)
completed = models.BooleanField(default=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
class Item(SyncModel):
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
SyncModel Features
When you inherit from SyncModel, your models automatically get these fields:
| Field | Type | Description |
|---|---|---|
sync_id |
UUIDField | Unique identifier for synchronization |
version |
PositiveIntegerField | Version number for conflict resolution |
is_local_only |
BooleanField | Marks records pending sync |
sync_error |
TextField | Stores sync error messages |
created_at |
DateTimeField | Auto-created timestamp |
updated_at |
DateTimeField | Auto-updated timestamp |
Automatic Synchronization
All models inheriting from SyncModel will:
- Automatically generate UUID
sync_idon creation - Increment
versionon each update - Track synchronization status with
is_local_only - Log synchronization errors in
sync_error - Participate in real-time WebSocket updates
User-Specific Sync
If your model has a user field (ForeignKey to User), synchronization will be scoped to that user:
class Task(SyncModel):
title = models.CharField(max_length=200)
user = models.ForeignKey(User, on_delete=models.CASCADE) # User-specific sync
Models without a user field will sync globally to all connected clients.
WebSocket Configuration
Add the WebSocket routing to your asgi.py:
from django_pulse.routing import websocket_urlpatterns
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": URLRouter(
websocket_urlpatterns
),
})
Required Settings
Ensure these settings are configured in your settings.py:
# Channels configuration
ASGI_APPLICATION = 'your_project.asgi.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [('127.0.0.1', 6379)],
},
},
}
API Endpoints
The library automatically creates these WebSocket endpoints:
ws://localhost:8000/ws/pulse/sync/- Main synchronization endpoint
Synchronization Flow
- Client Connects: WebSocket connection established
- Delta Sync Request: Client requests changes since last version
- Batch Upload: Client uploads pending local changes
- Real-time Updates: Server pushes changes to connected clients
- Conflict Resolution: Server resolves version conflicts
Example Usage
# Create a synced task
task = Task.objects.create(
title="Complete project",
description="Finish Django Pulse library",
user=request.user
)
# Update with automatic version increment
task.title = "Updated project title"
task.save() # Automatically increments version
# All changes are automatically synced to connected mobile clients
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_pulse-1.0.0.tar.gz.
File metadata
- Download URL: django_pulse-1.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d2558ff7c47dcdf5b2ccbe503077c1377c76ed8c8baa89f3567b65495d59fea
|
|
| MD5 |
a7bb5b9ce2ce489950a35a8a8b9334b8
|
|
| BLAKE2b-256 |
c94c6a8e37e530b36a6e8549469744b569d77c2d85a3154f7df35346385ece12
|
File details
Details for the file django_pulse-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_pulse-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17ec8dfb8f26a9c8b494ef4307984769578fa873d1a2666cba0fbc1e2d96c421
|
|
| MD5 |
f57bd96d725ce2f764b7e808bca090cf
|
|
| BLAKE2b-256 |
28b161a4e9d014748ebf15b671bebcc3d970adc327a6292fd355a2a40b319f0e
|