Metadata-Version: 2.4
Name: sycommon-python-lib
Version: 0.2.12a22
Summary: Add your description here
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: aio-pika==10.2.3
Requires-Dist: aiohttp==3.14.5
Requires-Dist: aiomysql==0.3.2
Requires-Dist: anyio==4.16.0
Requires-Dist: decorator==5.3.2
Requires-Dist: deepagents==0.7.41
Requires-Dist: elasticsearch==9.5.1
Requires-Dist: fastapi==0.165.0
Requires-Dist: jinja2==3.1.6
Requires-Dist: kafka-python==3.0.13
Requires-Dist: langchain==1.5.2
Requires-Dist: langchain-core==1.8.4
Requires-Dist: langchain-openai==1.8.5
Requires-Dist: langfuse==5.2.0
Requires-Dist: langgraph==1.2.24
Requires-Dist: langgraph-checkpoint-postgres==3.2.1
Requires-Dist: langgraph-checkpoint-redis==0.6.0
Requires-Dist: ldap3==2.9.1
Requires-Dist: loguru==0.8.0
Requires-Dist: mysql-connector-python==26.10.0
Requires-Dist: nacos-sdk-python==3.2.0
Requires-Dist: psutil==7.2.2
Requires-Dist: pyxxl==0.4.8
Requires-Dist: pydantic==2.14.4
Requires-Dist: python-dotenv==1.2.4
Requires-Dist: python-multipart==0.0.34
Requires-Dist: pyyaml==6.0.4
Requires-Dist: redis==7.4.0
Requires-Dist: sentry-sdk[fastapi]==3.0.0
Requires-Dist: sqlalchemy[asyncio]==2.1.9
Requires-Dist: starlette[full]==1.10.0
Requires-Dist: tiktoken==0.14.0
Requires-Dist: uvicorn==0.54.0
Requires-Dist: wecom-aibot-python-sdk==1.0.2
Requires-Dist: twine==7.0.0
Requires-Dist: minio==7.2.20
Requires-Dist: langchain-mcp-adapters==0.3.2
Requires-Dist: fastapi-mcp==0.4.0
Requires-Dist: psycopg[binary,pool]==3.3.9
Requires-Dist: agent-client-protocol==0.12.1
Requires-Dist: langchain-acp==1.13.0
Requires-Dist: pypinyin==0.55.0

# sycommon-python-lib

盛业 Python 公共库 — AI/LLM 生态(langchain/langgraph/deepagents/MCP/ACP/pi)的集成层 + 公司 Java starter jar 包的 Python 原生等价物。与 **sycommon-go-lib** 契约三端一致(同一 Java 上游、同一键名/键值/阈值/退避参数)。

安装(内网 Nexus):

```bash
pip install sycommon-python-lib -i http://192.168.2.174:8081/repository/pypy-group/simple/ --trusted-host 192.168.2.174
```

## 包结构

| 包 | 说明 |
| --- | --- |
| `sycommon/agent/` | DeepAgents/多 Agent 团队/沙箱(HOME 泄露封堵+seatbelt)/ACP/sensitive·skill-write·sandbox-path 守卫中间件 |
| `sycommon/llm/` | LLM 客户端封装、tiktoken 缓存、Langfuse/LangSmith |
| `sycommon/pi/` | pi coding agent 移植 |
| `sycommon/alert/` | **分级告警**(对齐 Java alert-sdk,见下) |
| `sycommon/logging/` | Kafka 日志 + L1-L4 分级脱敏引擎 |
| `sycommon/rabbitmq/` | MQ 客户端/延迟队列/审计存储(对齐 Java starter-mq) |
| `sycommon/synacos/` | Nacos 注册/配置/Feign/BizReject |
| `sycommon/database/` | MySQL/Redis/ES/分布式锁/TxnRef |
| `sycommon/config/` | YAML 单例 + nacos 分层读(read_key_layered) |
| `sycommon/middleware/` | CORS/Trace/上下文 |
| `sycommon/notice/` | 企微通知/进程监控 |
| `sycommon/xxljob/` | XXL-Job + 分片广播 |
| `sycommon/tools/` | audit/excel/tree/money/sso_token/usercache 等基础件 |
| `sycommon/services.py` | `Services.plugins` 统一装配入口(FastAPI 生命周期、默认挂载件) |

## 与 Java jar 包的对齐(分级告警/日志/MQ/基础件)

公司 **Java starter/common jar 包**(字节码反编译逐类对齐)的 Python 原生等价物。`sycommon-go-lib` 的对应包与这里**契约三端一致**(同一 Java 上游),跨语言互通按下列对照表核验:

### 分级告警 — `sycommon/alert/` ↔ Java shengye-platform-alert-sdk(1.0.0-SNAPSHOT,47 类反编译)

