Official Python SDK for SyncForge — control exactly when data syncs between your database and clients.
Project description
SyncForge Python SDK
Official Python SDK for the SyncForge data sync platform.
Control exactly when data syncs between your database and client applications — no polling, no wasted DB calls.
Installation
pip install syncforge
Zero external dependencies. Uses only Python stdlib (urllib, json, threading).
Quick Start
from syncforge import SyncForge
sf = SyncForge(api_key='sf_live_YOUR_KEY')
# After any DB write — notify all connected clients
sf.refresh('products')
The syncforge.py Pattern (Recommended)
Place a syncforge.py file at your project root — same level as manage.py or main.py.
This mirrors the Celery pattern and gives you a single shared instance.
# syncforge.py (project root)
import os
from syncforge import SyncForge
sf = SyncForge(
api_key=os.environ.get('SYNCFORGE_API_KEY', 'sf_live_YOUR_KEY')
)
Then import sf anywhere:
# views.py / routes.py
from syncforge import sf
def create_product(request):
Product.objects.create(name='New Item', price=99.99)
sf.refresh('products') # one line — all clients updated
return JsonResponse({'status': 'created'})
API Reference
SyncForge(api_key, base_url, timeout, silent, async_mode)
| Parameter | Default | Description |
|---|---|---|
api_key |
required | Your API key (sf_live_...) |
base_url |
https://syncforge.dev/api |
Override for local dev / self-hosted |
timeout |
10 |
HTTP timeout in seconds |
silent |
False |
Suppress errors — logs warnings instead of raising |
async_mode |
False |
Fire-and-forget — refresh runs in a background thread |
sf.refresh(*tables) → SyncResult | list[SyncResult]
sf.refresh('products') # single table
sf.refresh('products', 'categories', 'orders') # multiple at once
result = sf.refresh('products')
print(result.ok) # True
print(result.calls_saved) # 1854211
print(result.sync_mode) # 'Event — On INSERT / UPDATE / DELETE'
sf.ping() → bool
Health check — returns True if SyncForge is reachable.
sf.project_info() → dict
Returns project metadata and all registered tables.
sf.list_tables() → list
Lists all tables with their sync mode and stats.
Django Integration
# syncforge.py (next to manage.py)
import os
from syncforge import SyncForge
sf = SyncForge(api_key=os.environ.get('SYNCFORGE_API_KEY'))
# myapp/views.py
from syncforge import sf
def update_products(request):
Product.objects.filter(on_sale=True).update(price=F('price') * 0.9)
sf.refresh('products')
return JsonResponse({'status': 'updated'})
FastAPI Integration
from fastapi import FastAPI
from syncforge import sf
app = FastAPI()
@app.post("/products/")
async def create_product(name: str, price: float):
db.execute("INSERT INTO products ...")
sf.refresh('products')
return {"status": "ok"}
Production Tips
# Silent mode — SyncForge errors never crash your app
sf = SyncForge(api_key='sf_live_...', silent=True)
# Async mode — fire-and-forget, returns immediately
sf = SyncForge(api_key='sf_live_...', async_mode=True)
sf.refresh('products') # returns None, syncs in background
# Override base URL for local development
sf = SyncForge(api_key='sf_live_...', base_url='http://localhost:8000/api')
Error Handling
from syncforge import SyncForge, AuthError, TableNotFoundError, NetworkError
sf = SyncForge(api_key='sf_live_...')
try:
sf.refresh('products')
except AuthError:
print("Invalid API key")
except TableNotFoundError:
print("Register the table in your SyncForge dashboard first")
except NetworkError:
print("Could not reach SyncForge — check your internet connection")
License
MIT — see LICENSE
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
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 syncforge-1.0.1.tar.gz.
File metadata
- Download URL: syncforge-1.0.1.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7a59336a51857b34c0df1a30a005631cec7d7440de55a1f91c9091de3008e6d
|
|
| MD5 |
d09bdad6a02046b5a008e69e075dfe3b
|
|
| BLAKE2b-256 |
7dcb0d443a5d4398b643038f3e2545ac5b6e454ca0fa8e25a0cbcac0b9231c5b
|
File details
Details for the file syncforge-1.0.1-py3-none-any.whl.
File metadata
- Download URL: syncforge-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb207f4b20887780c1496f8a312d2b5208008893154377a923b7cfe7a4efc3e1
|
|
| MD5 |
f6d0645dc03f6a5be31500fae80c8812
|
|
| BLAKE2b-256 |
475b1dc16d75e3fc779a8e6fc29187c0a6c6dd0782b9f6713973272efc19c049
|