seerapi 103.2.0__py3-none-any.whl
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.
- seerapi/__init__.py +58 -0
- seerapi/_client.py +168 -0
- seerapi/_client.pyi +855 -0
- seerapi/_model_map.py +60 -0
- seerapi/_models.py +27 -0
- seerapi/_typing.py +125 -0
- seerapi-103.2.0.dist-info/METADATA +374 -0
- seerapi-103.2.0.dist-info/RECORD +11 -0
- seerapi-103.2.0.dist-info/WHEEL +5 -0
- seerapi-103.2.0.dist-info/licenses/LICENSE +21 -0
- seerapi-103.2.0.dist-info/top_level.txt +1 -0
seerapi/_model_map.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import seerapi_models as M
|
|
2
|
+
|
|
3
|
+
from seerapi._typing import ModelName, ModelType
|
|
4
|
+
|
|
5
|
+
MODEL_MAP: dict[ModelName, ModelType] = {
|
|
6
|
+
'achievement': M.Achievement,
|
|
7
|
+
'achievement_branch': M.AchievementBranch,
|
|
8
|
+
'achievement_category': M.AchievementCategory,
|
|
9
|
+
'achievement_type': M.AchievementType,
|
|
10
|
+
'title': M.Title,
|
|
11
|
+
'battle_effect': M.BattleEffect,
|
|
12
|
+
'battle_effect_type': M.BattleEffectCategory,
|
|
13
|
+
'pet_effect': M.PetEffect,
|
|
14
|
+
'pet_effect_group': M.PetEffectGroup,
|
|
15
|
+
'pet_variation': M.VariationEffect,
|
|
16
|
+
'energy_bead': M.EnergyBead,
|
|
17
|
+
'equip': M.Equip,
|
|
18
|
+
'suit': M.Suit,
|
|
19
|
+
'equip_type': M.EquipType,
|
|
20
|
+
'equip_effective_occasion': M.EquipEffectiveOccasion,
|
|
21
|
+
'soulmark': M.Soulmark,
|
|
22
|
+
'soulmark_tag': M.SoulmarkTagCategory,
|
|
23
|
+
'element_type': M.ElementType,
|
|
24
|
+
'element_type_combination': M.TypeCombination,
|
|
25
|
+
'item': M.Item,
|
|
26
|
+
'item_category': M.ItemCategory,
|
|
27
|
+
'gem': M.Gem,
|
|
28
|
+
'gem_category': M.GemCategory,
|
|
29
|
+
'gem_generation_category': M.GemGenCategory,
|
|
30
|
+
'skill_activation_item': M.SkillActivationItem,
|
|
31
|
+
'skill_stone': M.SkillStone,
|
|
32
|
+
'skill_stone_category': M.SkillStoneCategory,
|
|
33
|
+
'mintmark': M.Mintmark,
|
|
34
|
+
'ability_mintmark': M.AbilityMintmark,
|
|
35
|
+
'skill_mintmark': M.SkillMintmark,
|
|
36
|
+
'universal_mintmark': M.UniversalMintmark,
|
|
37
|
+
'mintmark_class': M.MintmarkClassCategory,
|
|
38
|
+
'mintmark_type': M.MintmarkTypeCategory,
|
|
39
|
+
'mintmark_rarity': M.MintmarkRarityCategory,
|
|
40
|
+
'pet': M.Pet,
|
|
41
|
+
'pet_class': M.PetClass,
|
|
42
|
+
'pet_gender': M.PetGenderCategory,
|
|
43
|
+
'pet_vipbuff': M.PetVipBuffCategory,
|
|
44
|
+
'pet_mount_type': M.PetMountTypeCategory,
|
|
45
|
+
'pet_skin': M.PetSkin,
|
|
46
|
+
'pet_skin_category': M.PetSkinCategory,
|
|
47
|
+
'pet_archive_story_entry': M.PetArchiveStoryEntry,
|
|
48
|
+
'pet_archive_story_book': M.PetArchiveStoryBook,
|
|
49
|
+
'pet_encyclopedia_entry': M.PetEncyclopediaEntry,
|
|
50
|
+
'peak_pool': M.PeakPool,
|
|
51
|
+
'peak_expert_pool': M.PeakExpertPool,
|
|
52
|
+
'nature': M.Nature,
|
|
53
|
+
'skill': M.Skill,
|
|
54
|
+
'skill_effect_type': M.SkillEffectType,
|
|
55
|
+
'skill_effect_param': M.SkillEffectParam,
|
|
56
|
+
'skill_hide_effect': M.SkillHideEffect,
|
|
57
|
+
'skill_category': M.SkillCategory,
|
|
58
|
+
'skill_effect_type_tag': M.SkillEffectTypeTag,
|
|
59
|
+
'eid_effect': M.EidEffect,
|
|
60
|
+
}
|
seerapi/_models.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from collections.abc import AsyncGenerator
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Generic, TypeVar
|
|
4
|
+
|
|
5
|
+
T = TypeVar('T')
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class PageInfo:
|
|
10
|
+
offset: int = field(default=0)
|
|
11
|
+
limit: int = field(default=100)
|
|
12
|
+
|
|
13
|
+
def __post_init__(self) -> None:
|
|
14
|
+
if self.offset < 0:
|
|
15
|
+
raise ValueError('offset must be greater than or equal to 0')
|
|
16
|
+
if self.limit < 0:
|
|
17
|
+
raise ValueError('limit must be greater than or equal to 0')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class PagedResponse(Generic[T]):
|
|
22
|
+
results: AsyncGenerator[T, None]
|
|
23
|
+
count: int
|
|
24
|
+
next: PageInfo | None = None
|
|
25
|
+
previous: PageInfo | None = None
|
|
26
|
+
first: PageInfo | None = None
|
|
27
|
+
last: PageInfo | None = None
|
seerapi/_typing.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from typing import Literal, TypeAlias, TypeVar
|
|
2
|
+
|
|
3
|
+
import seerapi_models as M
|
|
4
|
+
from seerapi_models.build_model import BaseResModel
|
|
5
|
+
from seerapi_models.common import ResourceRef
|
|
6
|
+
|
|
7
|
+
NamedModelName: TypeAlias = Literal[
|
|
8
|
+
'achievement',
|
|
9
|
+
'achievement_branch',
|
|
10
|
+
'achievement_category',
|
|
11
|
+
'achievement_type',
|
|
12
|
+
'title',
|
|
13
|
+
'battle_effect',
|
|
14
|
+
'battle_effect_type',
|
|
15
|
+
'pet_effect',
|
|
16
|
+
'pet_effect_group',
|
|
17
|
+
'pet_variation',
|
|
18
|
+
'energy_bead',
|
|
19
|
+
'equip',
|
|
20
|
+
'suit',
|
|
21
|
+
'equip_type',
|
|
22
|
+
'soulmark_tag',
|
|
23
|
+
'element_type',
|
|
24
|
+
'element_type_combination',
|
|
25
|
+
'item',
|
|
26
|
+
'item_category',
|
|
27
|
+
'gem',
|
|
28
|
+
'gem_category',
|
|
29
|
+
'skill_activation_item',
|
|
30
|
+
'skill_stone',
|
|
31
|
+
'skill_stone_category',
|
|
32
|
+
'mintmark',
|
|
33
|
+
'ability_mintmark',
|
|
34
|
+
'skill_mintmark',
|
|
35
|
+
'universal_mintmark',
|
|
36
|
+
'mintmark_class',
|
|
37
|
+
'mintmark_type',
|
|
38
|
+
'pet',
|
|
39
|
+
'pet_gender',
|
|
40
|
+
'pet_vipbuff',
|
|
41
|
+
'pet_mount_type',
|
|
42
|
+
'pet_skin',
|
|
43
|
+
'pet_archive_story_book',
|
|
44
|
+
'pet_encyclopedia_entry',
|
|
45
|
+
'nature',
|
|
46
|
+
'skill',
|
|
47
|
+
'skill_hide_effect',
|
|
48
|
+
'skill_category',
|
|
49
|
+
'skill_effect_type_tag',
|
|
50
|
+
'soulmark',
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
# 所有可用的模型路径名称
|
|
54
|
+
ModelName: TypeAlias = Literal[
|
|
55
|
+
NamedModelName,
|
|
56
|
+
'equip_effective_occasion',
|
|
57
|
+
'gem_generation_category',
|
|
58
|
+
'mintmark_rarity',
|
|
59
|
+
'pet_class',
|
|
60
|
+
'pet_skin_category',
|
|
61
|
+
'pet_archive_story_entry',
|
|
62
|
+
'skill_effect_type',
|
|
63
|
+
'skill_effect_param',
|
|
64
|
+
'eid_effect',
|
|
65
|
+
'peak_pool',
|
|
66
|
+
'peak_expert_pool',
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
ModelInstance: TypeAlias = BaseResModel
|
|
70
|
+
NamedModelInstance: TypeAlias = (
|
|
71
|
+
M.Achievement
|
|
72
|
+
| M.AchievementBranch
|
|
73
|
+
| M.AchievementCategory
|
|
74
|
+
| M.AchievementType
|
|
75
|
+
| M.Title
|
|
76
|
+
| M.BattleEffect
|
|
77
|
+
| M.BattleEffectCategory
|
|
78
|
+
| M.PetEffect
|
|
79
|
+
| M.PetEffectGroup
|
|
80
|
+
| M.VariationEffect
|
|
81
|
+
| M.EnergyBead
|
|
82
|
+
| M.Equip
|
|
83
|
+
| M.Suit
|
|
84
|
+
| M.EquipType
|
|
85
|
+
| M.SoulmarkTagCategory
|
|
86
|
+
| M.ElementType
|
|
87
|
+
| M.TypeCombination
|
|
88
|
+
| M.Item
|
|
89
|
+
| M.ItemCategory
|
|
90
|
+
| M.Gem
|
|
91
|
+
| M.GemCategory
|
|
92
|
+
| M.SkillActivationItem
|
|
93
|
+
| M.SkillStone
|
|
94
|
+
| M.SkillStoneCategory
|
|
95
|
+
| M.Soulmark
|
|
96
|
+
| M.Mintmark
|
|
97
|
+
| M.AbilityMintmark
|
|
98
|
+
| M.SkillMintmark
|
|
99
|
+
| M.UniversalMintmark
|
|
100
|
+
| M.MintmarkClassCategory
|
|
101
|
+
| M.MintmarkTypeCategory
|
|
102
|
+
| M.Pet
|
|
103
|
+
| M.PetGenderCategory
|
|
104
|
+
| M.PetVipBuffCategory
|
|
105
|
+
| M.PetMountTypeCategory
|
|
106
|
+
| M.PetSkin
|
|
107
|
+
| M.PetArchiveStoryBook
|
|
108
|
+
| M.PetEncyclopediaEntry
|
|
109
|
+
| M.Nature
|
|
110
|
+
| M.Skill
|
|
111
|
+
| M.SkillHideEffect
|
|
112
|
+
| M.SkillCategory
|
|
113
|
+
| M.SkillEffectTypeTag
|
|
114
|
+
)
|
|
115
|
+
ModelType: TypeAlias = type[ModelInstance]
|
|
116
|
+
|
|
117
|
+
T_ModelInstance = TypeVar('T_ModelInstance', bound=ModelInstance)
|
|
118
|
+
T_NamedModelInstance = TypeVar('T_NamedModelInstance', bound=NamedModelInstance)
|
|
119
|
+
|
|
120
|
+
ResourceArg: TypeAlias = (
|
|
121
|
+
ModelName | type[T_ModelInstance] | ResourceRef[T_ModelInstance]
|
|
122
|
+
)
|
|
123
|
+
NamedResourceArg: TypeAlias = (
|
|
124
|
+
NamedModelName | type[T_NamedModelInstance] | ResourceRef[T_NamedModelInstance]
|
|
125
|
+
)
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: seerapi
|
|
3
|
+
Version: 103.2.0
|
|
4
|
+
Summary: SeerAPI Python Client
|
|
5
|
+
Author-email: Nattsu39 <Nattsu39@outlook.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 SeerAPI
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/SeerAPI/seerapi-python
|
|
29
|
+
Project-URL: Repository, https://github.com/SeerAPI/seerapi-python
|
|
30
|
+
Keywords: seerapi,client
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Requires-Dist: hishel[httpx]>=1.1.5
|
|
43
|
+
Requires-Dist: httpx>=0.28.1
|
|
44
|
+
Requires-Dist: seerapi-models<104.0.0,>=103.2.0
|
|
45
|
+
Requires-Dist: typing-extensions>=4.15.0
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# SeerAPI Python 客户端
|
|
49
|
+
|
|
50
|
+
[SeerAPI](https://github.com/SeerAPI) 是一个提供赛尔号游戏数据的开放 API 平台。本项目是 SeerAPI 的官方 Python 客户端库,提供了简洁易用的异步接口,支持获取精灵、技能、装备、刻印等 50+ 种游戏资源数据。
|
|
51
|
+
|
|
52
|
+
## 特性
|
|
53
|
+
|
|
54
|
+
- 🚀 **异步优先**:基于 `httpx` 和 `hishel` 构建,提供高性能的异步 HTTP 请求
|
|
55
|
+
- 💾 **自动缓存**:集成 HTTP 缓存机制,减少重复请求
|
|
56
|
+
- 🎯 **类型安全**:完整的类型提示支持,提供良好的 IDE 智能提示
|
|
57
|
+
- 📦 **分页支持**:内置分页处理,方便获取大量数据
|
|
58
|
+
- 🔄 **同步兼容**:提供 `async_to_sync` 装饰器,在同步代码中也能使用
|
|
59
|
+
## 安装
|
|
60
|
+
|
|
61
|
+
使用 pip 安装:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install seerapi
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
或使用 uv:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uv add seerapi
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 快速开始
|
|
74
|
+
|
|
75
|
+
### 异步使用方式
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
from seerapi import SeerAPI, PageInfo
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
# 使用异步上下文管理器,自动管理连接
|
|
83
|
+
async with SeerAPI() as client:
|
|
84
|
+
# 获取单个精灵信息
|
|
85
|
+
pet = await client.get('pet', id=1)
|
|
86
|
+
print(f"精灵名称: {pet.name}")
|
|
87
|
+
|
|
88
|
+
# 获取所有精灵(自动分页)
|
|
89
|
+
count = 0
|
|
90
|
+
async for pet in client.list('pet'):
|
|
91
|
+
print(f"ID: {pet.id}, 名称: {pet.name}")
|
|
92
|
+
count += 1
|
|
93
|
+
if count >= 10: # 只显示前 10 个
|
|
94
|
+
break
|
|
95
|
+
|
|
96
|
+
if __name__ == '__main__':
|
|
97
|
+
asyncio.run(main())
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 同步使用方式
|
|
101
|
+
|
|
102
|
+
如果你需要在同步代码中使用,可以使用 `async_to_sync` 装饰器:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from seerapi import SeerAPI, PageInfo, async_to_sync
|
|
106
|
+
|
|
107
|
+
@async_to_sync
|
|
108
|
+
async def get_pet_info(pet_id: int):
|
|
109
|
+
async with SeerAPI() as client:
|
|
110
|
+
pet = await client.get('pet', id=pet_id)
|
|
111
|
+
return pet
|
|
112
|
+
|
|
113
|
+
# 像普通同步函数一样调用
|
|
114
|
+
pet = get_pet_info(1)
|
|
115
|
+
print(pet.name)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## API 文档
|
|
119
|
+
|
|
120
|
+
### SeerAPI 客户端
|
|
121
|
+
|
|
122
|
+
#### 初始化
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from seerapi import SeerAPI
|
|
126
|
+
|
|
127
|
+
# 使用默认配置(指向官方 API)
|
|
128
|
+
client = SeerAPI()
|
|
129
|
+
|
|
130
|
+
# 自定义配置
|
|
131
|
+
client = SeerAPI(
|
|
132
|
+
scheme='https',
|
|
133
|
+
hostname='api.seerapi.com',
|
|
134
|
+
version_path='v1'
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### 方法
|
|
139
|
+
|
|
140
|
+
##### `get(resource_name, id)`
|
|
141
|
+
|
|
142
|
+
获取单个资源的详细信息。
|
|
143
|
+
|
|
144
|
+
**参数:**
|
|
145
|
+
- `resource_name` (str): 资源类型名称
|
|
146
|
+
- `id` (int): 资源 ID
|
|
147
|
+
|
|
148
|
+
**返回:**
|
|
149
|
+
- 对应的模型实例
|
|
150
|
+
|
|
151
|
+
**示例:**
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
# 获取精灵信息
|
|
155
|
+
pet = await client.get('pet', id=1)
|
|
156
|
+
|
|
157
|
+
# 获取技能信息
|
|
158
|
+
skill = await client.get('skill', id=100)
|
|
159
|
+
|
|
160
|
+
# 获取装备信息
|
|
161
|
+
equip = await client.get('equip', id=50)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
##### `list(resource_name)`
|
|
165
|
+
|
|
166
|
+
获取所有资源的异步生成器,自动处理分页。
|
|
167
|
+
|
|
168
|
+
**参数:**
|
|
169
|
+
- `resource_name` (str): 资源类型名称
|
|
170
|
+
|
|
171
|
+
**返回:**
|
|
172
|
+
- `AsyncGenerator`: 异步生成器,用于遍历所有资源
|
|
173
|
+
|
|
174
|
+
**示例:**
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
# 遍历所有精灵
|
|
178
|
+
async for pet in client.list('pet'):
|
|
179
|
+
print(pet.name)
|
|
180
|
+
|
|
181
|
+
# 只获取前 100 个
|
|
182
|
+
count = 0
|
|
183
|
+
async for pet in client.list('pet'):
|
|
184
|
+
print(pet.name)
|
|
185
|
+
count += 1
|
|
186
|
+
if count >= 100:
|
|
187
|
+
break
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
##### `paginated_list(resource_name, page_info)`
|
|
191
|
+
|
|
192
|
+
获取资源列表(手动分页控制)。
|
|
193
|
+
|
|
194
|
+
**参数:**
|
|
195
|
+
- `resource_name` (str): 资源类型名称
|
|
196
|
+
- `page_info` (PageInfo): 分页信息对象
|
|
197
|
+
|
|
198
|
+
**返回:**
|
|
199
|
+
- `PagedResponse` 对象,包含:
|
|
200
|
+
- `count` (int): 总记录数
|
|
201
|
+
- `results` (AsyncGenerator): 异步生成器,用于遍历当前页结果
|
|
202
|
+
- `next` (PageInfo | None): 下一页信息
|
|
203
|
+
- `previous` (PageInfo | None): 上一页信息
|
|
204
|
+
- `first` (PageInfo | None): 首页信息
|
|
205
|
+
- `last` (PageInfo | None): 末页信息
|
|
206
|
+
|
|
207
|
+
**示例:**
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from seerapi import PageInfo
|
|
211
|
+
|
|
212
|
+
# 获取前 20 条记录
|
|
213
|
+
page_info = PageInfo(offset=0, limit=20)
|
|
214
|
+
response = await client.paginated_list('pet', page_info)
|
|
215
|
+
|
|
216
|
+
# 查看总数
|
|
217
|
+
print(f"总数: {response.count}")
|
|
218
|
+
|
|
219
|
+
# 遍历当前页的结果
|
|
220
|
+
async for pet in response.results:
|
|
221
|
+
print(pet.name)
|
|
222
|
+
|
|
223
|
+
# 获取下一页
|
|
224
|
+
if response.next:
|
|
225
|
+
next_response = await client.paginated_list('pet', response.next)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
##### `get_by_name(resource_name, name)`
|
|
229
|
+
|
|
230
|
+
通过名称获取资源。该方法仅支持具有名称属性的资源类型。
|
|
231
|
+
|
|
232
|
+
**参数:**
|
|
233
|
+
- `resource_name` (str): 资源类型名称(必须是支持按名称查询的资源类型)
|
|
234
|
+
- `name` (str): 资源名称
|
|
235
|
+
|
|
236
|
+
**返回:**
|
|
237
|
+
- `NamedData` 对象,包含:
|
|
238
|
+
- `data[int, named_model_instance]`: 同名的模型实例字典,key 为 ID,value 为模型实例
|
|
239
|
+
|
|
240
|
+
**示例:**
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
# 通过名称获取技能
|
|
244
|
+
async with SeerAPI() as client:
|
|
245
|
+
skills = await client.get_by_name('skill', '虚妄幻境') # 有三个技能都叫虚妄幻境
|
|
246
|
+
for id, skill in skills.data.items():
|
|
247
|
+
print(id)
|
|
248
|
+
print(skill.skill_effect)
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
### PageInfo 类
|
|
252
|
+
|
|
253
|
+
用于指定分页参数。
|
|
254
|
+
|
|
255
|
+
**属性:**
|
|
256
|
+
- `offset` (int): 偏移量,默认为 0
|
|
257
|
+
- `limit` (int): 每页记录数,默认为 100
|
|
258
|
+
|
|
259
|
+
**示例:**
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from seerapi import PageInfo
|
|
263
|
+
|
|
264
|
+
# 获取第 1-10 条记录
|
|
265
|
+
page1 = PageInfo(offset=0, limit=10)
|
|
266
|
+
|
|
267
|
+
# 获取第 11-20 条记录
|
|
268
|
+
page2 = PageInfo(offset=10, limit=10)
|
|
269
|
+
|
|
270
|
+
# 获取第 21-30 条记录
|
|
271
|
+
page3 = PageInfo(offset=20, limit=10)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### async_to_sync 装饰器
|
|
275
|
+
|
|
276
|
+
将异步函数转换为同步函数的装饰器。
|
|
277
|
+
|
|
278
|
+
**示例:**
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
from seerapi import async_to_sync, SeerAPI
|
|
282
|
+
|
|
283
|
+
@async_to_sync
|
|
284
|
+
async def fetch_pet_list(limit: int = 10):
|
|
285
|
+
async with SeerAPI() as client:
|
|
286
|
+
pets = []
|
|
287
|
+
count = 0
|
|
288
|
+
async for pet in client.list('pet'):
|
|
289
|
+
pets.append(pet)
|
|
290
|
+
count += 1
|
|
291
|
+
if count >= limit:
|
|
292
|
+
break
|
|
293
|
+
return pets
|
|
294
|
+
|
|
295
|
+
# 同步调用
|
|
296
|
+
pets = fetch_pet_list(limit=5)
|
|
297
|
+
for pet in pets:
|
|
298
|
+
print(pet.name)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## 错误处理
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
import asyncio
|
|
305
|
+
from httpx import HTTPStatusError
|
|
306
|
+
from seerapi import SeerAPI
|
|
307
|
+
|
|
308
|
+
async def safe_get_pet(pet_id: int):
|
|
309
|
+
async with SeerAPI() as client:
|
|
310
|
+
try:
|
|
311
|
+
pet = await client.get('pet', id=pet_id)
|
|
312
|
+
return pet
|
|
313
|
+
except HTTPStatusError as e:
|
|
314
|
+
if e.response.status_code == 404:
|
|
315
|
+
print(f"精灵 ID {pet_id} 不存在")
|
|
316
|
+
else:
|
|
317
|
+
print(f"HTTP 错误: {e.response.status_code}")
|
|
318
|
+
return None
|
|
319
|
+
except Exception as e:
|
|
320
|
+
print(f"发生错误: {e}")
|
|
321
|
+
return None
|
|
322
|
+
|
|
323
|
+
asyncio.run(safe_get_pet(999999))
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## 开发环境设置
|
|
327
|
+
|
|
328
|
+
### 环境要求
|
|
329
|
+
|
|
330
|
+
- Python >= 3.10
|
|
331
|
+
- uv(推荐)或 pip
|
|
332
|
+
|
|
333
|
+
### 安装开发依赖
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
# 克隆仓库
|
|
337
|
+
git clone https://github.com/your-org/seerapi-python.git
|
|
338
|
+
cd seerapi-python
|
|
339
|
+
|
|
340
|
+
# 使用 uv 安装依赖(推荐)
|
|
341
|
+
uv sync
|
|
342
|
+
|
|
343
|
+
# 或使用 pip
|
|
344
|
+
pip install -e .
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 代码风格
|
|
348
|
+
|
|
349
|
+
项目使用 Ruff 进行代码格式化和检查:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
# 格式化代码
|
|
353
|
+
ruff format .
|
|
354
|
+
|
|
355
|
+
# 检查代码
|
|
356
|
+
ruff check .
|
|
357
|
+
|
|
358
|
+
# 自动修复问题
|
|
359
|
+
ruff check --fix .
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### 类型检查
|
|
363
|
+
|
|
364
|
+
项目使用 Pyright 进行类型检查:
|
|
365
|
+
|
|
366
|
+
## 依赖项
|
|
367
|
+
|
|
368
|
+
- [httpx](https://www.python-httpx.org/) - 现代化的 HTTP 客户端
|
|
369
|
+
- [hishel](https://hishel.com/) - HTTP 缓存库
|
|
370
|
+
- [seerapi-models](https://github.com/SeerAPI/seerapi-models) - SeerAPI 数据模型
|
|
371
|
+
|
|
372
|
+
## 许可证
|
|
373
|
+
|
|
374
|
+
本项目采用 MIT 许可证。详见 [LICENSE](LICENSE) 文件。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
seerapi/__init__.py,sha256=oP4s_fhv48V6PnHnOA0VuQ9YIsSjMxAs0E2fgTF00gs,1869
|
|
2
|
+
seerapi/_client.py,sha256=m43ISsdfVyuwV4B2WhHBLk9Or4v_UrY-li_7zvWAvhs,5606
|
|
3
|
+
seerapi/_client.pyi,sha256=9mFaaIZtwctzbX6SetxMuyEwYjmxZiK2SKkywpuGJi0,31442
|
|
4
|
+
seerapi/_model_map.py,sha256=clqSMCBUKGYTY81ZauER59X5NvLEWB9BJExV9KITz20,2210
|
|
5
|
+
seerapi/_models.py,sha256=fubjnRAZDxwuJl2JSUDQe_nLR0XAHAGJ9-b_vBgCJdg,713
|
|
6
|
+
seerapi/_typing.py,sha256=KAj_odULHSC062ZnracbZGvpLJcdrEdWOgjopUS0wjU,2883
|
|
7
|
+
seerapi-103.2.0.dist-info/licenses/LICENSE,sha256=4tEK_JQJu8HGOJCCahAO8SlqOjMaNqvXo6hO92aqTew,1064
|
|
8
|
+
seerapi-103.2.0.dist-info/METADATA,sha256=ppHNOuVSP2j06-ojE66b1aOYfFSFHyG7SwBzEszzUGw,9401
|
|
9
|
+
seerapi-103.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
seerapi-103.2.0.dist-info/top_level.txt,sha256=GpG2Z0LTRIfLCHgYzyFT-idDu4FqvPhNw77DGBg-Q00,8
|
|
11
|
+
seerapi-103.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SeerAPI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
seerapi
|