python utils
Project description
jcutils - Python 多功能工具库
一个高效封装的 Python 工具库,集成数据库客户端、云服务 API、消息队列及常用开发工具,助力快速开发与运维自动化。
特性
- 🚀 开箱即用:统一接口设计,降低学习成本
- 🛡️ 生产级代码:内置连接池、异常重试、日志记录
- 📦 模块化设计:按需引用,无冗余依赖
- 📝 完整类型注解:Python 3.8+ 兼容,支持 IDE 智能提示
核心模块
Client(客户端)
数据库客户端
-
关系型数据库
mysql_client.py/mysql_client_async.py:MySQL 客户端(同步/异步)postgres_client.py/postgres_client_async.py:PostgreSQL 客户端(同步/异步)mssql_client.py:SQL Server 客户端sqlite3_client.py:SQLite 客户端PyodbcClient.py:通用 ODBC 客户端
-
OLAP/大数据
clickhouse_client.py:ClickHouse 客户端presto_client.py:Presto/Trino 客户端hive_client.py:Hive 客户端
-
NoSQL
mongo_client.py:MongoDB 客户端redis_client.py:Redis 客户端elasticsearch_client.py:Elasticsearch 客户端hbase_client.py/hbase_thrift2_client.py:HBase 客户端
云服务与存储
maxcompute_client.py:阿里云 MaxCompute(ODPS)dataworks_client.py:阿里云 DataWorkss3_client.py:AWS S3 兼容存储qiniu_client.py:七牛云存储hdfs_client.py:HDFS 客户端
消息与通信
kafka_client.py:Kafka 客户端work_weixin_bot.py/work_weixin_api.py:企业微信机器人/APIwork_weixin_send.py:企业微信消息推送weixin_offiaccount.py:微信公众号工具
其他
ftp_client.py:FTP 客户端ldap_client.py:LDAP 客户端imaplib_client.py:IMAP 邮件客户端
Utils(工具集)
日期时间
datetime_.py:日期时间操作(转换、计算、范围查询)relative_time.py:相对时间计算(如"3分钟前")date_encoder.py:日期 JSON 序列化
性能监控
run_time.py/run_func_time.py:函数执行时间装饰器run_line_time.py:行级性能分析装饰器run_log_time.py:带日志的执行时间装饰器Tool.py:重试装饰器、超时控制等
格式化与处理
format_utils.py:字符串格式化(支持宽字符)tabulate_utils.py:表格美化输出html.py/htmlstrip.py:HTML 标签去除
开发工具
try_except_.py:异常捕获装饰器logging_.py:日志配置工具tool_threading.py:多线程工具lazy_import.py:懒加载模块导入
系统与网络
os_path.py/os_platform.py/platform_.py:系统平台检测nginx_log.py:Nginx 日志分析apscheduler_.py:Cron 定时任务触发器
地理位置
geo.py/regeo.py/geapi.py:高德地图地理编码
其他
convert.py:类型转换工具built_in_tools.py:pickle 序列化工具save_data.py:CSV 文件保存dingtalkoapi.py:钉钉 API 客户端
安装
pip install jcutils
快速开始
数据库查询
from jcutils.client.clickhouse_client import ClickHouseClient
client = ClickHouseClient(host="localhost", user="default")
result = client.execute("SELECT * FROM system.tables")
print(result)
消息推送
from jcutils.client.work_weixin_bot import WeixinBot
bot = WeixinBot(webhook_url="YOUR_WEBHOOK")
bot.send_text("Alert: 服务器CPU负载超过90%")
性能监控
from jcutils.utils.run_func_time import run_time
@run_time
def slow_function():
import time
time.sleep(2)
slow_function() # 输出执行时间
日期处理
from jcutils.utils.datetime_ import day_ops, dt2ts, ts2dt
# 当前时间加一天
print(day_ops(days=1))
# 时间戳转换
print(ts2dt(1640995200))
文档
详细文档请参考:
贡献
欢迎提交 Issue 或 Pull Request!
License
MIT
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
jcutils-0.4.0.tar.gz
(345.2 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 jcutils-0.4.0.tar.gz.
File metadata
- Download URL: jcutils-0.4.0.tar.gz
- Upload date:
- Size: 345.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a12c43cbdc9693aa0e4dd5631259b68de266d18fa135047e086c12a927f042c
|
|
| MD5 |
1c7daf237839c8ce0fbc7fffc70e9545
|
|
| BLAKE2b-256 |
6879eba95aa3aa8b36f1b2d2f7c45cd08f3f91bffb481e2c4cbf49fa8d823c7d
|
File details
Details for the file jcutils-0.4.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: jcutils-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 354.9 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a90ba0d7c9040220b9b83dd3974cd4da3779bc5250d0bfb14ac03f52f928874
|
|
| MD5 |
aa28e5e3423fbda00ceca5fb88d4a699
|
|
| BLAKE2b-256 |
d5386a5ba7f385cc0c988083de4ef6977ba3d9ad1a66d093e5c75a41170941ae
|