Skip to main content

Data information synchronization

Project description

Datamation

PyPI - Python Version

特性

  • 不同数据库中大批量数据的导入、导出,ETL数据同步
  • 关系型数据库的数据导入到ElsticSearch
  • 数据库表结构差异比对、整表数据差异比对,定位到行列级别
  • 消息通知,支持邮件、钉钉、企业微信

安装

  1. 拉取git项目到本地
  2. pip install datamation

基本使用

初始化连接

import pymysql 
import datamation as dm

# 创建数据源连接
src_conn = lambda:pymysql.connect(host='127.0.0.1',user='root',passwd='xxx',database='demo',port=13307,write_timeout=50000,connect_timeout=20000)

# 创建目标数据库连接
tag_conn = lambda:pymysql.connect(host='127.0.0.1',user='root',passwd='xxx',database='demo',port=13306,read_timeout=50000,connect_timeout=10000)

示例1

dm.sqlsync(
        src_conn = src_conn,
        src_table='table1',
        tag_conn = tag_conn,
        tag_table='table2',
        batch_size=20000, # 批量写入行数
        truncate=True   # 同步开始时使用truncate命令清空目标数据表
        ) 

示例2

src = dm.source_sql(src_conn,'table1')
tag = dm.table_basic(tag_conn,'table1',columns =['col1','col2','col3'],batch_size=20000)
for row in src:
    tag.insert(row)
tag.endload()
数据库差异检测

校验两个数据表数据值是否一致,返回差异数据 1 当主键为数值类型时,使用主键进行比对

comp = dm.get_sqldata_diff2(src_conn,tag_conn,'tb_data','tb_data_copy1',compare_field='id')
print(comp)
  1. 当主键为uuid类型时
comp = dm.get_sqldata_diff1(src_conn,tag_conn,'tb_data','tb_data_copy1',compare_field='id',)
print(comp)

表结构差异比对 基于sqlalchemy

comp = dm.get_sqldb_diff(src_conn,tag_conn,'tb_data','tb_data_copy1')
print(comp)
消息通知

集成有邮件、钉钉、企业微信的消息推送

邮件消息发送 示例1

# 示例1
import datamation as dm
tm = dm.to_mail(user,passwd,host)
tm.name('hello word',to = ['xxx@xx.com','xxx@xxx.com'],
                            cc=  ['xxx@xx.com','xxx@xxx.com'],
                            bcc=  ['xxx@xx.com','xxx@xxx.com'],
            showname = 'datamation')
tm.add_text('hello word')
tm.add_html('<p> hello word</p> <img src=cid:image001.jpg style="height:71px; width:116px" />')
tm.add_related({'image001.jpg':'data/image001.jpg'}) # 添加在html中引用显示的图片内容
tm.add_attachment({'data.xlsx':'/data/data.xlsx'}) # 添加附件
tm.send()

示例2

# 示例2
import datamation as dm
tm = dm.to_mail(user,passwd,host)
tm.send('hello word',
        to = ['xxx@xx.com'],
        cc=  [''],
        bcc= [''],
        showname = 'datamation',
        related = {'image001.jpg':'data/image001.jpg'},
        attachment = {'data.xlsx':'/data/data.xlsx'})

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

datamation-0.1.2.tar.gz (66.7 kB view details)

Uploaded Source

Built Distribution

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

datamation-0.1.2-py3-none-any.whl (79.8 kB view details)

Uploaded Python 3

File details

Details for the file datamation-0.1.2.tar.gz.

File metadata

  • Download URL: datamation-0.1.2.tar.gz
  • Upload date:
  • Size: 66.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.12 Darwin/24.1.0

File hashes

Hashes for datamation-0.1.2.tar.gz
Algorithm Hash digest
SHA256 60e018207365b9dd029e3291a2409776241663e33666a05eff4c6cc59c4999e7
MD5 c3e0f5e5da73086fd61210efee6a0f94
BLAKE2b-256 f799043e0ff927e2f3e387a81e98f825ab0b6fbd99f6dd1bbd3641b6925a1c07

See more details on using hashes here.

File details

Details for the file datamation-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: datamation-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 79.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.12 Darwin/24.1.0

File hashes

Hashes for datamation-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 335cf3a2df1ba14158d44d97adb4942a02f5c72384fba18361321a48206ccd42
MD5 11bc85892d2c8b570067c7af3134d366
BLAKE2b-256 a70816d2d6ede2100ede93e0f4ed38f82db85b0d25d8c0f1d00b96b137ffb11a

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