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.0.tar.gz
(65.5 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.0.tar.gz.
File metadata
- Download URL: datamation-0.1.0.tar.gz
- Upload date:
- Size: 65.5 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 |
6166afb23493880628dd46ecf16e4ea24460d226493a7c6057e8db351d5602c7
|
|
| MD5 |
9fb573bf6ae7ba5b3cf21787fa25cfea
|
|
| BLAKE2b-256 |
5bcc00073dd834b01e66c286dc1b780cfe5642655a169120a6bca1e934e84cf0
|
File details
Details for the file datamation-0.1.0-py3-none-any.whl.
File metadata
- Download URL: datamation-0.1.0-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 |
c1f120ba41ce6fa4d397fcae370a19d01dd0bddaac50346633b1335b81903846
|
|
| MD5 |
1ea3c90c76bbfe1d97737410e6707234
|
|
| BLAKE2b-256 |
bcefe5a94a7bfcfb71990190e53ad76f7ec14fde14968fed9fba8e38dcb9ea9f
|