datasetseek 0.1.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.
@@ -0,0 +1,5 @@
1
+ from .client import Client
2
+ from .exceptions import DatasetSeekError, AuthenticationError, APIError
3
+
4
+ __version__ = "0.1.0"
5
+ __all__ = ["Client", "DatasetSeekError", "AuthenticationError", "APIError"]
datasetseek/client.py ADDED
@@ -0,0 +1,39 @@
1
+ import requests
2
+ from .exceptions import AuthenticationError, APIError
3
+
4
+
5
+ class Client:
6
+ def __init__(self, api_key: str, base_url: str = "http://127.0.0.1:8001/sdk"):
7
+ """
8
+ 初始化客户端
9
+ :param api_key: 你的 API Key (dsk_开头)
10
+ :param base_url: 老系统的服务端地址 (上线后改成你的公网域名)
11
+ """
12
+ if not api_key:
13
+ raise ValueError("api_key 不能为空")
14
+
15
+ self.api_key = api_key
16
+ self.base_url = base_url.rstrip("/")
17
+ self.session = requests.Session()
18
+ # 自动加上 Bearer 前缀
19
+ self.session.headers.update({
20
+ "Authorization": f"Bearer {self.api_key}",
21
+ "Content-Type": "application/json"
22
+ })
23
+
24
+ def search(self, q: str, limit: int = 20):
25
+ """搜索数据集"""
26
+ url = f"{self.base_url}/v1/search"
27
+ params = {"q": q, "limit": limit}
28
+
29
+ try:
30
+ resp = self.session.get(url, params=params, timeout=10)
31
+ except requests.RequestException as e:
32
+ raise APIError(f"网络请求失败: {e}")
33
+
34
+ if resp.status_code == 401:
35
+ raise AuthenticationError("API Key 无效或已过期")
36
+ if resp.status_code != 200:
37
+ raise APIError(f"服务端错误: HTTP {resp.status_code} - {resp.text}")
38
+
39
+ return resp.json().get("data", [])
@@ -0,0 +1,11 @@
1
+ class DatasetSeekError(Exception):
2
+ """所有异常的基类"""
3
+ pass
4
+
5
+ class AuthenticationError(DatasetSeekError):
6
+ """API Key 无效或未提供"""
7
+ pass
8
+
9
+ class APIError(DatasetSeekError):
10
+ """服务端返回错误"""
11
+ pass
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.5
2
+ Name: datasetseek
3
+ Version: 0.1.0
4
+ Summary: DatasetSeek 官方 Python SDK
5
+ Requires-Python: >=3.8
6
+ Requires-Dist: requests>=2.28
7
+ Description-Content-Type: text/markdown
8
+
9
+ # datasetseek
10
+
11
+ DatasetSeek 官方 Python SDK。
12
+
13
+ ## 安装
14
+ pip install datasetseek-test
15
+
16
+ ## 快速开始
17
+ ```python
18
+ from datasetseek import Client
19
+
20
+ client = Client(api_key="你的dsk_key")
21
+ results = client.search("测试")
22
+ print(results)
@@ -0,0 +1,6 @@
1
+ datasetseek/__init__.py,sha256=3_gGr4WaoIS6GnnWAIPNo93FZDJ1T8TCrWmaECkb6Ic,201
2
+ datasetseek/client.py,sha256=oyyNU7eXLKd63P1cVJ5UDAVZE849IesdI0RTIG8YX0c,1400
3
+ datasetseek/exceptions.py,sha256=TM6t6FeI4opyvzY3yRHmv9l6ZaUmQHZtOYVMgHnNWoU,253
4
+ datasetseek-0.1.0.dist-info/METADATA,sha256=NyuYcQjkC0EiuOpv5SBCsnPm8qicUqyq4Ywl-pYjBP4,424
5
+ datasetseek-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
6
+ datasetseek-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any