pewutils
PE Windmill Utils —— 为 Windmill 脚本平台提供的轻量级 Python 工具包。
由 peutils 迁移重构而来,适配 windmill 脚本平台。
能力清单
完整能力清单(模块、公开类/函数、签名与说明)由代码内省生成,始终与当前版本一致, 不要手工维护:
# 查看当前已安装版本的全部能力
python -m pewutils.capabilities
清单不生成文件、不随包分发;需要留档时重定向到任意路径即可。
安装
# 默认安装全部所需依赖(含 sqlalchemy、PG/MySQL 驱动、wmill)
pip install pewutils
# 本地开发(editable)
git clone <repo-url> pewutils
cd pewutils
pip install -e .
使用示例
URL 工具
from pewutils.url_util import (
get_clean_url,
parse_storage_url,
parse_oss_full_path,
get_relative_path,
)
# 去除 OSS 签名 URL 的查询参数
clean = get_clean_url("https://bucket.aliyuncs.com/path/file.pcd?Expires=123&Signature=xxx")
# -> "https://bucket.aliyuncs.com/path/file.pcd"
# 解析存储 URL(宽松)
bucket, path = parse_storage_url("oss://my-bucket/folder/file.txt")
# -> ("my-bucket", "folder/file.txt")
# 解析 OSS 目录路径(强约束,要求以 / 结尾)
bucket, folder = parse_oss_full_path("oss://my-bucket/folder/")
OSS 工具
from pewutils.oss_util import OSSClientFactory
# 创建带自动刷新的 OSS client(auth_str 12h 过期,11h 自动刷新)
client = OSSClientFactory.create_client(bucket_name="my-bucket")
# 读取 OSS 对象为字节流
data = client.read_bytes("path/to/file.pcd")
# 列举目录下所有文件
files = client.list_bucket_files_deep("path/to/folder/")
# BFS 查找最浅的目标文件
path = client.find_shallowest_target("root/", "target.json", "file")
数据库工具
sqlalchemy 与 PostgreSQL/MySQL 驱动已包含在默认依赖中, Windmill 脚本直接
from pewutils.db_util import DbClient即可,无需写# requirements:。
from pewutils.db_util import DbClient
db_setting = {"user": "u", "pwd": "p", "host": "127.0.0.1", "port": 5432}
with DbClient(db_setting, dbname="mydb") as db:
# 原生 SQL 查询(参数走绑定变量)
rows = db.query("select id, name from t where id = :id", {"id": 1})
user = db.query_one("select * from users where id = :id", {"id": 1})
total = db.query_scalar("select count(*) from users")
# 字典驱动 CRUD(免手写 SQL,表名/列名自动校验防注入)
db.insert("users", [{"name": "a"}, {"name": "b"}])
ids = db.insert("users", {"name": "c"}, returning="id")
db.update("users", {"status": 0}, where={"id": 1})
users = db.select("users", where={"status": 1}, order_by="id desc", limit=10)
db.delete("users", where={"status": 0})
# 事务:块内操作同一事务,异常自动回滚
with db.transaction():
db.execute("update a set x = 1 where id = :id", {"id": 2})
db.insert("b", {"y": 2})
# 大表流式遍历,不一次性载入内存
for row in db.stream("select * from big_table"):
process(row)
点云语义分割位图
点云脚本通常已随 pypcd4 等库携带 numpy,自动走向量化快路径; 无 numpy 时退化为纯 Python 实现,结果一致。
from pewutils.bitarray_util import BitArray
# 预标注:点索引 -> A9 shapeData 位图(numpy 数组直接传入即可)
ba = BitArray()
ba.set_all_bits(np.flatnonzero(seg_mask))
shape_data = {"data": ba.get_str_bits(), "size": ba.size}
# 后处理:A9 结果位图 -> 点索引
indices = BitArray.bits2list(shape["shapeData"]["0_pcd"]["data"])
# 或构造为对象继续操作
ba = BitArray.from_str_bits(shape["shapeData"]["0_pcd"]["data"])
Windmill 平台工具
from pewutils.wmill_util import zip_to_s3
# with 块内生成文件,退出时自动打包 zip 上传到 Windmill S3
with zip_to_s3("output/zip", suffix=".json") as out:
Path("a.json").write_text('{"k": 1}')
Path("b.json").write_text('{"k": 2}')
# out.result -> S3Object(s3="output/zip/20260729/uuid.zip")
# out.files -> [Path("a.json"), Path("b.json")]
目录结构
pewutils/
├── README.md
├── pyproject.toml # 打包配置(PEP 517/518,requires-python>=3.10)
├── .gitignore
└── pewutils/
├── __init__.py # 默认导出轻量模块(base/url_util/text_util/datetime_util/bitarray_util)
├── capabilities.py # 能力清单生成器(python -m pewutils.capabilities)
├── base.py # 通用数据结构(DotDict,纯标准库)
├── url_util.py # URL 处理(纯标准库)
├── text_util.py # 文本处理(纯标准库)
├── datetime_util.py # 时间处理(纯标准库)
├── bitarray_util.py # 点云语义分割位图(标准库;numpy 可选加速)
├── img_com_util.py # 图像组合标注(img_com)解析
├── oss_util.py # OSS 工具(oss2, requests)
├── db_util.py # 数据库工具(sqlalchemy + psycopg2-binary + pymysql)
├── wmill_util.py # Windmill 平台工具(wmill lazy import)
└── a9_result/ # A9 标注结果解析(core / image 2D / pointcloud 23D·4D)
构建
pip install build
python -m build
# 产物:dist/pewutils-<version>-py3-none-any.whl
Metadata
Release files for pewutils 0.0.19
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 | Actions |
|---|---|---|---|---|
| pewutils-0.0.19.tar.gz | 76.2 kB | Without provenance | Details for pewutils-0.0.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pewutils-0.0.19-py3-none-any.whl | Python 3 | none | any | Details for pewutils-0.0.19-py3-none-any.whl |
Total release size: 160.5 kB
Release files / pewutils-0.0.19.tar.gz
| Download URL | pewutils-0.0.19.tar.gz |
|---|---|
| Size | 76.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bc745d990d39ca1984ceb2a4fa6972b18d7a28c2f623880a294268651b66394
|
|
BLAKE2b-256 checksum How to use checksums |
209f7a0c66f193ff6f017a5de5aaa3a35155949223e6183675a60a15f4b40269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / pewutils-0.0.19-py3-none-any.whl
| Download URL | pewutils-0.0.19-py3-none-any.whl |
|---|---|
| Size | 84.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bf261280c6c2827cd07e81338d3f674f49394b8e09fe06cabc0c90c08627aae
|
|
BLAKE2b-256 checksum How to use checksums |
7748e28b19f2ef2e3e46ba18facb9896df0306c348017b9c22609e34841b0181
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for pewutils 0.0.19
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.