Skip to main content

:rocket: lautpy — 常用工具类 :facepunch:

轻量的 Python 工具集:管道式数据处理 + 日期/路径/哈希等常用工具函数。核心零强制依赖,第三方库(numpy/pandas/scikit-learn 等)按需可选。

Install

pip install -U lautpy

Pipe 管道工具

from lautpy.pipe import *

# Unix 风格管道:data | func1 | func2
[1, 2, 3, 4] | xmap_(lambda x: x * 2) | xfilter_(lambda x: x > 3)   # [4, 6, 8]

# 进度条 + 日志 + 计时
for i in range(5) | xtqdm:
    logger.info("这是一个进度条")

with timer('LOG'):
    logger.info("打印一条log所花费的时间")

常用管道(约定:尾部下划线 = 立即求值返回 list):

类别 管道
类型转换 xtuple xlist xset xarray
高阶函数 xmap xmap_ xfilter xfilter_ xenumerate xchain xchain_ xreduce xdrop xdrop_
字典 xchain_dict xDictValues xDictRemove xgetitem xitemgetter
分组/去重 xgroup xUnique xUniquePlus xHashBins xsort xCounter xCounterUpdate xBloomFilter
并发 xJobs xThreadPoolExecutor xProcessPoolExecutor xAsyncio
字符串 xjoin xstartswith xendswith xsse_parser

其他模块

from lautpy import dates, hashing, paths

# 日期(纯标准库)
dates.date_difference(days=1)                    # 昨天
dates.timestamp2str(time.time())                 # 时间戳 -> 字符串
dates.get_nday_list(7)                           # 过去 7 天

# 哈希 / AB 实验(murmurhash 需 scikit-learn)
hashing.md5("key:value")
hashing.murmurhash(bins=100)                     # 与 Java Guava 口径一致
hashing.ABTest(expid='10001', ranger=(0, 99)).is_hit("userid")
hashing.hash_bins(values, bins=4)                # 稳定哈希分桶
hashing.BloomFilter(capacity=10**6)              # 纯标准库布隆过滤器

# 路径 / 配置(yaml 支持需 pyyaml)
paths.file2json("config.yaml")                   # json/yaml -> dict
paths.path2list("dir", "*.txt")                  # 文件/目录展开

装饰器 / 通知 / LLM 客户端

from lautpy import decorators, notice, llm

# 装饰器(retry 需 tenacity,其余纯标准库)
@decorators.retrying(max_retries=3)       # 指数退避重试,耗尽后 reraise
@decorators.timeout(30)                   # 超时抛 TimeoutError
@decorators.background_task               # 后台执行,返回 Future,异常记日志
@decorators.ratelimit(calls=5, period=1)  # 滑动窗口限流
def flaky_api(): ...

# 群机器人通知(webhook 走环境变量:WECOM_WEBHOOK_URL / FEISHU_WEBHOOK_URL)
notice.wecom("部署完成", title="CI")
notice.feishu(["任务1 ✓", "任务2 ✓"], title="日报")

# OpenAI 兼容客户端工厂(openai 可选依赖;密钥走 <SVC>_API_KEY / <SVC>_BASE_URL)
client = llm.openai_client("moonshot")    # 任意 openai 兼容服务

API 封装(lautpy.apis

密钥一律走环境变量,源码中零硬编码;HTTP 统一带超时与自动重试:

import os
from lautpy.apis import get_api_key, request
from lautpy.apis.tools import shorten_url, data2qrcodeurl
from lautpy.apis.niutrans import translate

os.environ["NIUTRANS_API_KEY"] = "..."   # 或在 shell / .env 中配置
translate("你好", "auto", "en")           # NiuTrans 翻译
shorten_url("https://example.com/...")   # 无需密钥的短链/二维码工具

关于从 meutils 移植的取舍:meutils 有 325 个 API 封装文件,但其中大部分并非独立函数——它们依赖原作者的私人基建(飞书表格里的 key 池、其个人的阿里云 OSS、one-api 网关),还有 75 个文件内嵌明文密钥,通知模块甚至硬编码了作者本人的 webhook 地址。这些代码即使改成环境变量也无法脱离原体系验证,因此没有全量移植。同样未移植:db/oss/(厂商 SDK 薄封装,价值低于直接用 SDK)、schemas/(重复 openai 官方自带的 pydantic 模型)、crawlers/(上游本身是空目录)。本包只移植了可独立运行、可测试的部分,新接入照 client.py 模式即可。

设计约定

  • import lautpy 零第三方强制依赖,无导入副作用
  • 第三方依赖的管道函数在库缺失时自动不可用,不影响其余功能
  • from lautpy.pipe import * 仅导出公共 API(__all__),不泄漏实现细节

License

Apache-2.0。部分代码移植自 MeUtils(MIT License, Copyright (c) yuanjie),详见各模块 docstring。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lautpy-0.0.5.0.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lautpy-0.0.5.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file lautpy-0.0.5.0.tar.gz.

File metadata

  • Download URL: lautpy-0.0.5.0.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lautpy-0.0.5.0.tar.gz
Algorithm Hash digest
SHA256 80b7427a8fb5f80eb8b21923072c06b204fc7ba04ad65790393f2af6a5f0abbf
MD5 54563388d82398406a45904bd26519e5
BLAKE2b-256 ab08bdc41f1394658014641a37dea657795ebd9c823e90cdddd096860ea2b665

See more details on using hashes here.

Provenance

The following attestation bundles were made for lautpy-0.0.5.0.tar.gz:

Publisher: publish.yml on elimes/lautpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lautpy-0.0.5.0-py3-none-any.whl.

File metadata

  • Download URL: lautpy-0.0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lautpy-0.0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d80ea653b7cd550b3bf8864bf8fb8d90ec3d848d25a4e125ee9e06fca0b4432c
MD5 afd13e812e468f245b27119f1258b7b5
BLAKE2b-256 8e9ca8675611a4b77cb19f974969ef5230cb909f7c686bb3a533040c855c1b00

See more details on using hashes here.

Provenance

The following attestation bundles were made for lautpy-0.0.5.0-py3-none-any.whl:

Publisher: publish.yml on elimes/lautpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.0.6.0

2 files

This release

0.0.5.0 This release

2 files

0.0.4.0

2 files

0.0.3.0

2 files

0.0.2.4

2 files

0.0.2.3

2 files

0.0.2.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page