freelybase 1.0.0__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.
- freelybase-1.0.0/LICENSE +21 -0
- freelybase-1.0.0/PKG-INFO +104 -0
- freelybase-1.0.0/README.md +61 -0
- freelybase-1.0.0/pyproject.toml +24 -0
- freelybase-1.0.0/setup.cfg +4 -0
- freelybase-1.0.0/src/freelybase/__init__.py +86 -0
- freelybase-1.0.0/src/freelybase/client.py +134 -0
- freelybase-1.0.0/src/freelybase/exceptions.py +19 -0
- freelybase-1.0.0/src/freelybase/fb_ai.py +267 -0
- freelybase-1.0.0/src/freelybase/fb_file.py +150 -0
- freelybase-1.0.0/src/freelybase/fb_live_query.py +238 -0
- freelybase-1.0.0/src/freelybase/fb_object.py +253 -0
- freelybase-1.0.0/src/freelybase/fb_query.py +359 -0
- freelybase-1.0.0/src/freelybase/fb_user.py +303 -0
- freelybase-1.0.0/src/freelybase/geo_point.py +93 -0
- freelybase-1.0.0/src/freelybase/helpers.py +119 -0
- freelybase-1.0.0/src/freelybase/query.py +118 -0
- freelybase-1.0.0/src/freelybase.egg-info/PKG-INFO +104 -0
- freelybase-1.0.0/src/freelybase.egg-info/SOURCES.txt +21 -0
- freelybase-1.0.0/src/freelybase.egg-info/dependency_links.txt +1 -0
- freelybase-1.0.0/src/freelybase.egg-info/requires.txt +15 -0
- freelybase-1.0.0/src/freelybase.egg-info/top_level.txt +1 -0
- freelybase-1.0.0/tests/test_sdk.py +288 -0
freelybase-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FreelyBase
|
|
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,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: freelybase
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: FreelyBase Python SDK
|
|
5
|
+
Author-email: Zhengshaomin <daboluo719@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 FreelyBase
|
|
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
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: requests>=2.28
|
|
32
|
+
Provides-Extra: async
|
|
33
|
+
Requires-Dist: httpx>=0.24; extra == "async"
|
|
34
|
+
Provides-Extra: realtime
|
|
35
|
+
Requires-Dist: websocket-client>=1.6; extra == "realtime"
|
|
36
|
+
Provides-Extra: crypto
|
|
37
|
+
Requires-Dist: cryptography>=41.0; extra == "crypto"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: httpx>=0.24; extra == "all"
|
|
40
|
+
Requires-Dist: websocket-client>=1.6; extra == "all"
|
|
41
|
+
Requires-Dist: cryptography>=41.0; extra == "all"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# FreelyBase Python SDK
|
|
45
|
+
|
|
46
|
+
Python SDK for [FreelyBase](http://www.freelybase.com), aligned with the Kotlin SDK.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install freelybase
|
|
52
|
+
# with optional extras
|
|
53
|
+
pip install "freelybase[realtime]" # FBLiveQuery (WebSocket)
|
|
54
|
+
pip install "freelybase[async]" # AsyncFreelyBase (httpx)
|
|
55
|
+
pip install "freelybase[crypto]" # EncryptedFreelyBase
|
|
56
|
+
pip install "freelybase[all]" # everything
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from freelybase import FreelyBase, FBObject, FBQuery, FBUser, FBFile, FBGeoPoint, FBAI
|
|
63
|
+
|
|
64
|
+
# Initialize
|
|
65
|
+
FreelyBase.initialize(app_key="your_app_id", base_url="https://your-domain.com")
|
|
66
|
+
|
|
67
|
+
# Define a model
|
|
68
|
+
class Post(FBObject):
|
|
69
|
+
table_name = "Post"
|
|
70
|
+
title: str = ""
|
|
71
|
+
view_count: int = 0
|
|
72
|
+
active: bool = True
|
|
73
|
+
|
|
74
|
+
# Create
|
|
75
|
+
post = Post(title="Hello", active=True)
|
|
76
|
+
post.save()
|
|
77
|
+
|
|
78
|
+
# Query
|
|
79
|
+
results = FBQuery(Post).equal_to("active", True).order("-created_at").limit(20).find()
|
|
80
|
+
|
|
81
|
+
# User login
|
|
82
|
+
user = FBUser.login("user@example.com", "password123")
|
|
83
|
+
|
|
84
|
+
# File upload
|
|
85
|
+
fb_file = FBFile.upload("photo.jpg")
|
|
86
|
+
print(fb_file.url)
|
|
87
|
+
|
|
88
|
+
# AI chat
|
|
89
|
+
response = FBAI.chat("Hello!")
|
|
90
|
+
print(response.content)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Features
|
|
94
|
+
|
|
95
|
+
| Class | Description |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `FreelyBase` | Global client & HTTP |
|
|
98
|
+
| `FBObject` | Data model base class |
|
|
99
|
+
| `FBQuery` | Query builder with geo, time, cache |
|
|
100
|
+
| `FBUser` | Auth: register, login, third-party |
|
|
101
|
+
| `FBFile` | File upload & URL resolution |
|
|
102
|
+
| `FBGeoPoint` | Geo coordinates & distance |
|
|
103
|
+
| `FBLiveQuery` | Real-time WebSocket listener |
|
|
104
|
+
| `FBAI` | AI chat (streaming & non-streaming) |
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# FreelyBase Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for [FreelyBase](http://www.freelybase.com), aligned with the Kotlin SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install freelybase
|
|
9
|
+
# with optional extras
|
|
10
|
+
pip install "freelybase[realtime]" # FBLiveQuery (WebSocket)
|
|
11
|
+
pip install "freelybase[async]" # AsyncFreelyBase (httpx)
|
|
12
|
+
pip install "freelybase[crypto]" # EncryptedFreelyBase
|
|
13
|
+
pip install "freelybase[all]" # everything
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from freelybase import FreelyBase, FBObject, FBQuery, FBUser, FBFile, FBGeoPoint, FBAI
|
|
20
|
+
|
|
21
|
+
# Initialize
|
|
22
|
+
FreelyBase.initialize(app_key="your_app_id", base_url="https://your-domain.com")
|
|
23
|
+
|
|
24
|
+
# Define a model
|
|
25
|
+
class Post(FBObject):
|
|
26
|
+
table_name = "Post"
|
|
27
|
+
title: str = ""
|
|
28
|
+
view_count: int = 0
|
|
29
|
+
active: bool = True
|
|
30
|
+
|
|
31
|
+
# Create
|
|
32
|
+
post = Post(title="Hello", active=True)
|
|
33
|
+
post.save()
|
|
34
|
+
|
|
35
|
+
# Query
|
|
36
|
+
results = FBQuery(Post).equal_to("active", True).order("-created_at").limit(20).find()
|
|
37
|
+
|
|
38
|
+
# User login
|
|
39
|
+
user = FBUser.login("user@example.com", "password123")
|
|
40
|
+
|
|
41
|
+
# File upload
|
|
42
|
+
fb_file = FBFile.upload("photo.jpg")
|
|
43
|
+
print(fb_file.url)
|
|
44
|
+
|
|
45
|
+
# AI chat
|
|
46
|
+
response = FBAI.chat("Hello!")
|
|
47
|
+
print(response.content)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
| Class | Description |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `FreelyBase` | Global client & HTTP |
|
|
55
|
+
| `FBObject` | Data model base class |
|
|
56
|
+
| `FBQuery` | Query builder with geo, time, cache |
|
|
57
|
+
| `FBUser` | Auth: register, login, third-party |
|
|
58
|
+
| `FBFile` | File upload & URL resolution |
|
|
59
|
+
| `FBGeoPoint` | Geo coordinates & distance |
|
|
60
|
+
| `FBLiveQuery` | Real-time WebSocket listener |
|
|
61
|
+
| `FBAI` | AI chat (streaming & non-streaming) |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta:__legacy__"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "freelybase"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "FreelyBase Python SDK"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{name = "Zhengshaomin", email = "daboluo719@gmail.com"}]
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"requests>=2.28",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
async = ["httpx>=0.24"]
|
|
19
|
+
realtime = ["websocket-client>=1.6"]
|
|
20
|
+
crypto = ["cryptography>=41.0"]
|
|
21
|
+
all = ["httpx>=0.24", "websocket-client>=1.6", "cryptography>=41.0"]
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FreelyBase Python SDK
|
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
4
|
+
标准 Python 包,对齐 Kotlin SDK 能力。
|
|
5
|
+
|
|
6
|
+
依赖:
|
|
7
|
+
pip install requests # 必须
|
|
8
|
+
pip install websocket-client # FBLiveQuery 实时监听
|
|
9
|
+
pip install httpx # AsyncFreelyBase 异步客户端
|
|
10
|
+
pip install cryptography # EncryptedFreelyBase 请求加密
|
|
11
|
+
|
|
12
|
+
快速开始:
|
|
13
|
+
from freelybase import FreelyBase, FBObject, FBQuery, FBUser, FBFile, FBGeoPoint, FBAI
|
|
14
|
+
|
|
15
|
+
# 初始化
|
|
16
|
+
FreelyBase.initialize(app_key="your_app_id", base_url="https://your-domain.com")
|
|
17
|
+
|
|
18
|
+
# 定义数据模型
|
|
19
|
+
class Post(FBObject):
|
|
20
|
+
table_name = "Post"
|
|
21
|
+
title: str = ""
|
|
22
|
+
view_count: int = 0
|
|
23
|
+
active: bool = True
|
|
24
|
+
|
|
25
|
+
# 新增
|
|
26
|
+
post = Post(title="Hello", active=True)
|
|
27
|
+
post.save()
|
|
28
|
+
|
|
29
|
+
# 查询
|
|
30
|
+
results = FBQuery(Post).equal_to("active", True).order("-created_at").limit(20).find()
|
|
31
|
+
|
|
32
|
+
# 用户登录
|
|
33
|
+
user = FBUser.login("user@example.com", "password123")
|
|
34
|
+
|
|
35
|
+
# 文件上传
|
|
36
|
+
fb_file = FBFile.upload("photo.jpg")
|
|
37
|
+
print(fb_file.url)
|
|
38
|
+
|
|
39
|
+
# AI 聊天
|
|
40
|
+
response = FBAI.chat("你好")
|
|
41
|
+
print(response.content)
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
from .exceptions import FreelyBaseException, FreelyBaseError
|
|
45
|
+
from .client import FreelyBase
|
|
46
|
+
from .geo_point import FBGeoPoint, DistanceUnit
|
|
47
|
+
from .fb_file import FBFile
|
|
48
|
+
from .fb_object import FBObject
|
|
49
|
+
from .fb_query import FBQuery, CachePolicy, clear_query_cache
|
|
50
|
+
from .fb_user import FBUser
|
|
51
|
+
from .fb_live_query import FBLiveQuery
|
|
52
|
+
from .fb_ai import FBAI, AiMessage, AiQuota, AiChatResponse
|
|
53
|
+
from .query import Query
|
|
54
|
+
from .helpers import Relation, Batch
|
|
55
|
+
|
|
56
|
+
__version__ = "2.0.0"
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
# 核心
|
|
60
|
+
"FreelyBase",
|
|
61
|
+
"FreelyBaseException",
|
|
62
|
+
"FreelyBaseError", # 向后兼容
|
|
63
|
+
# 数据模型
|
|
64
|
+
"FBObject",
|
|
65
|
+
"FBQuery",
|
|
66
|
+
"CachePolicy",
|
|
67
|
+
"clear_query_cache",
|
|
68
|
+
# 用户
|
|
69
|
+
"FBUser",
|
|
70
|
+
# 文件
|
|
71
|
+
"FBFile",
|
|
72
|
+
# 地理位置
|
|
73
|
+
"FBGeoPoint",
|
|
74
|
+
"DistanceUnit",
|
|
75
|
+
# 实时监听
|
|
76
|
+
"FBLiveQuery",
|
|
77
|
+
# AI
|
|
78
|
+
"FBAI",
|
|
79
|
+
"AiMessage",
|
|
80
|
+
"AiQuota",
|
|
81
|
+
"AiChatResponse",
|
|
82
|
+
# 轻量级字典 API(兼容旧版)
|
|
83
|
+
"Query",
|
|
84
|
+
"Relation",
|
|
85
|
+
"Batch",
|
|
86
|
+
]
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""FreelyBase SDK 全局配置与 HTTP 客户端"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any, Dict, Optional
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
from .exceptions import FreelyBaseException
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FreelyBase:
|
|
13
|
+
"""
|
|
14
|
+
FreelyBase SDK 主入口(单例风格,也可实例化使用)。
|
|
15
|
+
|
|
16
|
+
推荐用法(全局初始化):
|
|
17
|
+
FreelyBase.initialize(app_key="your_app_id", base_url="https://your-domain.com")
|
|
18
|
+
|
|
19
|
+
也可直接实例化:
|
|
20
|
+
fb = FreelyBase(app_key="your_app_id")
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# ── 全局单例状态 ──────────────────────────────────────────────────────────
|
|
24
|
+
_instance: Optional["FreelyBase"] = None
|
|
25
|
+
|
|
26
|
+
base_url: str = "http://www.freelybase.com/api"
|
|
27
|
+
app_key: str = ""
|
|
28
|
+
token: Optional[str] = None
|
|
29
|
+
debug: bool = False
|
|
30
|
+
_timeout: int = 15
|
|
31
|
+
_session: requests.Session = requests.Session()
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
app_key: str = "",
|
|
36
|
+
base_url: str = "http://www.freelybase.com/api",
|
|
37
|
+
token: Optional[str] = None,
|
|
38
|
+
timeout: int = 15,
|
|
39
|
+
debug: bool = False,
|
|
40
|
+
):
|
|
41
|
+
self.app_key = app_key
|
|
42
|
+
self.base_url = base_url.rstrip("/")
|
|
43
|
+
self.token = token
|
|
44
|
+
self._timeout = timeout
|
|
45
|
+
self.debug = debug
|
|
46
|
+
self._session = requests.Session()
|
|
47
|
+
# 设置为全局实例
|
|
48
|
+
FreelyBase._instance = self
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def initialize(
|
|
52
|
+
cls,
|
|
53
|
+
app_key: str,
|
|
54
|
+
base_url: str = "http://www.freelybase.com/api",
|
|
55
|
+
timeout: int = 15,
|
|
56
|
+
debug: bool = False,
|
|
57
|
+
) -> "FreelyBase":
|
|
58
|
+
"""初始化全局 SDK 实例,返回实例供链式调用。"""
|
|
59
|
+
inst = cls(app_key=app_key, base_url=base_url, timeout=timeout, debug=debug)
|
|
60
|
+
cls._instance = inst
|
|
61
|
+
return inst
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def get_instance(cls) -> "FreelyBase":
|
|
65
|
+
if cls._instance is None:
|
|
66
|
+
raise FreelyBaseException("FreelyBase 未初始化,请先调用 FreelyBase.initialize()")
|
|
67
|
+
return cls._instance
|
|
68
|
+
|
|
69
|
+
# ── Token 管理 ────────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
def set_token(self, token: Optional[str]) -> None:
|
|
72
|
+
self.token = token
|
|
73
|
+
|
|
74
|
+
def clear_token(self) -> None:
|
|
75
|
+
self.token = None
|
|
76
|
+
|
|
77
|
+
def is_logged_in(self) -> bool:
|
|
78
|
+
return bool(self.token)
|
|
79
|
+
|
|
80
|
+
# ── 内部 HTTP ─────────────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
def _headers(self) -> Dict[str, str]:
|
|
83
|
+
h: Dict[str, str] = {"Content-Type": "application/json"}
|
|
84
|
+
if self.token:
|
|
85
|
+
h["Authorization"] = f"Bearer {self.token}"
|
|
86
|
+
return h
|
|
87
|
+
|
|
88
|
+
def _url(self, path: str) -> str:
|
|
89
|
+
return f"{self.base_url}/{path.lstrip('/')}"
|
|
90
|
+
|
|
91
|
+
def _request(self, method: str, path: str, **kwargs) -> Any:
|
|
92
|
+
url = self._url(path)
|
|
93
|
+
kwargs.setdefault("headers", self._headers())
|
|
94
|
+
kwargs.setdefault("timeout", self._timeout)
|
|
95
|
+
if self.debug:
|
|
96
|
+
print(f"[FreelyBase] {method} {url}")
|
|
97
|
+
resp = self._session.request(method, url, **kwargs)
|
|
98
|
+
if not resp.ok:
|
|
99
|
+
try:
|
|
100
|
+
detail = resp.json().get("detail", resp.text)
|
|
101
|
+
except Exception:
|
|
102
|
+
detail = resp.text
|
|
103
|
+
raise FreelyBaseException(
|
|
104
|
+
f"Request failed: {method} {url}",
|
|
105
|
+
status_code=resp.status_code,
|
|
106
|
+
detail=detail,
|
|
107
|
+
)
|
|
108
|
+
if resp.status_code == 204 or not resp.content:
|
|
109
|
+
return {}
|
|
110
|
+
return resp.json()
|
|
111
|
+
|
|
112
|
+
def get(self, path: str, params: Optional[Dict] = None) -> Any:
|
|
113
|
+
return self._request("GET", path, params=params, headers=self._headers())
|
|
114
|
+
|
|
115
|
+
def post(self, path: str, body: Any = None) -> Any:
|
|
116
|
+
return self._request("POST", path, json=body, headers=self._headers())
|
|
117
|
+
|
|
118
|
+
def put(self, path: str, body: Any = None) -> Any:
|
|
119
|
+
return self._request("PUT", path, json=body, headers=self._headers())
|
|
120
|
+
|
|
121
|
+
def delete(self, path: str) -> Any:
|
|
122
|
+
return self._request("DELETE", path, headers=self._headers())
|
|
123
|
+
|
|
124
|
+
# ── 服务器时间 ────────────────────────────────────────────────────────────
|
|
125
|
+
|
|
126
|
+
def server_time(self) -> str:
|
|
127
|
+
"""获取服务器时间,返回 ISO 8601 字符串。"""
|
|
128
|
+
result = self.get("/public/server-time")
|
|
129
|
+
return result.get("server_time", "")
|
|
130
|
+
|
|
131
|
+
def get_public_key(self) -> str:
|
|
132
|
+
"""获取 RSA 公钥(用于请求加密)。"""
|
|
133
|
+
result = self.get("/crypto/public-key")
|
|
134
|
+
return result.get("public_key_pem", "")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""FreelyBase SDK 异常定义"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class FreelyBaseException(Exception):
|
|
7
|
+
"""SDK 基础异常"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, status_code: int = 0, detail: Any = None):
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.status_code = status_code
|
|
12
|
+
self.detail = detail
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
return f"[{self.status_code}] {super().__str__()} | detail={self.detail}"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# 向后兼容别名
|
|
19
|
+
FreelyBaseError = FreelyBaseException
|