Echo流服务器API客户端

python-echo-streamserver的Python项目详细描述


这是echo streamserver api的python版本。请参阅echoDevelopers文档。

功能接口

函数接口提供每个api作为一个简单的modulepackage包。api使用default帐户联系echo。例如,items apiecho.items并具有rest api方法。

>>> # Items API: Count EQL Query
>>> from echo import items, StreamServerError
>>> try:
>>>     n = items.count("scope:http//example.com/\*")
>>>     print "EQL Count: %d" % n
>>> except StreamServerError, e:
>>>     print "Error: %s" % str(e)

默认帐户

默认帐户echo.settings模块的一部分。在那里设置echoappkeysecretapi\u键。

::
/usr/lib/python2.x/site packages/echo/settings.py

客户端接口

client接口将每个api作为类instance提供。client使用一个account对象来联系echo,或默认值。例如,key-value store apiecho.kvs.client并具有kvs api方法。

>>> # KVS Client API: Get a value for the key 'sample'.
>>> from echo import kvs, StreamServerError
>>> # Create a KVS client using the default account.
>>> client = kvs.Client()
>>> try:
>>>     v = client.get('sample')
>>>     print "KVS: %r" % v
>>> except StreamServerError, e:
>>>     print "Error: %s" % str(e)

帐户对象

每个clientinstance都可以使用account对象来联系echo。这是支持multipleecho帐户所必需的。

>>> from echo import feeds, Account
>>> # Non-default account: Login Account.BasicAuth with no secret
>>> other_account = Account('test.echoenabled.com', '', Account.BasicAuth)
>>> client = feeds.Client(account=other_account)

mux请求

items api支持muxmultiplexed请求。几个countsearch请求可以组合成一个rest调用。items.mux方法将muxrequest对象的列表发送到echo。有关输出格式,请参阅echomux方法文档。

>>> from echo import items
>>> from echo.items.mux_api import MuxRequest
>>> # EQL Query String
>>> query_eql = "scope:http://www.example.com/\*"
>>> # Search Query (default)
>>> search = MuxRequest(query_eql)
>>> # Count Query
>>> count = MuxRequest(query_eql, api_method='count')
>>> # Form list of them for Mux API.
>>> requests = [ search, count ]
>>> # Send Mux API requests.
>>> r = items.mux(requests)

回声查询语言生成器

有一个object-orientedecho查询语言api来构建查询字符串。可以将echo.eql.query对象传递给items api方法eql.items.counteql.items.search而不是查询文本。添加echo.eql.filters以基于查询项生成完整的EQL查询字符串。

eql语法限制

eql生成器不能保证整个eql文本有效。每个term单独有效,但echo streamserver仍可能拒绝eql字符串。eql语法规则限制如何构造query及其filters。打印echo.eql.query对象以检查其查询字符串,并根据需要检查reorder筛选条件。

查询方法api

使用方法调用构建一个echo.eql.query对象。添加echo.eql.filters.queryfilter对象以限制结果。大多数queryfilter对象可以negated来排除该术语。

>>> from echo import eql
>>> q = eql.Query("http://site.example.com/index.html", uri_filter='url')
>>> q.add_filter(eql.filters.ChildrenDepth(3))
>>> q.add_filter(eql.filters.TypeFilter('article'), negate=True)
>>> print "EQL> ", q
EQL> "url:"http://site.example.com/index.html" children:3 -type:article"

查询运算符api

使用布尔运算符将filters添加到echo.eql.query对象。有关详细信息,请阅读echo.eql.filters文档。

>>> from echo import eql
>>> q = eql.Query("http://www.example.com/movies//")
>>> # Exclude articles and notes with (-).
>>> q = q - eql.filters.TypeFilter(['article', 'note'])
>>> # Allow children up to depth 2.
>>> q + (eql.filters.ChildrenDepth(2))
echo.eql.Query Operators
operatorexampledescription
plus +q + rAdd filter r to query q.
minus -q - rNegate filter r on query q.
and &q1 & q2Combine queries q1 and q2.
pipe |q1 | q2Select query q1 or q2.
echo.eql.filters Operators
operatorexampledescription
minus --rNegate filter r.
and &r1 & r2Combine filters r1 and r2.
pipe |r1 | r2Apply filter r1 or r2.

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

推荐PyPI第三方库


热门话题
反射Java getMethod()会导致NoSuchMethodException错误   编译器构造Java编译时错误:解析时到达文件末尾   java我无法使用Spring Boot从应用程序引擎中的服务连接到Google数据存储   java单一注销配置文件Idp注销问题   regex如何在java中编写和使用正则表达式   java Android:单击标签打开电子邮件应用程序   java如何确保函数执行函数的整个检查?   java如何将字母数字电话号码转换为数字   listview更改中项目内部的java ImageView   java将空对象转换为整数   对等端重置java Google Drive SDk连接   在java程序中测试未授权的隐藏测试(代码战)