ashengtools
ashengtools 是一个功能强大的 Python 工具集合,旨在简化文件处理、文本操作、网络请求、数据处理以及自动化任务。它封装了常用的操作,让开发者能更高效地编写代码。
📦 安装
前置要求
- Python 3.10+
安装方式
你可以通过 pip 安装本项目(如果已发布到 PyPI):
pip install ashengtools
或者从源码安装:
git clone https://github.com/Asheng008/ashengtools.git
cd ashengtools
pip install .
依赖库
本项目依赖以下第三方库:
pandas: 数据处理paramiko: SSH/SFTP 连接requests: 网络请求python-docx,pydocx: Word 文档处理lxml: XML/HTML 解析Faker: 生成伪造数据pywin32: Windows 系统调用 (仅 Windows 环境)
注意: Linux 系统环境下不需要也不应安装 pywin32。
✨ 功能特性
ashengtools 提供了多个模块,涵盖了开发中的常见需求:
📂 文件与目录操作 (ashengtools.files)
- 文件读写: 便捷的
readtxt,writetxt,readjson,writejson函数。 - 文件查找: 快速遍历目录查找文件 (
get_filelist)。 - 路径处理: 智能处理文件路径和分隔符。
- 中文数字转换: 支持中文数字与阿拉伯数字互转。
🌐 网络与 SFTP (ashengtools.sftp, ashengtools.request)
- SFTP 客户端: 封装
paramiko,提供更易用的Sftp类,支持递归创建目录、文件上传下载、存在性检测等。 - HTTP 请求: 封装
requests,简化常用网络操作。
📝 文本与数据处理 (ashengtools.text, ashengtools.strs)
- 文本清洗: 提供正则表达式辅助函数
reg。 - 格式转换:
txt2list和list2txt方便地在文本文件和列表/Series 之间转换。 - 字符串操作:
strs.py提供了中文数字转换 (Cn_num,Num_cn) 和字符串处理工具。 - 代码转换:
py2html将 Python 代码转换为带行号的 HTML。
📊 数据结构工具 (ashengtools.lists, ashengtools.dicts, ashengtools.panda)
- 列表/字典增强: 提供额外的列表和字典操作辅助函数。
- Pandas 扩展: 针对 Pandas DataFrame 和 Series 的常用操作封装。
📄 文档处理 (ashengtools.document)
- Word 文档: 支持读取和处理
.docx文件内容。
🚀 使用示例
1. 文件操作
from ashengtools.files import readtxt, writetxt, get_filelist
# 读取文本文件
content = readtxt('data.txt')
# 写入文本文件
writetxt('Hello World', 'output.txt')
# 获取当前目录下所有 .py 文件
py_files = get_filelist('.', type='py')
print(py_files)
2. SFTP 操作
from ashengtools.sftp import Sftp
# 连接 SFTP
sftp = Sftp('192.168.1.100', 22, 'username', 'password')
# 检查远程目录是否存在
if not sftp.exist('/remote/path/data'):
sftp.mkdirs('/remote/path/data')
# 上传目录
sftp.upload_dir('./local_data', '/remote/path/data')
sftp.close()
3. 文本处理
from ashengtools.text import txt2list
from ashengtools.strs import reg
# 将文本文件内容转为列表
lines = txt2list('config.txt', is_ser=False)
# 正则提取
text = "Order ID: 12345, Date: 2023-01-01"
order_id = reg(r'Order ID: (\d+)', text)
print(order_id) # 输出: 12345
🛠️ 项目结构
ashengtools/
├── src/
│ └── ashengtools/
│ ├── __init__.py # 包入口
│ ├── files.py # 文件操作
│ ├── sftp.py # SFTP 工具
│ ├── text.py # 文本处理
│ ├── request.py # 网络请求
│ ├── document.py # 文档处理
│ └── ...
├── tests/ # 测试用例
├── pyproject.toml # 项目配置
└── README.md # 说明文档
📄 许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
👤 作者
- Asheng
- Email: w62745@qq.com
Metadata
Release files for ashengtools 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ashengtools-0.1.0.tar.gz | 40.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ashengtools-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 79.4 kB
Release files / ashengtools-0.1.0.tar.gz
| Download URL | ashengtools-0.1.0.tar.gz |
|---|---|
| Size | 40.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13171cec9d12414a1f7ad2d705b236429c18b5c714cf5b75c189409002741761
|
|
BLAKE2b-256 checksum How to use checksums |
2315d6850ac38353d674cf9623a177f5933c48845c7c1f6124ae2782ee78fa11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / ashengtools-0.1.0-py3-none-any.whl
| Download URL | ashengtools-0.1.0-py3-none-any.whl |
|---|---|
| Size | 38.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8af56b3c915264300bb741142ccec4e1c77ad82adcfa12400b28c14e61cd9c2f
|
|
BLAKE2b-256 checksum How to use checksums |
14203bb53831ca78a0ceb3691f01038d0d86c09fd0be59dba2975cfa96b1cce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for ashengtools 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.