Data information synchronization
Project description
Datamation
特性
- 不同数据库中大批量数据的导入、导出,ETL数据同步
- 关系型数据库的数据导入到ElsticSearch
- 数据库表结构差异比对、整表数据差异比对,定位到行列级别
- 消息通知,支持邮件、钉钉、企业微信
安装
- 拉取git项目到本地
- 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)
- 当主键为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.1.tar.gz
(65.4 kB
view details)
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 datamation-0.1.1.tar.gz.
File metadata
- Download URL: datamation-0.1.1.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.9.12 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
370bcb43579b747bbd762304422f71993267ff8d038f856bb8507703da4903a9
|
|
| MD5 |
4a7d222fdd7b2582dbf9e4a800caa073
|
|
| BLAKE2b-256 |
861f0a7473e815038f6285fccc236d9d3be3f4f62d615d390406ea13c444b257
|
File details
Details for the file datamation-0.1.1-py3-none-any.whl.
File metadata
- Download URL: datamation-0.1.1-py3-none-any.whl
- Upload date:
- Size: 78.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.9.12 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f7b2c5bda39320b39e327307d9bc03089abce71771f55a94a7c105a8aaaa89a
|
|
| MD5 |
51b5e4bf358118a6458200dc436235f3
|
|
| BLAKE2b-256 |
06b2fb12270300e406779382230499e28a85fa2594aafe62583546ef5d99630e
|