EasyCome LangChain SDK
让 easycome 社媒数据 API 无缝接入 LangChain 智能体。
安装
pip install easycome-langchain
快速开始
import os
os.environ["EASYCOME_BASE_URL"] = "https://www.easycome.com.cn"
os.environ["EASYCOME_API_KEY"] = "dg_xxxxxxxxxxxx"
os.environ["EASYCOME_COOKIE_XHS"] = "a1=xxx; web_session=yyy"
from easycome_langchain import get_tools
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
tools = get_tools() # 自动发现所有 API
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, tools)
result = agent.invoke({
"messages": [{"role": "user", "content": "搜索小红书关于"成都美食"的笔记,只看前3条"}]
})
环境变量
| 变量 | 必填 | 说明 |
|---|---|---|
EASYCOME_BASE_URL |
是 | API 基础 URL |
EASYCOME_API_KEY |
是 | API 密钥 (dg_ 开头) |
EASYCOME_COOKIE_XHS |
按需 | 小红书平台 Cookie |
EASYCOME_COOKIE_DOUYIN |
按需 | 抖音平台 Cookie |
EASYCOME_COOKIE_BIlibili |
按需 | B站平台 Cookie |
EASYCOME_COOKIE_WEIBO |
按需 | 微博平台 Cookie |
EASYCOME_COOKIE_ZHIHU |
按需 | 知乎平台 Cookie |
EASYCOME_COOKIES |
按需 | JSON 格式: {"xhs":"...", "bilibili":"..."} |
API
get_tools(...)
主入口,返回 list[StructuredTool] 供 LangChain Agent 使用。
from easycome_langchain import get_tools
# 获取所有工具
tools = get_tools()
# 筛选特定平台
xhs_tools = get_tools(platform="xhs")
# 筛选特定分类
stock_tools = get_tools(category="stock")
# 只获取指定工具
tools = get_tools(slugs=["xhs_search", "bilibili_video_detail"])
# 显式传参(替代环境变量)
tools = get_tools(
base_url="https://www.easycome.com.cn",
api_key="dg_xxx",
cookies={"xhs": "a1=xxx; web_session=yyy"},
)
EasyComeClient
底层 REST 客户端,也可以独立使用。
from easycome_langchain import EasyComeClient
client = EasyComeClient(
base_url="https://www.easycome.com.cn",
api_key="dg_xxx",
cookies={"xhs": "a1=xxx"},
)
# 同步调用
data = client.call_sync("xhs_search", {"keyword": "美食", "page": "1"})
# 异步调用
data = await client.call("xhs_search", {"keyword": "美食"})
fetch_catalog()
获取 API 目录(不依赖 LangChain)。
from easycome_langchain import fetch_catalog
entries = fetch_catalog("https://www.easycome.com.cn")
for e in entries:
print(f"{e.slug}: {e.name} [{e.platform}]")
Cookie 管理
SDK 自动处理 Cookie 注入——Agent 不需要知道 Cookie 参数的存在。
- Cookie 按平台配置(不是按端点)
- 创建 Tool 时自动匹配 platform → cookie
- 端点需要 cookie 但未配置时,调用会抛出
CookieRequiredError
多平台 Cookie 示例:
os.environ["EASYCOME_COOKIE_XHS"] = "a1=xxx; web_session=yyy"
os.environ["EASYCOME_COOKIE_BIlibili"] = "SESSDATA=xxx; bili_jct=yyy"
os.environ["EASYCOME_COOKIE_WEIBO"] = "SUB=xxx"
tools = get_tools() # 自动匹配各平台的 Cookie
异常处理
from easycome_langchain import (
AuthError, # API Key 无效
QuotaError, # 余额不足
RateLimitError, # 请求过于频繁
UpstreamError, # 上游平台返回错误
NotFoundError, # 端点不存在
CookieRequiredError, # 缺少必需的 Cookie
)
结合 LangGraph 使用
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from easycome_langchain import get_tools
tools = get_tools(platform="xhs")
agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools)
async for event in agent.astream_events(
{"messages": [{"role": "user", "content": "帮我分析小红书'穿搭'话题的热门笔记"}]},
version="v2",
):
# 处理流式事件
pass
Metadata
Release files for easycome-langchain 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easycome_langchain-0.1.0.tar.gz | 9.3 kB | Without provenance | Details for easycome_langchain-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easycome_langchain-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for easycome_langchain-0.1.0-py3-none-any.whl |
Total release size: 19.9 kB
Release files / easycome_langchain-0.1.0.tar.gz
| Download URL | easycome_langchain-0.1.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
936e979143d1d2e3753dd23fc2930a75c0b5749379e00f2aa19f3831a172bd72
|
|
BLAKE2b-256 checksum How to use checksums |
201c835de82400b23f0e85a621ffb6d9f06be6bae6e80e6b88889b0974e77672
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / easycome_langchain-0.1.0-py3-none-any.whl
| Download URL | easycome_langchain-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36da124df4d125c2899ae140513ee76dc5a9786e4df407b207382cedebd449b9
|
|
BLAKE2b-256 checksum How to use checksums |
45c6bd9d8d4609b92d0deab933bb15375059f9d801899ea3b5ef980b5756296f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for easycome-langchain 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.