A package for backend-frontend data synchronization without API endpoints
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
๐ dsn-sync
Revolutionary Backend-Frontend Data Synchronization Without API Endpoints
Features โข Installation โข Quick Start โข Usage Examples โข Advanced Features
๐ Overview
dsn-sync is a groundbreaking Python package that enables seamless data synchronization between your backend and frontend without requiring any API endpoints, REST APIs, WebSocket connections, Firebase, Celery, Redis, or Webhooks.
Simply install the package, define your schemas, and watch as your frontend automatically syncs data in real-time through a secure, encrypted channel.
โจ Why dsn-sync?
- ๐ซ No API Endpoints - Zero REST API or WebSocket setup required
- ๐ซ No Firebase - Self-hosted solution, no vendor lock-in
- ๐ซ No Celery/Redis - Built-in auto-tasks without external dependencies
- ๐ซ No Webhooks - Direct encrypted communication
- โก Auto-Sync - Frontend automatically creates tables and syncs data
- ๐ Key-Based - Simple key-based data synchronization
- ๐ Secure - Encrypted communication, dynamic endpoints
- ๐ฆ Easy Setup - Install and start using in minutes
- ๐ Real-Time - Automatic data synchronization
- ๐ฏ Schema-Driven - Define once, sync everywhere
๐ฏ Features
- โ Zero API Configuration - No need to create API endpoints
- โ Automatic URL Generation - Unique sync URL generated on installation
- โ Schema Definition - Define your data structure once
- โ Auto Table Creation - Frontend automatically creates matching tables
- โ Key-Based Sync - Simple and efficient data synchronization
- โ Real-Time Updates - Data changes reflect automatically
- โ CRUD Operations - Create, Read, Update, Delete data
- โ Get All Data - Fetch all records from a table
- โ Get Single Data - Fetch single record by ID/key
- โ Auto Tasks - Background tasks without Celery/Redis
- โ Notifications - Real-time notifications without Firebase/WebSocket
- โ Chat System - Chat functionality without WebSocket/API
- โ Chart Data Flow - Real-time data for charts and analytics
- โ Lightweight - Minimal dependencies, fast performance
๐ฆ Installation
Backend (Python)
pip install dsn-sync
Frontend (JavaScript)
npm install dsn-sync-client
๐ Quick Start
Backend Setup
from dsn_sync import DSNSync
# Initialize dsn-sync
sync = DSNSync(port=3000)
# Start embedded server
sync.start()
# Get the unique sync URL (share this with frontend)
sync_url = sync.get_url()
print(f"Sync URL: {sync_url}")
# Get authentication token
token = sync.get_token()
print(f"Token: {token}")
# Define your schema
sync.define_table('users', {
'key': 'user_id',
'fields': ['name', 'email', 'cart', 'status']
})
# Sync data (READ operation - Backend โ Frontend)
sync.sync('users', 'user_123', {
'name': 'John Doe',
'email': 'john@example.com',
'cart': [],
'status': 'active'
})
Frontend Setup
import { connectDSN } from 'dsn-sync-client';
// Connect using the URL and token from backend
const client = connectDSN('https://localhost:3000/sync/001', 'YOUR_TOKEN');
// Data automatically syncs to IndexedDB
// Tables are created automatically based on schema
๐ Usage Examples
1. Get All Data
Backend:
# Sync multiple records
sync.sync('users', 'user_001', {'name': 'John', 'email': 'john@example.com'})
sync.sync('users', 'user_002', {'name': 'Jane', 'email': 'jane@example.com'})
sync.sync('users', 'user_003', {'name': 'Bob', 'email': 'bob@example.com'})
Frontend:
// Get all users
const allUsers = await client.getAll('users');
console.log(allUsers);
// Output: {
// 'user_001': {name: 'John', email: 'john@example.com'},
// 'user_002': {name: 'Jane', email: 'jane@example.com'},
// 'user_003': {name: 'Bob', email: 'bob@example.com'}
// }
2. Get Single Data by ID/Key
Frontend:
// Get single user by ID
const user = await client.get('users', 'user_001');
console.log(user);
// Output: {name: 'John', email: 'john@example.com'}
3. Create Data (WRITE - Frontend โ Backend)
Backend:
# Register event handler for create
@sync.on_create('users')
def handle_user_create(data):
# data contains: {'user_id': 'user_004', 'name': 'Alice', ...}
print(f"New user created: {data['name']}")
# Save to your database
# db.save_user(data)
# Update RAM (automatic)
# sync.sync('users', data['user_id'], data)
return True
Frontend:
// Create new user
await client.create('users', 'user_004', {
name: 'Alice',
email: 'alice@example.com',
cart: [],
status: 'active'
});
// This triggers @sync.on_create('users') in backend
4. Update Data
Backend:
@sync.on_update('users')
def handle_user_update(data):
# data contains updated fields
print(f"User updated: {data}")
# Update your database
# db.update_user(data['user_id'], data)
return True
Frontend:
// Update user
await client.update('users', 'user_001', {
name: 'John Updated',
status: 'inactive'
});
// This triggers @sync.on_update('users') in backend
5. Delete Data
Backend:
@sync.on_delete('users')
def handle_user_delete(data):
# data contains: {'user_id': 'user_001'}
print(f"User deleted: {data['user_id']}")
# Delete from your database
# db.delete_user(data['user_id'])
return True
Frontend:
// Delete user
await client.delete('users', 'user_001');
// This triggers @sync.on_delete('users') in backend
๐ Complete Data Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TWO-WAY DATA FLOW โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
BACKEND โ FRONTEND (READ)
โโโโโโโโโโโโโโโโโโโโโโโโโ
Backend: sync('users', 'user_123', {...})
โ
Encrypt Data
โ
Embedded Server
โ
Frontend: Receives & Decrypts
โ
Store in IndexedDB
โ
UI Updates Automatically
FRONTEND โ BACKEND (WRITE)
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
Frontend: client.create('users', 'user_123', {...})
โ
Encrypt & Sign
โ
Send to Backend
โ
Backend: Decrypt & Validate
โ
Trigger @sync.on_create()
โ
Save to Database + RAM
โ
Response to Frontend
๐ฏ Advanced Features
1. Auto Tasks (Without Celery/Redis)
Backend:
import time
from threading import Thread
# Auto task example - runs in background
def auto_task():
while True:
# Your background task logic
print("Auto task running...")
# Sync data automatically
sync.sync('tasks', 'task_001', {
'status': 'running',
'timestamp': time.time()
})
time.sleep(60) # Run every minute
# Start auto task
task_thread = Thread(target=auto_task, daemon=True)
task_thread.start()
# No Celery, No Redis needed!
2. Notifications (Without Firebase/WebSocket)
Backend:
# Define notifications table
sync.define_table('notifications', {
'key': 'notification_id',
'fields': ['user_id', 'message', 'type', 'read', 'timestamp']
})
# Send notification
sync.sync('notifications', 'notif_001', {
'user_id': 'user_123',
'message': 'You have a new message',
'type': 'info',
'read': False,
'timestamp': time.time()
})
Frontend:
// Listen for notifications
client.onDataChange('notifications', (notifications) => {
const unread = Object.values(notifications).filter(n => !n.read);
showNotificationBadge(unread.length);
});
// Mark as read
await client.update('notifications', 'notif_001', {read: true});
3. Chat System (Without WebSocket/API)
Backend:
# Define messages table
sync.define_table('messages', {
'key': 'message_id',
'fields': ['from_user', 'to_user', 'message', 'timestamp', 'read']
})
@sync.on_create('messages')
def handle_new_message(data):
# data contains new message
print(f"New message: {data['message']}")
# Save to database
# db.save_message(data)
# Notify recipient
sync.sync('notifications', f"notif_{data['message_id']}", {
'user_id': data['to_user'],
'message': f"New message from {data['from_user']}",
'type': 'message',
'read': False,
'timestamp': time.time()
})
return True
Frontend:
// Send message
await client.create('messages', `msg_${Date.now()}`, {
from_user: 'user_123',
to_user: 'user_456',
message: 'Hello!',
timestamp: Date.now(),
read: false
});
// Get all messages
const messages = await client.getAll('messages');
// Get messages for specific user
const userMessages = Object.values(messages).filter(
msg => msg.to_user === 'user_123' || msg.from_user === 'user_123'
);
4. Chart Data Flow (Real-time Analytics)
Backend:
# Define analytics table
sync.define_table('analytics', {
'key': 'record_id',
'fields': ['metric', 'value', 'timestamp', 'category']
})
# Auto-update chart data
def update_chart_data():
while True:
# Collect metrics
metrics = {
'users_online': get_online_users_count(),
'sales_today': get_sales_today(),
'page_views': get_page_views()
}
for metric, value in metrics.items():
sync.sync('analytics', f"{metric}_{int(time.time())}", {
'metric': metric,
'value': value,
'timestamp': time.time(),
'category': 'realtime'
})
time.sleep(5) # Update every 5 seconds
# Start chart data updates
chart_thread = Thread(target=update_chart_data, daemon=True)
chart_thread.start()
Frontend:
// Get chart data
const chartData = await client.getAll('analytics');
// Filter by metric
const salesData = Object.values(chartData)
.filter(d => d.metric === 'sales_today')
.sort((a, b) => a.timestamp - b.timestamp);
// Update chart
updateChart(salesData);
// Real-time updates
client.onDataChange('analytics', (data) => {
const salesData = Object.values(data)
.filter(d => d.metric === 'sales_today')
.sort((a, b) => a.timestamp - b.timestamp);
updateChart(salesData);
});
๐ง Complete Example: E-commerce Application
Backend
from dsn_sync import DSNSync
import time
from threading import Thread
sync = DSNSync(port=3000)
sync.start()
url = sync.get_url()
token = sync.get_token()
print(f"URL: {url}")
print(f"Token: {token}")
# Define schemas
sync.define_table('products', {
'key': 'product_id',
'fields': ['name', 'price', 'description', 'image', 'stock']
})
sync.define_table('cart', {
'key': 'user_id',
'fields': ['items', 'total']
})
sync.define_table('orders', {
'key': 'order_id',
'fields': ['user_id', 'items', 'total', 'status', 'timestamp']
})
# Event handlers
@sync.on_create('cart')
def handle_cart_update(data):
print(f"Cart updated for user: {data['user_id']}")
# Save to database
return True
@sync.on_create('orders')
def handle_order_create(data):
print(f"New order: {data['order_id']}")
# Process order
# Update inventory
return True
# Sync products
sync.sync('products', 'prod_001', {
'name': 'Laptop',
'price': 999.99,
'description': 'High-performance laptop',
'image': 'laptop.jpg',
'stock': 50
})
# Auto task - update stock
def update_stock():
while True:
# Check and update stock
sync.sync('products', 'prod_001', {
'stock': get_current_stock('prod_001')
})
time.sleep(300) # Every 5 minutes
Thread(target=update_stock, daemon=True).start()
Frontend
import { connectDSN } from 'dsn-sync-client';
const client = connectDSN('YOUR_URL', 'YOUR_TOKEN');
// Get all products
const products = await client.getAll('products');
// Get single product
const laptop = await client.get('products', 'prod_001');
// Add to cart
await client.create('cart', 'user_123', {
items: ['prod_001', 'prod_002'],
total: 1499.98
});
// Get cart
const cart = await client.get('cart', 'user_123');
// Place order
await client.create('orders', `order_${Date.now()}`, {
user_id: 'user_123',
items: cart.items,
total: cart.total,
status: 'pending',
timestamp: Date.now()
});
// Real-time updates
client.onDataChange('products', (products) => {
updateProductList(products);
});
client.onDataChange('orders', (orders) => {
updateOrderStatus(orders);
});
๐ API Reference
Backend (Python)
DSNSync(port=3000, db_connection_string=None)
Initialize dsn-sync instance.
get_url() -> str
Get connection URL for frontend.
get_token() -> str
Get authentication token.
start() -> bool
Start embedded server.
stop() -> bool
Stop embedded server.
define_table(table_name: str, schema: dict) -> bool
Define table schema.
sync(table_name: str, key: str, data: dict) -> bool
Sync data to frontend (READ operation).
on_create(table_name: str)
Decorator for create event handler.
on_update(table_name: str)
Decorator for update event handler.
on_delete(table_name: str)
Decorator for delete event handler.
Frontend (JavaScript)
connectDSN(url: string, token: string) -> Client
Connect to dsn-sync server.
client.getAll(table_name: string) -> Promise<Object>
Get all data from table.
client.get(table_name: string, key: string) -> Promise<Object>
Get single record by key.
client.create(table_name: string, key: string, data: Object) -> Promise<boolean>
Create new record.
client.update(table_name: string, key: string, data: Object) -> Promise<boolean>
Update existing record.
client.delete(table_name: string, key: string) -> Promise<boolean>
Delete record.
client.onDataChange(table_name: string, callback: Function) -> void
Listen for data changes.
๐ ๏ธ Requirements
- Python 3.7+
- cryptography>=41.0.0
- Node.js 14+ (for frontend package)
๐ Security Features
- โ Encrypted communication (HTTPS)
- โ Dynamic endpoint rotation (every 100 requests)
- โ Secure key management (never in URLs)
- โ Token-based authentication
- โ Signature validation
๐ License
This project is licensed under the MIT License.
๐ค Author
Satish Choudhary
- Email: satishchoudhary394@gmail.com
- GitHub: @python-hacked
๐ค Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
โญ Show Your Support
Give a โญ๏ธ if this project helped you!
Made with โค๏ธ by Satish Choudhary
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 dsn_sync-0.1.0.tar.gz.
File metadata
- Download URL: dsn_sync-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33f35e9e74ca6bb7cf8754fde88b53c52de384442087aeaa8ea74f49f22b5ecf
|
|
| MD5 |
8ac3ce2a30d9ce4821c0d1fb2262c98b
|
|
| BLAKE2b-256 |
18d4fb8622c61cb85b46d88b39282468fda82f15960f20f8c11428b9af9a9e15
|
File details
Details for the file dsn_sync-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dsn_sync-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2d390d805cf810a1810b27b85b84632791cf0a609250165aa940faa3d4454f6
|
|
| MD5 |
8088f0de52e09dc2ce219ad2c12d15b9
|
|
| BLAKE2b-256 |
13f041439b5b15613d04f2a66b1d499df5d2db719bcb805584783a1a8b817300
|