Skip to main content

Kenger Service Python SDK

Project description

KengerKit

Kenger Service Python SDK,用于与 kenger-service 进行交互。

安装

pip install kengerkit

或从源码安装:

git clone https://github.com/xiaoyu-ai/kengerkit.git
cd kengerkit
pip install -e .

快速开始

from kengerkit import KengerClient

# 初始化客户端
client = KengerClient(
    base_url="https://your-kenger-service.com",
    token="your_api_token"
)

# 获取配置
value = client.config.get("my_key")
print(value)

# 设置配置
client.config.set("new_key", "new_value", value_type="str", description="描述")

# 更新配置(通过 key)
client.config.update_by_key("new_key", value="updated_value")

# 设置或更新(存在则更新,不存在则新增)
client.config.set_or_update("some_key", "some_value")

# 删除配置
client.config.delete_by_key("new_key")

配置管理

获取配置

# 获取配置值
value = client.config.get("my_key")

# 获取配置详情(包含 id, key, value, value_type, description 等)
detail = client.config.get_detail("my_key")

设置配置

# 支持的 value_type: str, int, float, bool, json
client.config.set("key", "value", value_type="str", description="描述")

# JSON 类型
client.config.set("json_key", {"foo": "bar"}, value_type="json")

更新配置

# 通过 ID 更新
client.config.update(config_id=1, value="new_value")

# 通过 key 更新
client.config.update_by_key("my_key", value="new_value")

# 设置或更新(推荐)
client.config.set_or_update("key", "value")

删除配置

# 通过 ID 删除
client.config.delete(config_id=1)

# 通过 key 删除
client.config.delete_by_key("my_key")

列表和搜索

# 分页获取列表
result = client.config.list(page=1, page_size=10)
# result = {"items": [...], "total": 100, "page": 1, "page_size": 10}

# 模糊搜索
result = client.config.search("keyword", page=1, page_size=10)

邮件发送

# 初始化时设置 email_token
client = KengerClient(
    base_url="https://your-service.com",
    token="api_token",
    email_token="email_token"
)

# 发送邮件
client.email.send(
    to="recipient@example.com",
    title="邮件主题",
    content="<h1>HTML 内容</h1>",
    is_html=True
)

# 或在发送时传入 token
client.email.send(
    to="recipient@example.com",
    title="邮件主题",
    content="纯文本内容",
    is_html=False,
    token="email_token"
)

# 带附件
client.email.send(
    to="recipient@example.com",
    title="邮件主题",
    content="请查收附件",
    attachments=[{"path": "/path/to/file.pdf", "name": "文件.pdf"}]
)

异常处理

from kengerkit import (
    KengerClient,
    KengerKitError,
    AuthenticationError,
    ValidationError,
    NotFoundError,
    ServerError,
)

client = KengerClient(base_url, token)

try:
    client.config.set("key", "value")
except AuthenticationError:
    print("认证失败,请检查 token")
except ValidationError as e:
    print(f"参数错误: {e.message}")
except ServerError as e:
    print(f"服务端错误: {e.message}")
except KengerKitError as e:
    print(f"其他错误: {e.message}")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kengerkit-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kengerkit-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file kengerkit-0.1.0.tar.gz.

File metadata

  • Download URL: kengerkit-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for kengerkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29a2fbec4c97633ab2709d852827cf5f5f8600d956eb2fe07bbaba192ce70358
MD5 cf701dfe2e15f576d49c6fe996a787ab
BLAKE2b-256 2afe220527077664b2375b1239f644cfe63144f00a14619340af82047f70ddff

See more details on using hashes here.

File details

Details for the file kengerkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kengerkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for kengerkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90c7aa258477439852516dd34ce7e1ea457b03b59bd714f1c2a367d2a53df4a5
MD5 64d3d2d7f82ca3579ffd89da7dbb7ba5
BLAKE2b-256 1dfa35dc7b5662d3827d9fd4e350dd0fecd479de06c20def91ba907dc0641c52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page