管理primedio的python客户端

pyprimed的Python项目详细描述


pyprimed:管理primedio的python库

创建一个个性化的web应用程序,它是唯一的,并且与每个使用Primed.io的用户都相关。

安装

pip install pyprimed

快速启动

导入sdk并启动连接

frompyprimed.pioimportPiopio=Pio(uri='http://<user>:<password>@<api_url>:<port>')

创建一个宇宙,并附加几个目标

# create a new universe and attach a single targetpio\
  .universes\
  .create(name='myfirstuniverse')\
  .targets\
  .upsert([{'key':'ARTICLE-1','value':{'url':'www.example.com/article-1'}}])# retrieving the newly created universeu=pio.universes.filter(name='myfirstuniverse').first# list all targets currently associated with this universefortargetinu.targets.all():print(target.key,target.created_at)# prepare a list of new targetsnew_targets=[{'key':'ARTICLE-2','value':{'url':'www.example.com/article-2'}},{'key':'ARTICLE-3','value':{'url':'www.example.com/article-3'}}]# upsert the new targetsu.targets.upsert(new_targets)# targets are upserted, which means that for a given key there# can be only one instance in the database. Trying to create an# instance with the same key will update the value of the record# in the databaseu.targets.upsert([{'key':'ARTICLE-1','value':{'url':'THIS IS NEW!'}}])u.targets.filter(key='ARTICLE-1').first.value

创建一个模型,并附加一些信号

# create a new model and attach a single signalpio\
  .models\
  .create(name='myfirstmodel')\
  .signals\
  .upsert([{'key':'ALICE'}])# retrieving the created modelm=pio.models.filter(name='myfirstmodel').first# list all signals currently associated with this modelforsignalinm.signals.all():print(signal.key,signal.created_at)# prepare a list of new signalsnew_signals=[{'key':'BOB'},{'key':'CHRIS'}]# create the new signalsm.signals.upsert(new_signals)# prepare a set of predictions (sk stand for signal.key, and tk for target.key)# WARNING: `sk` and `tk` should always be a string!predictions=[{'sk':'ALICE','tk':'ARTICLE-1','score':0.35},{'sk':'BOB','tk':'ARTICLE-1','score':0.75},{'sk':'CHRIS','tk':'ARTICLE-1','score':0.15}]# create the new predictions u=pio.universes.filter(name='myfirstuniverse').firstpio\
    .predictions\
    .on(model=m,universe=u)\
    .upsert(predictions,asynchronous=False)# the `asynchronous=False` settings waits for this operation to end before # continuing

创建一个活动,实验并设置ab测试,开始使用预测

frompyprimed.models.abvariantimportCustomAbvariant,RandomControlAbvariant,NullControlAbvariant# we create a custom abvariant that blends models m1 and m2 using a 60%/40% weight ratioab0=CustomAbvariant(label='A',models={m1:0.6,m2:0.4})ab1=RandomControlAbvariant(label='B')ab2=NullControlAbvariant(label='C')# we attach the abvariants to the experiment# `ab0` will receive 80% of traffic, `ab1` and `ab2`# receive 10% eache.abvariants.create({ab0:0.8,ab1:0.1,ab2:0.1})res=c.personalise(pubkey='mypubkey',secretkey='mysecretkey',signals={'userid':'BOB'},abvariant='A')# abvariant with label 'A' will be returned

更新实验

frompyprimed.models.abvariantimportCustomAbvariant,RandomControlAbvariant,NullControlAbvariant# obtain existing experimente=c.experiments.filter(name="myexperiment").first()# change propertye.salt="new_salt"e.update()# update abvariantsab1=CustomAbvariant(label="NEWLABEL",{m1:0.33,m2:0.77})ab2=RandomControlAbvariant(label="NEWRANDOMCONTROL")e.abvariants.update({ab1:0.5,ab2:0.5})

显影剂

制作文档:

cd docs && pydocmd build

预览有关http://localhost:8000

的文档
cd docs && pydocmd serve

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
图像处理Java 8 ImageIO在Linux中无法正确读取JPEG   spring如何用Java 1.4兼容版本替换@Resource注释   java Http请求参数类型传播   在web浏览器中看不到Java Maven Tomcatplugin web应用程序   jvm在Java中使用直接内存的目的是什么?   如何从列表转换为字符串java   java setAdapter gridview发送上下文   SwingJava。方法上的lang.NullPointerException   java什么是shell脚本、makefile和ant文件   当使用getGraphics()方法时,java JPanel图形会闪烁   java如何将迭代转换为递归?   java为什么我的抽屉菜单在同一个XML上有ConstraintLayout时没有响应?   java如何在图像上画一个圆?   Android studio:Rabbitmq:Error:java。lang.ClassNotFoundException:类io。千分尺。果心仪器找不到仪表注册表