A Django package for database synchronization
Project description
Django Sync
Django Sync is a powerful Django utility that enables seamless data synchronization between two databases. It is designed to be simple to configure and flexible to use, supporting both manual and automatic synchronization.
Features
- Directional Sync: Synchronize data from a
defaultdatabase to aslavedatabase, or vice-versa. - Manual Sync Command: A
sync_datamanagement command with directional control. - Automatic Sync: Automatically syncs data on model save and delete operations.
- Flexible Configuration: Easily configure which models and fields to include or exclude from synchronization.
Installation
-
Install the package from PyPI:
pip install django-sync-package
-
Add
'sync'to yourINSTALLED_APPSinsettings.py:INSTALLED_APPS = [ # ... other apps 'sync', ]
Configuration
-
Databases: In your
settings.py, define yourdefault(master) database and aslavedatabase connection.DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'db_master', # ... other settings }, 'slave': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'db_slave', # ... other settings } }
-
Sync Configuration: Add a
SYNC_CONFIGdictionary to yoursettings.pyto specify which models to sync.SYNC_CONFIG = { 'MODELS': [ 'auth.User', 'yourapp.YourModel', ], 'EXCLUDE': { 'auth.User': ['password', 'last_login', 'date_joined'], } }
Usage
Manual Synchronization
The sync_data management command allows you to perform a uni-directional sync. You can control the direction with the --direction flag.
-
Push data from
defaulttoslave:python manage.py sync_data --direction=master-to-slave
-
Pull data from
slavetodefault:python manage.py sync_data --direction=slave-to-master
Example: Syncing Two Instances
If you are running two separate instances of a project (e.g., on different servers), you can keep them in sync by configuring each instance to recognize the other's database and running a two-step sync process:
- Pull changes from the remote instance:
python manage.py sync_data --direction=slave-to-master - Push local changes to the remote instance:
python manage.py sync_data --direction=master-to-slave
Automatic Synchronization
By default, Django Sync will automatically trigger a synchronization whenever a model included in SYNC_CONFIG is saved or deleted.
- When an object is created, updated, or deleted in the
defaultdatabase, the change is automatically propagated to theslavedatabase. - This provides a simple way to maintain a real-time replica of your data.
Running Tests
To run the built-in tests for the sync app:
python manage.py test sync
Contributing
Contributions are welcome! If you have a feature request, bug report, or a pull request, please feel free to open an issue or submit a PR on the project's GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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_sync_package-0.1.0.tar.gz.
File metadata
- Download URL: django_sync_package-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264d8824a983fb3ab1e7b68a2a1c34497e9ce25753a5c35e3ed17610a0590505
|
|
| MD5 |
68db7aca21692a7adffe096f1db58205
|
|
| BLAKE2b-256 |
04181a26746bdf3dff334173fc56d790279224329a6bacd25911017b571b94e9
|
File details
Details for the file django_sync_package-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_sync_package-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c8c0fbc2647afea6545cf3ec4249547aa7ba7cc7268dfef22655e2e3fb51b3f
|
|
| MD5 |
33c2b77f9c769001f0bfad9a96efd2a1
|
|
| BLAKE2b-256 |
218f75108ed9ea3d5725916ff151d346aba8cf4e055fe7d5cdcfb552babf883c
|