wsapi-sdk 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: wsapi-sdk
3
+ Version: 0.1.1
4
+ Summary: WasaiTalent API Python SDK
5
+ Author-email: Chandler <275737875@qq.com>
6
+ Requires-Python: >=3.8
7
+ Requires-Dist: requests>=2.28.0
8
+ Provides-Extra: dev
9
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
10
+ Requires-Dist: responses>=0.23.0; extra == "dev"
@@ -0,0 +1,236 @@
1
+ # WasaiTalent API Python SDK
2
+
3
+ WasaiTalent 人才管理系统后端 API 的 Python 客户端封装。
4
+
5
+ ## 环境准备
6
+
7
+ Python >= 3.8
8
+
9
+ ### 安装 SDK(开发模式)
10
+
11
+ ```bash
12
+ cd wsapi
13
+ pip install -e ".[dev]"
14
+ ```
15
+
16
+ 这会将 `wsapi` 以可编辑模式安装到当前 Python 环境中,安装后即可在任意目录下 `from wsapi import ...`。
17
+
18
+ ### 仅安装运行时依赖
19
+
20
+ ```bash
21
+ cd wsapi
22
+ pip install -r requirements.txt
23
+ ```
24
+
25
+ ## 快速开始
26
+
27
+ ### 1. JWT 认证模式(Auth / Talents / Admin)
28
+
29
+ ```python
30
+ from wsapi import WasaiTalentClient
31
+
32
+ client = WasaiTalentClient(base_url="http://localhost:3001")
33
+
34
+ # 注册
35
+ client.auth.register("admin", "admin@example.com", "password123")
36
+
37
+ # 登录(token 自动保存)
38
+ client.auth.login("admin", "password123")
39
+
40
+ # 查看当前用户
41
+ me = client.auth.me()
42
+ print(me) # {"user": {"id": 1, "username": "admin", ...}}
43
+ ```
44
+
45
+ ### 2. 人才管理(需先登录)
46
+
47
+ ```python
48
+ # 创建人才
49
+ talent = client.talents.create(
50
+ "张三",
51
+ company="OpenAI",
52
+ email="zhang@openai.com",
53
+ location="北京",
54
+ skills="Python,ML",
55
+ )
56
+ tid = talent["data"]["id"]
57
+
58
+ # 查询列表(支持 25+ 个筛选参数)
59
+ result = client.talents.list(search="张三", location="北京", page=1, limit=20)
60
+ print(result["pagination"])
61
+
62
+ # 查看详情(含 profiles / experiences / notes 等子资源)
63
+ detail = client.talents.get(tid)
64
+
65
+ # 更新
66
+ client.talents.update(tid, company="Anthropic", title="Research Engineer")
67
+
68
+ # 删除
69
+ client.talents.delete(tid)
70
+ ```
71
+
72
+ ### 3. 子资源管理(备注 / 经历 / 论文 / 专利 等)
73
+
74
+ ```python
75
+ # 备注
76
+ client.talents.add_note(tid, "优秀候选人,建议跟进")
77
+ client.talents.list_notes(tid)
78
+ client.talents.update_note(tid, note_id=1, content="已完成初试")
79
+ client.talents.delete_note(tid, note_id=1)
80
+
81
+ # 工作经历
82
+ client.talents.add_experience(tid, company="Google", title="SWE", start_date="2020-01")
83
+ client.talents.list_experiences(tid)
84
+
85
+ # 教育经历
86
+ client.talents.add_education(tid, school="清华大学", degree="硕士", field="计算机科学")
87
+
88
+ # 论文
89
+ client.talents.add_paper(tid, "Attention Is All You Need", year=2017, venue="NeurIPS")
90
+
91
+ # 专利
92
+ client.talents.add_patent(tid, "AI 辅助编程方法", patent_type="发明专利")
93
+
94
+ # 行业会议
95
+ client.talents.add_conference(tid, "NeurIPS", role="Speaker", year=2024)
96
+
97
+ # GitHub 项目
98
+ client.talents.add_repo(tid, "transformer", language="Python", stars=5000)
99
+
100
+ # 平台档案
101
+ client.talents.create_profile(tid, "github", username="zhangsan", platform_url="https://github.com/zhangsan")
102
+
103
+ # 跟盯记录
104
+ client.talents.add_followup(tid, "已发送 offer", type="offer", next_action="等待回复", next_date="2025-02-01")
105
+ ```
106
+
107
+ ### 4. 人才关联/取消关联
108
+
109
+ ```python
110
+ # 关联两个人才
111
+ client.talents.merge(primary_talent_id=1, merged_talent_id=2, match_type="email")
112
+
113
+ # 取消关联
114
+ client.talents.unmerge(primary_talent_id=1, merged_talent_id=2)
115
+ ```
116
+
117
+ ### 5. 统计查询
118
+
119
+ ```python
120
+ client.talents.stats_sources() # 按数据来源
121
+ client.talents.stats_import_methods() # 按导入方式
122
+ client.talents.stats_companies() # 按公司(Top 20)
123
+ client.talents.stats_platforms() # 按平台档案
124
+ ```
125
+
126
+ ### 6. 管理员接口(需 admin 角色)
127
+
128
+ ```python
129
+ # 系统概览
130
+ dashboard = client.admin.dashboard()
131
+
132
+ # 用户管理
133
+ client.admin.list_users()
134
+ client.admin.update_user_role(user_id=2, role="viewer")
135
+ client.admin.delete_user(user_id=3)
136
+
137
+ # API Key 管理
138
+ key = client.admin.create_api_key("数据导入 Key", permissions="read,write")
139
+ api_key_value = key["data"]["key"] # 仅在创建时返回一次
140
+ client.admin.list_api_keys()
141
+ client.admin.delete_api_key(key_id=1)
142
+ ```
143
+
144
+ ### 7. 开放接口(API Key 认证)
145
+
146
+ ```python
147
+ client = WasaiTalentClient(
148
+ base_url="http://localhost:3001",
149
+ api_key="your-api-key-here",
150
+ )
151
+
152
+ # 查询人才
153
+ client.open.list_talents(search="李四", limit=50)
154
+ client.open.get_talent(1)
155
+ client.open.create_talent("王五", company="腾讯")
156
+
157
+ # 多平台导入
158
+ client.open.import_github({"login": "torvalds", "name": "Linus"})
159
+ client.open.import_github_batch([{"login": "user1"}, {"login": "user2"}])
160
+
161
+ client.open.import_maimai({"name": "张三", "company": "字节跳动"})
162
+ client.open.import_maimai_batch([{"name": "用户A"}])
163
+
164
+ client.open.import_linkedin({"name": "Alice", "company": "Google", "experience": [...]})
165
+ client.open.import_wechat({"name": "微信用户", "wechat_id": "wx123"})
166
+ client.open.import_wechat_batch([{"name": "联系人A"}])
167
+
168
+ client.open.import_arxiv({"name": "Researcher", "papers": [...]})
169
+ client.open.import_patent({"name": "Inventor", "patents": [...]})
170
+ client.open.import_conference({"name": "Speaker", "conferences": [...]})
171
+
172
+ # CSV 导入/导出
173
+ client.open.import_csv("./talents.csv")
174
+ csv_text = client.open.export_csv()
175
+
176
+ # JSON 批量导入
177
+ client.open.batch_import([{"name": "批量用户1"}, {"name": "批量用户2"}])
178
+
179
+ # 人才关联
180
+ client.open.merge(primary_talent_id=1, merged_talent_id=2)
181
+ ```
182
+
183
+ ## 异常处理
184
+
185
+ ```python
186
+ from wsapi import (
187
+ WasaiAPIError, # 基础异常
188
+ AuthenticationError, # 401
189
+ ForbiddenError, # 403
190
+ NotFoundError, # 404
191
+ ConflictError, # 409
192
+ ValidationError, # 400
193
+ ServerError, # 500
194
+ )
195
+
196
+ try:
197
+ client.talents.get(999)
198
+ except NotFoundError as e:
199
+ print(e.status_code, e.message)
200
+ except WasaiAPIError as e:
201
+ print(f"API 错误: {e}")
202
+ ```
203
+
204
+ ## 运行测试
205
+
206
+ ```bash
207
+ # 推荐方式:在 wsapi/ 目录下执行 pytest(会自动发现 tests/ 目录)
208
+ cd wsapi
209
+ pytest -v
210
+
211
+ # 也可以从项目根目录执行
212
+ cd project-root
213
+ pytest wsapi/tests/ -v
214
+
215
+ # 运行单个测试文件
216
+ cd wsapi
217
+ pytest tests/test_admin.py -v
218
+ ```
219
+
220
+ ## 目录结构
221
+
222
+ ```
223
+ wsapi/
224
+ ├── __init__.py # 包入口,导出所有公共类
225
+ ├── client.py # 核心实现:_BaseClient + AuthAPI/TalentAPI/AdminAPI/OpenAPI + WasaiTalentClient
226
+ ├── exceptions.py # 自定义异常类
227
+ ├── pyproject.toml # 包构建配置 & pytest 配置
228
+ ├── requirements.txt # 依赖声明(兼容旧方式)
229
+ ├── README.md # 本文档
230
+ └── tests/
231
+ ├── conftest.py # pytest 公共 fixtures(mock_api / client)
232
+ ├── test_auth.py # AuthAPI 测试
233
+ ├── test_talents.py # TalentAPI 测试
234
+ ├── test_admin.py # AdminAPI 测试
235
+ └── test_openapi.py # OpenAPI 测试
236
+ ```
@@ -0,0 +1,35 @@
1
+ """WasaiTalent API Python SDK"""
2
+
3
+ from .client import (
4
+ WasaiTalentClient,
5
+ AuthAPI,
6
+ TalentAPI,
7
+ AdminAPI,
8
+ OpenAPI,
9
+ )
10
+ from .exceptions import (
11
+ WasaiAPIError,
12
+ AuthenticationError,
13
+ ForbiddenError,
14
+ NotFoundError,
15
+ ConflictError,
16
+ ValidationError,
17
+ ServerError,
18
+ )
19
+
20
+ __all__ = [
21
+ "WasaiTalentClient",
22
+ "AuthAPI",
23
+ "TalentAPI",
24
+ "AdminAPI",
25
+ "OpenAPI",
26
+ "WasaiAPIError",
27
+ "AuthenticationError",
28
+ "ForbiddenError",
29
+ "NotFoundError",
30
+ "ConflictError",
31
+ "ValidationError",
32
+ "ServerError",
33
+ ]
34
+
35
+ __version__ = "0.1.1"