跳转到主要内容

未提供项目描述

项目描述

heksher for python的SDK

这是一个用于在Python中使用的heksher服务器的库。兼容Python 3.7、3.8和3.9。该库包含异步客户端和基于线程的客户端。还包括存根客户端,以便在没有服务的情况下进行测试。

示例用法

# main.py
from contextvars import ContextVar
from heksher import AsyncHeksherClient, Setting

user = ContextVar('user', default='guest')

class App:
    ...
    
    async def startup(self):
        ...
        
        # initialize the client, and set it as the process' main client
        self.heksher_client = AsyncHeksherClient('http://heksher.service.url',
                                            update_interval=60, 
                                            context_features=['user', 'trust', 'theme'])
        # set certain context features to be retrieved either from string constants or
        # context variables 
        self.heksher_client.set_defaults(user = user, theme="light")
        await self.heksher_client.set_as_main()
    
    async def shutdown(self):
        await self.heksher_client.close()        
        ...

cache_size_setting = Setting('cache_size', type=int, configurable_features=['user', 'trust'], default_value=10)
def foo(trust: str):
    ...
    # should be run after App.startup is completed
    cache_size = cache_size_setting.get(trust=trust)
    ...

基于线程的客户端用法几乎相同。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

heksher-0.2.2.tar.gz (18.9 kB 查看哈希值)

上传时间:

构建分布

heksher-0.2.2-py3-none-any.whl (23.8 kB 查看哈希值)

上传时间: Python 3

由以下支持