| Java jar 组件 | Python 实现 | 说明 |
| --- | --- | --- |
| AlertSdk 四级告警(fatal/critical/warn/info × title/detail/Throwable 重载矩阵) | `alert/api.py`:`fatal/critical/warn/info` + `biz_*`(templateNo 前置=BizAlertSdk) | AlertAo 15 字段/优先级(fatal=100/critical=50/warn=20)/compareTo 排序序/hutool 4.6.1 JSON 序列化形态逐字段对齐 |
| InnerSdk 发送通道(批量投递/优先级队列) | `alert/sdk.py` + `queue.py`(BoundedAlarmQueue) | 队列满驱逐最低优先最旧、SelfCheck 自检通道、网关 URL 按 profile 路由(wsdev/wsuat1/prod)对齐 |
| AlertEnv 配置读取 | `alert/env.py` | relaxed binding(SY_ALERT_MONITOR_ENABLE ↔ sy-alert.monitor.enable)/nacos 分层(read_key_layered)对齐 |
| GcMonitor(排除 young GC 的 GC 占比监控) | `alert/monitor.py` `_gc_monitor_loop` | `gc.callbacks` start/stop 计时差累计(真·时间占比);阈值 falt 0.5/critical 0.2/warning 0.05;msg 模板逐字节同;告警 msg 追加分代窗口增量 `(分代: gen0=+N ... /stats gen0=X)`(Go 侧无分代概念,此为 Python 独有诊断增强) |
| DatasourceMonitor(连接池饱和度) | `monitor.py register_db_stats` + `bridge.py` | SQLAlchemy engine.pool.status() 注入;阈值 0.7/0.8/0.95 与 4 字段 desc 对齐 |
| spring.factories 自动挂载 | `services.py` 生命周期 6.5 步 → `bridge.init_alert_monitors()` | 引入基础包即集成;`sy-alert.monitor.enable` 默认 false 零行为变化 |

### 分级日志脱敏 — `sycommon/logging/` ↔ Java shengye-platform-starter-log 2.0.0-SNAPSHOT

| Java jar 组件 | Python 实现 | 说明 |
| --- | --- | --- |
| MaskEngine/MaskUtil L1-L4 分级脱敏 | `logging/mask_engine.py` + `log_masker.py` | 快照构建/levels 解析/shouldMask 状态机/慢告警/nacos 热更新(MaskConfigRefresher 同款 reload 回调);len≤7 全 x/全串匹配/逐键分层三锚点 |
| LogModel 三方 29 字段表 | `logging/kafka_log.py` | pSpanId/pAgentId 等逐字段对齐;msg 819200/detail 102400 双限长分离;getFormattedMessage 解包对齐 |
| Kafka 日志投递 | `logging/bounded_kafka_sink.py` | 有界队列治 loguru enqueue 无界 OOM;信封与 Java starter-log 平台侧契约一致 |

### MQ — `sycommon/rabbitmq/` + `synacos/` ↔ Java shengye-platform-starter-mq(1.0.0-SNAPSHOT,22 类逆向)

| Java jar 组件 | Python 实现 | 说明 |
| --- | --- | --- |
| 消费失败告警 MqAlertHelper | `alert/mq_alert.py` | Redis SETNX 限频(`mq:alert:throttle:{topic}`,300s)/topic 维度/manualFlag 不进计数链 |
| BizRejectException(588) | `synacos/feign.py` `BizRejectError` | 588 业务拒绝语义化;**必须在 `except Exception` 之前放行**(语义化拒绝不被兜底吞掉) |
| 消费重投退避 RabbitAwareBeanPostProcessor | `rabbitmq/delay_queue.py` | 20s/×5/120s cap(可配 MQ_RETRY_BACKOFF_MS);DLX/retry-wait 档位拓扑 |
| MqHelperDao/MqRetryThread | `rabbitmq/mq_store.py` | tk_mq_msg 持久化 + 重试线程,自动建表 DDL 同款;无 DB/Redis 静默降级纯直发 |
| FeignRequestInterceptor | `synacos/feign.py` | token 重签(reqSource=服务名/全键 ALWAYS/password 剥离/username 派生/时间格式归一)+ inner=1 |
| 消费 ACK 语义/header/traceId 契约 | `rabbitmq/rabbitmq_client.py` 等 | handler 成功后 ack + Redis 计数重试;SSOUser 消费链路恢复 |

### Java 基础件九件套(与 go-lib α.65 同基线)

| Java 上游 | Python 实现 |
| --- | --- |
| starter-redis DistributedLock | `database/distlock.py`(锁键前缀 `dstc:lock:` 三端统一;Lua 值相等才删) |
| common-web TxnRefUtils | `database/txnref.py` |
| common-web AuditUtils.log | `tools/audit.py` |
| common-core ExcelHelper | `tools/excel.py` |
| common-core TreeUtils | `tools/tree.py` |
| starter-task ShardingUtils | `xxljob/sharding.py` |
| CrossTenantContext | `models/` 跨租户上下文 |
| common-web 用户缓存 | `tools/usercache.py` |
| common-core MoneyUtils | `tools/money.py`(金额大写) |

> 对齐方法论:Java 侧以**字节码反编译**为唯一事实源,逐常量池/逐分支核对;每项对齐后跑对抗复审。历史轮次见 git log(`Java`/`jar` 关键词):0.2.10a11 信封字段、a15/a17 feign 重签 + MQ 全量、a22 GC 真实时长占比。**sycommon-go-lib**(`infra/alert/`、`infra/logs/mask_engine.go`、`infra/rabbitmq/`、`infra/redis/{distlock,txnref,usercache}.go`、`core/{excel,tree,money}.go` 等)与这里共享同一 Java 基线,跨语言契约(键前缀/阈值/退避参数/信封字段)变更时三端同步。

---

## Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin http://git.syf.com/syai/sycommon-python-lib.git
git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](http://git.syf.com/syai/sycommon-python-lib/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

---

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name

Choose a self-explaining name for your project.

## Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

## License

For open source projects, say how it is licensed.

## Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
