Skip to main content

Official Python SDK for SyncForge — control exactly when data syncs between your database and clients.

Project description

SyncForge Python SDK

PyPI Python License: MIT

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

syncforge-1.0.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

syncforge-1.0.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file syncforge-1.0.2.tar.gz.

File metadata

  • Download URL: syncforge-1.0.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for syncforge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 eec206e12cd2ea1b49f4116ae77427661fbebf6b88820d5100e4d0a9926ddbc9
MD5 b4b7baece77fed48d7059d44d430752f
BLAKE2b-256 e28c373a16e727bd1bab4aaa0c9d96c4f68011280e3c9805270a5e6f3864e225

See more details on using hashes here.

File details

Details for the file syncforge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: syncforge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for syncforge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a543b69e5bf5bdf5cabee29c57e4541584cf96ae0ade4d1231ff57465d73593f
MD5 890b9ad08bb466fbf09e81ddf6441d76
BLAKE2b-256 ceb5790be7f884e07781f975b15edce32c903d516dd8717c5a4ae4285dc610fb

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