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.0.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.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kengerkit-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 faf0bee5792531c2ace1357e2c61dc68b2b865470f2988d7f8959c4a8a34fbf8
MD5 444a692e09ff1b643e5e6e703fef945a
BLAKE2b-256 56f04713fc88f56c70455d2f74ba1fea0108a7f820a394d2ceb07a79b14d2a7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kengerkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abf290baa37cd59d565191408014325d1f93ea39f1f78ec900e06a1317b4966c
MD5 66335218c90257977e48460ce472b748
BLAKE2b-256 13c0a63fecdfbebdddfa67d861c0ee28b3539afeab5d0170e3e7d62acafb8725

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