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.2.1.tar.gz (9.3 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.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kengerkit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0fd61a5f46bd335a6202deecf018806a4ccd37193e34eda398dce1538a51db9a
MD5 f55185a973a736e232fb5d281b53849e
BLAKE2b-256 6f034d58fab9d254e94bd299d7dc0fe06960b94142ec51b1eda28277c08439e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kengerkit-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf838e5c817b67b641dff09d186657dc573d6b7bb4384b2cc9f32e404f654664
MD5 a980a642fcdcf7f8d1a74039a80d0c9d
BLAKE2b-256 c852efe733abb64a699225a8c1fc4da52f0abf3073dbc300c16059cf6e8c9e79

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