python version of xiaobo tool module
Project description
Xiaobo Tool 
Python 通用工具库,提供任务执行器、代理池、X(Twitter) 客户端、临时邮箱等模块。
安装
uv add xiaobo-tool
模块概览
task_executor - 任务执行器
支持同步(线程池)和异步(asyncio)两种模式,内置重试、代理轮换、回调通知和统计。
from xiaobo_tool.task_executor import TaskExecutor, Target
def my_task(target: Target):
print(f"执行任务: {target.data}, 代理: {target.proxy}")
with TaskExecutor(name="Demo", max_workers=3, retries=2) as executor:
executor.submit_tasks(
task_func=my_task,
source=["item1", "item2", "item3"],
on_success=lambda t, r: print(f"{t.data} 成功"),
on_error=lambda t, e: print(f"{t.data} 失败: {e}"),
)
executor.wait()
executor.statistics()
异步模式:
import asyncio
from xiaobo_tool.task_executor import AsyncTaskExecutor, Target
async def my_async_task(target: Target):
print(f"执行任务: {target.data}")
async def main():
async with AsyncTaskExecutor(name="AsyncDemo", max_workers=5) as executor:
executor.submit_tasks(task_func=my_async_task, source=10)
await executor.wait()
await executor.statistics()
asyncio.run(main())
从文件批量提交任务:
# 读取 accounts.txt,每行按 "----" 分割
executor.submit_tasks_from_file(task_func=my_task, filename="accounts", separator="----")
配置通过 Settings 管理,支持构造参数、环境变量、.env 文件三种方式:
| 配置项 | 默认值 | 说明 |
|---|---|---|
MAX_WORKERS |
5 |
最大线程数 |
PROXY |
(空) | 代理,支持 host:port / user:pass@host:port,占位符 ***** 自动替换为 index 或第一位数据 |
PROXY_IPV6 |
(空) | IPv6 代理,格式同 PROXY |
PROXY_API |
(空) | 代理提取 API 地址(一行一个),格式同 PROXY |
PROXY_IPV6_API |
(空) | IPv6 代理提取 API 地址 |
RETRIES |
2 |
重试次数(抛出 TaskFailed 不重试) |
RETRY_DELAY |
0 |
重试延迟(秒) |
SHUFFLE |
false |
是否打乱任务顺序,按照数量运行的任务,支持布尔值或任务名称,多个任务用&拼接,如: task1&task2 |
USE_PROXY_IPV6 |
false |
是否优先使用 IPv6 代理,支持布尔值或任务名称,多个任务用&拼接,如: task1&task2 |
DISABLE_PROXY |
false |
是否禁用代理,支持布尔值或任务名称,多个任务用&拼接,如:task1&task2 |
抛出 TaskFailed 异常可跳过重试,直接标记任务失败:
from xiaobo_tool.task_executor import TaskFailed
def my_task(target: Target):
if invalid(target.data):
raise TaskFailed("数据无效,无需重试")
proxy_pool - 代理池
管理代理获取与轮换,支持直连代理和 API 代理(带 3 分钟缓存)。
from xiaobo_tool.proxy_pool import ProxyPool
pool = ProxyPool(proxy_api="http://your-proxy-api.com/get")
proxy = pool.get_proxy()
x - X(Twitter) 客户端
基于 auth_token 操作 X API,支持发推和 OAuth2 授权。
from xiaobo_tool.x import XClient
client = XClient(auth_token="your_auth_token", proxy="http://127.0.0.1:7890")
tweet_url = client.send_tweet("Hello World!")
OAuth2 授权:
redirect_uri = client.authorize_oauth2("https://x.com/i/oauth2/authorize?client_id=xxx&...")
temp_email - 临时邮箱
创建临时邮箱并接收邮件,支持同步和异步两种模式。
from xiaobo_tool.temp_email import TempEmail
with TempEmail() as mail:
domains = mail.query_domains()
mailbox = mail.create_mailbox()
result = mail.get_new_mail(mailbox)
异步模式:
from xiaobo_tool.temp_email import AsyncTempEmail
async with AsyncTempEmail() as mail:
mailbox = await mail.create_mailbox(domain="example.com", mail_type=1)
result = await mail.get_new_mail(mailbox, title="验证码")
utils - 工具函数
read_txt_file_lines(filename)- 按行读取 txt 文件write_txt_file(filename, data)- 写入/追加 txt 文件get_session(proxy)/get_async_session(proxy)- 创建 HTTP 会话(curl_cffi)json_get(data, path, default)- 通过路径访问嵌套 JSON 数据raise_response_error(name, response)- 解析 HTTP 错误响应并抛出异常
开发
# 安装开发依赖
uv sync --dev
# 运行测试
uv run pytest
依赖
- curl-cffi - HTTP 客户端(浏览器指纹模拟)
- loguru - 日志
- pydantic-settings - 配置管理
- tenacity - 重试机制
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
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 xiaobo_tool-1.0.3.tar.gz.
File metadata
- Download URL: xiaobo_tool-1.0.3.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31466333897a4fad5bc07f061c59a6311084c3b21adf7299cd99130c866339db
|
|
| MD5 |
a80ed08fc04a3d9512a7f08937737c83
|
|
| BLAKE2b-256 |
96db6779ac52584594b5507bd5f5950fe4a9bca4458f9ca7f978e3fdac514652
|
Provenance
The following attestation bundles were made for xiaobo_tool-1.0.3.tar.gz:
Publisher:
workflow.yml on Xiaobooooo/xiaobo-tool-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xiaobo_tool-1.0.3.tar.gz -
Subject digest:
31466333897a4fad5bc07f061c59a6311084c3b21adf7299cd99130c866339db - Sigstore transparency entry: 956354056
- Sigstore integration time:
-
Permalink:
Xiaobooooo/xiaobo-tool-python@55161c3a6e5ba5f58f193c5d3905eefaf018a4d8 -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/Xiaobooooo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@55161c3a6e5ba5f58f193c5d3905eefaf018a4d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xiaobo_tool-1.0.3-py3-none-any.whl.
File metadata
- Download URL: xiaobo_tool-1.0.3-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3b12c8aabf85a24d332f1e0d6299364ff2d10dfaa83a4da30fc4a212374d65a
|
|
| MD5 |
940726630289df9d051acf65506a67bd
|
|
| BLAKE2b-256 |
b32e829dc974ea729f297f11023a538d5d3461b90c724be61b1baff55e315495
|
Provenance
The following attestation bundles were made for xiaobo_tool-1.0.3-py3-none-any.whl:
Publisher:
workflow.yml on Xiaobooooo/xiaobo-tool-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xiaobo_tool-1.0.3-py3-none-any.whl -
Subject digest:
a3b12c8aabf85a24d332f1e0d6299364ff2d10dfaa83a4da30fc4a212374d65a - Sigstore transparency entry: 956354061
- Sigstore integration time:
-
Permalink:
Xiaobooooo/xiaobo-tool-python@55161c3a6e5ba5f58f193c5d3905eefaf018a4d8 -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/Xiaobooooo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@55161c3a6e5ba5f58f193c5d3905eefaf018a4d8 -
Trigger Event:
push
-
Statement type: