Synchronization of data from different sources into one database using SQLAlchemy as an ORM.
Project description
SQLAlchemy sync data
Synchronization of data from different sources into one database using SQLAlchemy.
Examples
# models.py
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String
CommonBase = declarative_base()
class User(CommonBase):
__tablename__ = "old_users"
id = Column(Integer, autoincrement=True, unique=True, primary_key=True, nullable=False)
first_name = Column(String(255), nullable=False)
last_name = Column(String(255), nullable=False)
username = Column(String(255), nullable=False)
# getters.py
from sqlalchemy_sync_data.getters import SQLiteGetter
class UserGetter(SQLiteGetter):
template_query = """select id, first_name, last_name, email from users"""
connection_settings = {"database": "sqlalchemy_sync_data.sqlite"}
# handlers.py
from sqlalchemy_sync_data.handlers import BaseHandler
from .getters import UserGetter
from .models import User
class UserHandler(BaseHandler):
model = User
db_fields_to_model_mapping = {
"id": "id",
"first_name": "first_name",
"last_name": "last_name",
"email": "username",
}
field_name_as_external_id = 'id'
getter_class = UserGetter
# synchronizators.py
from sqlalchemy_sync_data.synchronizator import BaseSyncronizator
from .handlers import UserHandler
class UserSyncronizator(BaseSyncronizator):
handler_classes = (UserHandler,)
# Run sync data
from .synchronizators import UserSyncronizator
syncronizator = UserSyncronizator()
syncronizator.run()
Environment variables
SQLALCHEMY_SYNC_DATA_LOCAL_TIMEZONE - setting time zone (default value "UTC").
Required
- python >=3.11, <4.0
- fastapi >=0.100.0, <1.0
- SQLAlchemy >=1.4.36, <2.1.0
- requests >=2.32.3
- psycopg2 >=2.9.5
- pytz >=2020.1
- environs >=9.3.1
Installation
pip install sqlalchemy-sync-data
Contribution
You can run tests with pytest.
pip install poetry
poetry install
pytest
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 sqlalchemy_sync_data-0.0.1.tar.gz.
File metadata
- Download URL: sqlalchemy_sync_data-0.0.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
960c0182536146f80f61b1fd3d935961aa5eb04deb7a8d8f3c6ae29eedcbbcb3
|
|
| MD5 |
2fba8334ef699f146d2a43fbce6b89ce
|
|
| BLAKE2b-256 |
f5b16bc35e9b663136a3296c3d8b8cc687c6af08c81c756e6825a586b4f0de83
|
File details
Details for the file sqlalchemy_sync_data-0.0.1-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_sync_data-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dec67820935257caf3abadb0026c1d5f4d8acb66b7d6265557d29748985af2a
|
|
| MD5 |
bd7632439d24415cec7ebc1928c2a7f7
|
|
| BLAKE2b-256 |
e5283d2c406329816bb379830a1fd3d8b9e49271b4c90bcc96b7faa7232e19df
|