small_toolkit
纯标准库的通用 Python 小工具集合:产物目录、日志初始化、命令行参数、终端表格。
边界
- 零第三方依赖:只用标准库(
pathlib/logging/argparse/unicodedata)。 - 无凭据、无内网地址:不读环境里的密钥,不内置任何内网域名;环境变量只做名字层面的回退。
- 只抽跨项目复用的通用能力,业务逻辑(平台 SDK、数据源客户端、领域规则)留在各自仓库。
安装
从 tag 安装(跨仓依赖固定到 tag,不跟浮动分支):
uv add "small_toolkit @ git+https://github.com/jalousiex/py-toolkit.git@v0.1.1"
本地开发:
uv sync
uv run pytest -q
分区
| 模块 | 内容 |
|---|---|
small_toolkit.outputs |
output_root / output_dir / get_output_dir / tool_output_dir / display_path / env_suffix / tool_dir_name / save_json / write_json / save_bytes / save_response |
small_toolkit.logs |
setup_job(控制台着色 + 延迟建目录的文件日志)/ set_log_env / add_debug_argument / enable_debug_logging |
small_toolkit.cli |
add_grouped_subparsers / add_parameter / resolve_parameters / resolve_env_var |
small_toolkit.table |
print_table / print_grouped_table / print_tree |
顶层 small_toolkit 已重导出全部公开 API,from small_toolkit import setup_job, tool_output_dir 即可。
产物目录约定
<产物根>/output/<分类 slug>/<工具名>[@<env 小写>]/<产物类型>/
- 产物根:默认运行目录;从运行目录向上命中便携标记(
WORKSPACE_MARKERS,默认.workspace-root/.dataphin.jsonc)时归到该目录,工作区任意子目录启动都落到工作区根。 - 环境后缀:
tst(含未传,大小写不敏感)无后缀;其它环境@<env 小写>,同一套归一 同时作用于产物目录与日志文件名。 - 落盘统一走
save_json/write_json/save_bytes:自动建父目录;save_json不补末尾 换行、非序列化对象按str()落盘,write_json末尾补换行。
from small_toolkit import setup_job, tool_output_dir
setup_job(__file__, log_file=True)
out = tool_output_dir("data_dev", "intake_tool", env="prod", create=True)
日志与 --debug
setup_job() 只在真终端给消息正文着色;管道、重定向、子进程捕获、NO_COLOR
下一律纯文本,落盘日志始终纯文本。add_debug_argument() 默认 argparse.SUPPRESS,
顶层与子命令各注册一次也不会互相覆盖,判断统一交给 enable_debug_logging()。
命令行回退顺序
add_parameter() 登记后,resolve_parameters() 按
CLI → 平台代码参数(parameter)→ 环境变量(env)→ 默认值 填充;
平台占位符(${name})按未设置处理。resolve_env_var(env, base) 依次读
{base}_LIST(env=value;...)、{base}_{ENV},仅 prod 时回退原生 {base}。
版本
pyproject.toml 的 version 为唯一来源;发版打 tag(v0.1.1),引用方按 tag 固定。
发布
PyPI 走 GitHub Actions + Trusted Publishing(OIDC,不用 API token):
- 先手动跑
publish-test(workflow_dispatch)发 TestPyPI 验证,不占正式版本号; - 正式发布:
pyproject.toml升版本 → 打 tagv*→ push tag,publish工作流构建并上传。 - 工作流会先校验 tag 与
pyproject.toml的version一致,不一致直接失败(PyPI 同版本不可覆盖)。 - GitHub 仓库需要预先配置 PyPI 的 pending publisher(Owner / Repository / Workflow / Environment 四项与工作流一致)。
Metadata
Release files for small-toolkit 0.1.1
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 |
|---|---|---|---|---|
| small_toolkit-0.1.1.tar.gz | 21.1 kB | With provenance | Details for small_toolkit-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| small_toolkit-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for small_toolkit-0.1.1-py3-none-any.whl |
Total release size: 37.2 kB
Release files / small_toolkit-0.1.1.tar.gz
| Download URL | small_toolkit-0.1.1.tar.gz |
|---|---|
| Size | 21.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9486831eae57338dbffdb284904fd72f66a64e0c119b7b2ae1e89d0dc72066af
|
|
BLAKE2b-256 checksum How to use checksums |
611c186213e57f93c867477a998363d0a1220ca423be2e3cc497e8f3000895fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logRelease files / small_toolkit-0.1.1-py3-none-any.whl
| Download URL | small_toolkit-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4f3733c43b99d3d331c04967a595ae74ff4414eb7a25ae54f6d6f364aa98bee
|
|
BLAKE2b-256 checksum How to use checksums |
502fd26fe70b7adbcfce34cbead7ac1d843a41d3cb186734ab21aac07d4a8f6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logSecurity for small-toolkit 0.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for small_toolkit-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logA 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.