面向北森 Beisen OpenAPI 的异步 Python 迷你 SDK
Project description
leap-beisen-sdk
面向北森 (Beisen / iTalent) OpenAPI 的异步 Python 迷你 SDK。
PyPI 包名是 leap-beisen-sdk,Python import 包名保持为
beisen_custom_sdk。当前聚焦三个能力:
- access token 获取、缓存和自动刷新。
- 报表表头查询与报表数据分页查询。
- 应聘者原始简历文件地址获取。
环境要求
- Python >= 3.13
- 推荐使用 uv 管理项目
安装
pip install leap-beisen-sdk
使用 uv:
uv add leap-beisen-sdk
配置
复制 .env.template 为 .env 并填入北森应用凭证:
BEISEN_KEY=你的 app_key
BEISEN_SECRET=你的 app_secret
SDK 解析凭证的优先级是:显式传参 > 环境变量。
两者都未提供时,构造客户端会立即抛出 BeisenError。
快速开始
import asyncio
from beisen_custom_sdk import BeisenClient
async def main() -> None:
async with BeisenClient() as client:
header = await client.get_report_header("报表ID")
for col in header.columns:
print(f"{col.title} -> {col.id}")
page = await client.get_report_data("报表ID", page=1, page_size=100)
print(f"总记录数: {page.total_records}")
print(page.rows[0])
readable_page = await client.get_report_data(
"报表ID",
page=1,
page_size=100,
readable=True,
)
print(readable_page.rows[0])
resume = await client.get_resume_url("应聘者ID")
print(resume.download_url)
print(resume.preview_url)
asyncio.run(main())
也可以显式传入凭证:
async with BeisenClient(app_key="your_key", app_secret="your_secret") as client:
...
API 参考
BeisenClient
BeisenClient(
app_key: str | None = None,
app_secret: str | None = None,
*,
base_url: str = "https://openapi.italent.cn",
header_cache_ttl: float = 600,
timeout: float = 30,
max_retries: int = 10,
retry_base_delay: float = 1.0,
retry_max_delay: float = 30.0,
)
| 参数 | 说明 |
|---|---|
app_key |
北森应用 Key;为 None 时从 BEISEN_KEY 读取 |
app_secret |
北森应用 Secret;为 None 时从 BEISEN_SECRET 读取 |
base_url |
API 基础地址,默认北森生产环境 |
header_cache_ttl |
报表表头缓存有效期,单位秒 |
timeout |
HTTP 请求超时时间,单位秒 |
max_retries |
遇到 429 / 5xx 时的最大重试次数 |
retry_base_delay |
指数退避基础延迟 |
retry_max_delay |
单次退避等待上限 |
使用 async with 管理生命周期,退出时会自动关闭 HTTP 连接。
报表接口
get_report_header(report_id) -> ReportHeader
获取分析报表或定制报表的表头数据。
header = await client.get_report_header("80c0b3b2-858b-46ff-a509-d553d5a68496")
mapping = header.id_to_title_map()
get_report_data(report_id, page, page_size, *, readable=False) -> ReportPage
获取报表单页数据。SDK 不封装全量分页遍历,业务层自行控制分页。
page = await client.get_report_data("报表ID", page=1, page_size=100)
readable_page = await client.get_report_data(
"报表ID",
page=1,
page_size=100,
readable=True,
)
readable=True 时,SDK 会自动获取并缓存表头,把返回行里的 column_id
替换为 column_title。同一报表的后续请求不会重复调用表头接口,直到缓存过期。
简历接口
get_resume_url(applicant_id) -> ResumeInfo
获取应聘者原始简历文件地址。若北森返回的是 //... 地址,SDK 会自动补成
http://...。
resume = await client.get_resume_url("8b5ad780-6968-476d-b7e8-9226d6d8ff2e")
print(resume.download_url)
print(resume.preview_url)
print(resume.dfs_path)
数据模型
| 类 | 说明 |
|---|---|
ReportColumn |
报表列,含 title、id、sub_columns |
ReportHeader |
报表表头,含 is_complex、columns,提供 id_to_title_map() |
ReportPage |
单页数据,含 total_records、rows |
ResumeInfo |
简历信息,含 download_url、preview_url、dfs_path、raw |
异常处理
from beisen_custom_sdk import BeisenAPIError, BeisenAuthError, BeisenError
try:
header = await client.get_report_header("bad-id")
except BeisenAuthError:
# Token 获取或刷新失败
...
except BeisenAPIError as exc:
# 北森 API 业务错误
print(exc.code)
print(exc.api_message)
except BeisenError:
# 其他 SDK 异常
...
开发
uv sync --dev
uv run ruff check src tests
uv run pyright src
uv run pytest tests/ -v
uv run python -m compileall -q src
许可证
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
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 leap_beisen_sdk-0.1.2.tar.gz.
File metadata
- Download URL: leap_beisen_sdk-0.1.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a15c4028dd8551e585c7ed5bcffe82a1e4db846cc9baabb5eb99d6bf013f4baf
|
|
| MD5 |
1de385c8483c22e48f19dea1495fa946
|
|
| BLAKE2b-256 |
b1b62b6676bbea2d56d7c41be4b4b4db8e3496e28ccfdd82c477c3fc42d7ec70
|
Provenance
The following attestation bundles were made for leap_beisen_sdk-0.1.2.tar.gz:
Publisher:
publish.yml on Llugaes/leap-beisen-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leap_beisen_sdk-0.1.2.tar.gz -
Subject digest:
a15c4028dd8551e585c7ed5bcffe82a1e4db846cc9baabb5eb99d6bf013f4baf - Sigstore transparency entry: 1765658566
- Sigstore integration time:
-
Permalink:
Llugaes/leap-beisen-sdk@ae8b1dfadcc972907e440094e80b1ac7f0f864fa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Llugaes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae8b1dfadcc972907e440094e80b1ac7f0f864fa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file leap_beisen_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: leap_beisen_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c201a5b1cbd7738f7231e03a045308339258b84db9f9173a3cb451c234d5012
|
|
| MD5 |
2948868b7f34269070bd3db459411f54
|
|
| BLAKE2b-256 |
535e1b6ee04c8aad5fb5c0bcdbc80ef6be3d2d5dfa79deb9edbe177cf36da439
|
Provenance
The following attestation bundles were made for leap_beisen_sdk-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on Llugaes/leap-beisen-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leap_beisen_sdk-0.1.2-py3-none-any.whl -
Subject digest:
9c201a5b1cbd7738f7231e03a045308339258b84db9f9173a3cb451c234d5012 - Sigstore transparency entry: 1765658854
- Sigstore integration time:
-
Permalink:
Llugaes/leap-beisen-sdk@ae8b1dfadcc972907e440094e80b1ac7f0f864fa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Llugaes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae8b1dfadcc972907e440094e80b1ac7f0f864fa -
Trigger Event:
workflow_dispatch
-
Statement type: