Athena Kit
Athena Kit 是 Athena 项目使用的模块化 Python 工具包。
它发布为一个 Python 包:athena-kit,并提供统一的 Python 命名空间:athena_kit。
安装
uv add athena-kit
uv add "athena-kit[http]"
uv add "athena-kit[lark]"
uv add "athena-kit[matplotlib]"
uv add "athena-kit[dataframe]"
uv add "athena-kit[all]"
Usage
athena http
athena_kit.http 基于 HTTPX 做薄封装,提供同步/异步客户端、常用 event hooks、JSON 响应提取和简单重试工具。
同步请求:
from athena_kit.http import HttpClient
with HttpClient(base_url="https://api.example.test", request_id=True) as client:
response = client.get("/items")
response.raise_for_status()
异步请求:
from athena_kit.http import AsyncHttpClient
async with AsyncHttpClient(base_url="https://api.example.test", request_id=True) as client:
response = await client.get("/items")
response.raise_for_status()
启用请求 ID、日志和响应状态检查:
from athena_kit.http import HttpClient
with HttpClient(
base_url="https://api.example.test",
request_id=True,
logging=True,
response_status=True,
) as client:
response = client.get("/items")
提取 JSON 响应中的业务数据:
from athena_kit.http import create_biz_code_validator, extract_response_json_value
data = extract_response_json_value(
response,
"data.items[0]",
validator=create_biz_code_validator(code_key="code", success_codes=(0,)),
)
为请求增加简单重试:
import httpx
from athena_kit.http import RetryOptions, retry
response = retry(
request=lambda: client.get("/items"),
options=RetryOptions(attempts=3, initial_delay=0.2, multiplier=2.0, jitter=0.1, logger=True),
should_retry_result=lambda response: response.status_code in {429, 500, 502, 503, 504},
should_retry_exception=lambda exc: isinstance(exc, httpx.TimeoutException),
)
更多 HTTP 使用案例见 docs/athena_http.md。
athena tabular
athena_kit.core.tabular 提供二维表格模型、单元格序列化、pandas DataFrame 转换,以及同步/异步表格后端和仓储抽象。
定义一行表格模型:
from datetime import date
from athena_kit.core.tabular import TableCell, TableRow
class TradeRow(TableRow):
trade_date: date = TableCell(title="日期", order=1)
symbol: str = TableCell(title="代码", order=2)
amount: int = TableCell(title="成交额", order=3)
模型和二维表格行互相转换:
row = TradeRow(trade_date=date(2026, 6, 11), symbol="000001", amount=1200)
assert TradeRow.table_headers() == ["日期", "代码", "成交额"]
assert row.to_table_row() == ["2026-06-11", "000001", 1200]
使用 repository 接入具体二维表格后端:
from athena_kit.core.tabular import TableRepository
repository = TableRepository(backend, locator, TradeRow)
rows = repository.list_all()
更多 Tabular 使用案例见 docs/athena_tabular.md。
athena lark
athena_kit.lark 提供飞书开放平台异步客户端。当前重点支持 Sheets,包括创建电子表格、批量新增工作表、读写单个工作表范围,以及接入 core.tabular 的异步表格后端。
创建飞书客户端并新增电子表格:
from athena_kit.lark import AsyncLarkClient
async with AsyncLarkClient(app_id="cli_xxx", app_secret="xxx", response_status=True) as client:
spreadsheet_token, url = await client.sheets.create_spreadsheet(
folder_token="fldcn_xxx",
title="交易汇总",
)
写入飞书工作表:
revision, updated_rows, updated_columns = await client.sheets.overwrite_values(
spreadsheet_token=spreadsheet_token,
sheet_id="sheet_xxx",
headers=["日期", "代码", "成交额"],
rows_values=[["2026-06-11", "000001", 1200]],
start_row=1,
)
接入异步表格仓储:
from athena_kit.core.tabular import AsyncTableRepository
from athena_kit.lark.sheets import AsyncLarkSheetsBackend, LarkSheetsLocator
backend = AsyncLarkSheetsBackend(client.sheets)
locator = LarkSheetsLocator(spreadsheet_token=spreadsheet_token, sheet_id="sheet_xxx")
repository = AsyncTableRepository(backend, locator, TradeRow)
rows = await repository.list_all()
更多 Lark Sheets 使用案例见 docs/athena_lark.md。
模块结构
athena_kit.core:基础模型、时间编解码、表格和通用值处理工具。athena_kit.http:基于 HTTPX 的同步/异步 HTTP 工具。athena_kit.lark:飞书开放平台异步客户端和 Sheets 工具。athena_kit.matplotlib:声明式图表渲染工具。
开发
uv sync --extra all
uv run ruff check src tests examples
uv run ruff format --check src tests examples
uv run pytest tests
发布到 PyPI
发布前确认版本号已经更新,并且 pyproject.toml 和 src/athena_kit/__init__.py 中的版本一致。
uv sync --extra all
uv run ruff check src tests examples
uv run ruff format --check src tests examples
uv run pytest tests
rm -rf dist
uv build
uv publish
如果是第一次发布,先在 PyPI 创建 API Token,然后按 uv publish 的提示输入 token;也可以提前设置环境变量:
export UV_PUBLISH_TOKEN="pypi-..."
uv publish
发布完成后,在其他项目中安装:
uv add athena-kit
Metadata
Release files for athena-kit 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| athena_kit-1.1.1.tar.gz | 84.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| athena_kit-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 241.5 kB
Release files / athena_kit-1.1.1.tar.gz
| Download URL | athena_kit-1.1.1.tar.gz |
|---|---|
| Size | 84.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35691026e38ce8dd02ccf9fe0a3b2ab0452ed48a78f28dc89165f8debad5bc08
|
|
BLAKE2b-256 checksum How to use checksums |
0a35e758083c05d945f83de789618f7c2c29a9524e54fd135e8ac4199f5bf66a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|
Release files / athena_kit-1.1.1-py3-none-any.whl
| Download URL | athena_kit-1.1.1-py3-none-any.whl |
|---|---|
| Size | 156.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f4da91a108cc596c18d8ea3d7da43dd737d187e1ec928eedfb77a5a0522ad36
|
|
BLAKE2b-256 checksum How to use checksums |
9e706b1b9bb185fb88072367b0d0d5842d3686e533fa11eeef1a379e5fee6abc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|
Security for athena-kit 1.1.1
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.