farspec
farspec 是一个纯 Python 的任务协议规范包:提供 Request/Response/Task 基类,
以及 dataclass ↔ dict(JSON 友好)的通用序列化工具,方便在不同服务/任务系统之间
约定统一的输入输出结构。不依赖网络、数据库或云服务。
特性
BaseRequest:请求基类,自动生成request_id,meta承载版本/追踪等横切信息BaseResponse:响应基类,内置status/events/耗时统计与成功/失败标记方法BaseTask:模板方法基类,run()统一处理开始/结束时间戳、事件记录与异常捕获to_jsonable/from_jsonable/dataclass_to_dict/dataclass_from_dict:通用的 dataclass ↔ JSON 友好 dict 转换工具,支持X | None、list、dict、Enum、datetime、嵌套 dataclass
环境要求
- Python 3.10 或更高版本
安装
pip install farspec
本地开发用可编辑安装:
git clone https://github.com/farfarfun/farspec.git
cd farspec
pip install -e .
快速开始
from farspec.task import BaseRequest, BaseResponse, BaseTask
class EchoTask(BaseTask[BaseRequest, BaseResponse]):
def build_response(self) -> BaseResponse:
return BaseResponse()
def execute(self, response: BaseResponse, *args, **kwargs) -> BaseResponse:
response.add_event("echo", "doing work")
response.mark_succeeded(payload={"echoed": True})
return response
task = EchoTask(BaseRequest(request_id="req-42"))
result = task.run()
print(result.status) # TaskStatus.SUCCEEDED
print(result.payload) # {'echoed': True}
print(result.to_dict()) # JSON 友好 dict,可直接 json.dumps
开发
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pytest tests/ -v
许可证
本项目使用 MIT License。
关于 farfarfun
farfarfun 是一个专注于实用工具库的开源组织, 涵盖云存储、数据处理、AI、多媒体与开发工具链等方向。
- 🏠 组织主页:https://github.com/farfarfun
- 📦 PyPI:https://pypi.org/user/niuliangtao/
- 📧 联系:farfarfun@qq.com
本项目基于 MIT 协议开源。
Metadata
Release files for farspec 1.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| farspec-1.0.12-py3-none-any.whl | Python 3 | none | any | Details for farspec-1.0.12-py3-none-any.whl |
Release files / farspec-1.0.12-py3-none-any.whl
| Download URL | farspec-1.0.12-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66f0ba442d9419b0683c4b31160c8b78de59b73b3e67923fed8623aa4d8f4aa0
|
|
BLAKE2b-256 checksum How to use checksums |
0d24c161c4720d3a216b877093b575c11e5d067543e07ec97a63d23e3935ebea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for farspec 1.0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.