Skip to main content

Backend sync engine for pulse-rn

Project description

Django Pulse

Backend engine for the pulse-rn React Native library.

Quick Start

  1. Install: pip install django-pulse
  2. 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_id on creation
  • Increment version on 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)],
        },
    },
}

Synchronization Flow

  1. Client Connects: WebSocket connection established
  2. Delta Sync Request: Client requests changes since last version
  3. Batch Upload: Client uploads pending local changes
  4. Real-time Updates: Server pushes changes to connected clients
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_pulse-1.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_pulse-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file django_pulse-1.0.1.tar.gz.

File metadata

  • Download URL: django_pulse-1.0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for django_pulse-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f82e29ae15633cce0169fa2ed6b04b56fb2e59afc32ee9e925519a656eaf8610
MD5 f71cf6e9e0c3b870d950054d4b310c7f
BLAKE2b-256 f9ebc459008460ec252664a7e6d74fe56cb2ac18aa78faa7da6bf47f9970900a

See more details on using hashes here.

File details

Details for the file django_pulse-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_pulse-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for django_pulse-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcb01ef755364dae008dccc21333cc729a1f2693d7e3c109ece64f73aa8f458b
MD5 96ac37829efa57b8adb861b286c23afd
BLAKE2b-256 0703b9e396560c83bca70d866b0a0d3ea00da7793c9fbcef12760bfd38b6e7ff

See more details on using hashes here.

Supported by

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