Skip to main content

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

Release files for sqlalchemy-sync-data 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-sync-data 0.0.1
File Size Uploaded
sqlalchemy_sync_data-0.0.1.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-sync-data 0.0.1
File Interpreter ABI Platform
sqlalchemy_sync_data-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.7 kB

Release files / sqlalchemy_sync_data-0.0.1.tar.gz

Download URL sqlalchemy_sync_data-0.0.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
960c0182536146f80f61b1fd3d935961aa5eb04deb7a8d8f3c6ae29eedcbbcb3
BLAKE2b-256 checksum
How to use checksums
f5b16bc35e9b663136a3296c3d8b8cc687c6af08c81c756e6825a586b4f0de83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure

Release files / sqlalchemy_sync_data-0.0.1-py3-none-any.whl

Download URL sqlalchemy_sync_data-0.0.1-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9dec67820935257caf3abadb0026c1d5f4d8acb66b7d6265557d29748985af2a
BLAKE2b-256 checksum
How to use checksums
e5283d2c406329816bb379830a1fd3d8b9e49271b4c90bcc96b7faa7232e19df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page