Skip to main content

Ice Rule Engine Python SDK

Project description

Ice Python SDK

Ice 规则引擎的 Python 实现,与 Java ice-core 和 Go SDK 功能一致。

安装

pip install ice-rules

快速开始

1. 注册叶子节点

import ice
from ice import Roam

@ice.leaf("com.example.ScoreFlow")
class ScoreFlow:
    threshold: int = 0
    
    def do_roam_flow(self, roam: Roam) -> bool:
        return roam.get_int("score", 0) >= self.threshold

2. 启动客户端

# 同步方式
client = ice.FileClient(app=1, storage_path="./ice-data")
client.start()

pack = ice.Pack(ice_id=1)
pack.roam.put("score", 85)
results = ice.sync_process(pack)

client.destroy()

3. 异步方式

import asyncio

async def main():
    client = ice.AsyncFileClient(app=1, storage_path="./ice-data")
    await client.start()
    
    pack = ice.Pack(ice_id=1)
    pack.roam.put("score", 85)
    results = await ice.async_process(pack)
    
    await client.destroy()

asyncio.run(main())

叶子节点类型

Flow 类型(返回 True/False)

  • do_flow(ctx: Context) -> bool
  • do_pack_flow(pack: Pack) -> bool
  • do_roam_flow(roam: Roam) -> bool

Result 类型(返回 True/False)

  • do_result(ctx: Context) -> bool
  • do_pack_result(pack: Pack) -> bool
  • do_roam_result(roam: Roam) -> bool

None 类型(无返回值)

  • do_none(ctx: Context) -> None
  • do_pack_none(pack: Pack) -> None
  • do_roam_none(roam: Roam) -> None

版本要求

  • Python >= 3.11

License

Apache-2.0

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

ice_rules-2.1.3.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

ice_rules-2.1.3-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file ice_rules-2.1.3.tar.gz.

File metadata

  • Download URL: ice_rules-2.1.3.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ice_rules-2.1.3.tar.gz
Algorithm Hash digest
SHA256 4195e88f45cef6ed6a5868e067bc82896627f94d9bc50b6463dd317bd87f8a9c
MD5 5a865bb49cb99fa07e4828be8c160842
BLAKE2b-256 8bf6c08c9728c6918b32a0c5635a846bf3982b8201264e49e8f4c4cbcac0150b

See more details on using hashes here.

File details

Details for the file ice_rules-2.1.3-py3-none-any.whl.

File metadata

  • Download URL: ice_rules-2.1.3-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ice_rules-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b942672bb82ae3b54ef5a0de6b8b396d556a498b357d796f6e12001fa52f9ff
MD5 512942f5a29318d6bbbd29a60ee27fc0
BLAKE2b-256 f3fe2983ccccc30cc8adfc455410217da13c638757b33c404c79a77f7c77c6d3

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