Skip to main content

SAGE 框架核心公共工具包

Project description

SAGE Common

SAGE 框架的核心工具和共享组件

Python Version License

📋 概述

SAGE Common 提供所有 SAGE 包共用的基础工具和组件。 这是基础层(L1),提供:

  • 配置管理 - YAML/TOML 文件支持
  • 日志框架 - 自定义格式化器和处理程序
  • 网络工具 - TCP/UDP 通信支持
  • 序列化工具 - dill 和 pickle 支持
  • 系统工具 - 环境和进程管理
  • 嵌入服务 - sage_embedding、sage_llm

该包确保 SAGE 生态系统的一致性并减少代码重复。

✨ 核心特性

  • 统一配置 - YAML/TOML 配置加载和验证
  • 高级日志 - 彩色输出、结构化日志、自定义格式器
  • 网络工具 - TCP 客户端/服务器、网络助手
  • 灵活序列化 - 多种后端(dill、pickle、JSON)
  • 系统管理 - 环境检测、进程控制
  • LLM 集成 - 嵌入和 vLLM 服务

核心模块

  • utils.config - 配置管理工具
  • utils.logging - 日志框架和格式化器
  • utils.network - 网络工具和 TCP 客户端/服务器
  • utils.serialization - 序列化工具(包含 dill 支持)
  • utils.system - 环境和进程管理的系统工具
  • _version - 版本管理

📦 包结构

sage-common/
├── src/
│   └── sage/
│       └── common/
│           ├── __init__.py
│           ├── _version.py
│           ├── utils/                  # 核心工具
│           │   ├── config/            # 配置管理
│           │   ├── logging/           # 日志框架
│           │   ├── network/           # 网络工具
│           │   ├── serialization/     # 序列化工具
│           │   └── system/            # 系统工具
│           └── components/            # 共享组件
│               ├── sage_embedding/    # 嵌入服务
│               └── sage_llm/         # vLLM 服务
├── tests/
├── pyproject.toml
└── README.md

🚀 安装

基础安装

pip install isage-common

开发安装

cd packages/sage-common
pip install -e .

可选依赖安装

# 嵌入支持
pip install isage-common[embedding]

# vLLM 支持
pip install isage-common[vllm]

# 完整安装
pip install isage-common[all]

📖 快速开始

配置管理

from sage.common.utils.config.loader import ConfigLoader

# 加载配置
config = ConfigLoader("config.yaml")

# 访问配置
model_name = config.get("model.name", default="default-model")

日志

from sage.common.utils.logging.custom_logger import get_logger

# 获取日志器
logger = get_logger(__name__)

# 使用日志器
logger.info("应用程序已启动")
logger.debug("调试信息")
logger.error("发生错误", exc_info=True)

网络工具

from sage.common.utils.network import TCPClient, TCPServer

# 创建 TCP 服务器
server = TCPServer(host="localhost", port=8080)
server.start()

# 创建 TCP 客户端
client = TCPClient(host="localhost", port=8080)
client.connect()
client.send(b"你好,服务器!")

序列化

from sage.common.utils.serialization import serialize, deserialize

# 序列化数据
data = {"key": "value", "numbers": [1, 2, 3]}
serialized = serialize(data, format="dill")

# 反序列化数据
restored = deserialize(serialized, format="dill")

🔧 配置

配置文件通常使用 YAML 或 TOML 格式:

# config.yaml
logging:
  level: INFO
  format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

network:
  host: localhost
  port: 8080
  timeout: 30

embedding:
  model: sentence-transformers/all-MiniLM-L6-v2
  device: cuda

🧪 测试

# 运行单元测试
pytest tests/unit

# 运行集成测试
pytest tests/integration

# 运行覆盖率测试
pytest --cov=sage.common --cov-report=html

📚 文档

  • 用户指南 - 查看 docs-public
  • API 参考 - 查看包文档字符串和类型提示
  • 示例 - 查看各模块中的 examples/ 目录

🤝 贡献

欢迎贡献!请查看 CONTRIBUTING.md 了解指导原则。

📄 许可证

该项目采用 MIT 许可证 - 详情请查看 LICENSE 文件。

🔗 相关包

  • sage-kernel - 使用通用工具进行运行时管理
  • sage-libs - 基于通用组件构建库
  • sage-middleware - 使用网络和序列化工具
  • sage-tools - 使用配置和日志工具

📮 支持


SAGE 框架的一部分 | 主仓库

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

isage_common-0.2.3.5-py3-none-any.whl (548.9 kB view details)

Uploaded Python 3

File details

Details for the file isage_common-0.2.3.5-py3-none-any.whl.

File metadata

  • Download URL: isage_common-0.2.3.5-py3-none-any.whl
  • Upload date:
  • Size: 548.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for isage_common-0.2.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 caf92e9b8fb18ef185ff3f50c1f3c72a6f7a477a6965a0209abbc86b6387c614
MD5 779aa985276bda5b4a412a65cc7c2738
BLAKE2b-256 f862894090c3c4182437d824ffc7a81043bd628357456df0a147e1046191186a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page