yayo 工具包
Project description
yayo-pypkg
yayo 工具包 —— 提供常用的 Python 工具函数。
Python 版本支持
| 范围 | 说明 |
|---|---|
基础功能 (log / config / utils) |
✅ Python >= 3.7(零三方依赖:只有 requests + snowflake-id) |
进阶功能(pydantic schemas) |
需要 Python >= 3.8 |
core extras(调度器) |
需要 Python >= 3.7 |
llm extras(LangChain) |
需要 Python >= 3.10 |
api extras(FastAPI + DB) |
需要 Python >= 3.8 |
all extras(全包) |
需要 Python >= 3.10 |
全部源码已用
from __future__ import annotations,PEP 604 (str \| None) / 内建泛型 (list[str]) 语法都已惰性化,旧版 Python 也能跑。
安装
# 基础(只装 log / config / utils,推荐 Python 3.7+ 项目用)
pip install yayo-pypkg
# + pydantic schemas(给 json_utils / schemas 用)
pip install yayo-pypkg[pydantic]
# + 定时任务调度器
pip install yayo-pypkg[core]
# + LLM / DeepSeek / OpenAI
pip install yayo-pypkg[llm]
# + FastAPI + SQLAlchemy + MySQL
pip install yayo-pypkg[api]
# 全包
pip install yayo-pypkg[all]
uv 用户:把
pip install换成uv add即可,语义完全一样。
快速上手
支持两种导入方式(完全等价,任选其一):
# 方式 1:完整包名
from yayo_pypkg import hello, config, get_logger
# 方式 2:短别名
from ypk import hello, config, get_logger
print(hello()) # -> hello from yayo_pypkg
print(config.DB_HOST) # -> 从 .env 自动读取(支持类型自动转换)
日志(get_logger)
一行接入,按天切割 + 保留 7 天 + 控制台/文件双输出:
# log.py
from yayo_pypkg import get_logger
logger = get_logger() # 自动用入口脚本名,如 main.py → ./logs/main.log
logger.info("hello")
logger.error("oops")
- 默认自动在 CWD 下创建
./logs/<name>.log - 同名 logger 幂等,多次
get_logger()不会重复挂 handler - 业务方只需
from .log import logger即可
配置(config)
读取项目根目录的 .env,支持 str / int / float / bool 自动类型推断:
# .env
DB_HOST=localhost
DB_PORT=3306
DEBUG=true
APP_NAME="my service"
from yayo_pypkg import config
print(config.DB_HOST) # -> 'localhost' (str)
print(config.DB_PORT) # -> 3306 (int,自动转换)
print(config.DEBUG) # -> True (bool,自动转换)
print(config.APP_NAME) # -> 'my service' (引号自动剥离)
- 环境变量优先级高于
.env文件 - 访问不存在的属性会抛
AttributeError,IDE 友好
模块概览
| 模块 | 说明 |
|---|---|
yayo_pypkg.core.logger |
日志配置(get_logger / setup_logger) |
yayo_pypkg.core.config |
.env 加载 + 类型推断 |
yayo_pypkg.cron.scheduler |
定时任务调度器([core] extras) |
yayo_pypkg.path_utils |
路径处理(项目根目录 / 目录创建) |
yayo_pypkg.datetime_utils |
日期时间工具 |
yayo_pypkg.str_utils |
字符串工具 |
yayo_pypkg.file_utils |
文件读写工具 |
yayo_pypkg.list_utils |
列表/集合工具 |
yayo_pypkg.json_utils |
JSON 工具(pydantic 懒加载,[pydantic] extras) |
yayo_pypkg.http_utils |
HTTP 客户端封装 |
yayo_pypkg.snowflake_utils |
雪花 ID 生成器 |
yayo_pypkg.exceptions |
自定义异常层级 |
yayo_pypkg.llm |
LLM / DeepSeek 流式服务([llm] extras) |
yayo_pypkg.middleware |
FastAPI 中间件([api] extras) |
yayo_pypkg.schemas |
Pydantic Schema 基类([pydantic] extras) |
yayo_pypkg.db |
MySQL 连接池([api] extras) |
yayo_pypkg.ocr |
MinerU OCR 客户端 |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yayo_pypkg-0.0.7.tar.gz
(37.6 kB
view details)
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 yayo_pypkg-0.0.7.tar.gz.
File metadata
- Download URL: yayo_pypkg-0.0.7.tar.gz
- Upload date:
- Size: 37.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64911f9366f893501494095b3da526a46efd2306ae87ba300111937b8c8132f2
|
|
| MD5 |
5c28e8b65df475b7d3c8427d2bcf53ee
|
|
| BLAKE2b-256 |
9d9f814c58cca6f58ff188b27c5e1b0a7fc64875cbe99e37e3359359f458a906
|
File details
Details for the file yayo_pypkg-0.0.7-py3-none-any.whl.
File metadata
- Download URL: yayo_pypkg-0.0.7-py3-none-any.whl
- Upload date:
- Size: 51.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f2084fe1b8ec9d3ceb5b04213cbae960ee2d8014d839b6516f34f2c1965a37c
|
|
| MD5 |
70e3dda843ea655c95f08615d908ea2f
|
|
| BLAKE2b-256 |
c7313b827f9a79890590930a1bddb58e1e0bb6fefc69ee43b9e2478021ada854
|