Package: python-echo-streamserver
This is a Python version of theEcho StreamServer API. See the EchoDevelopersDocumentation.Function InterfaceThefunctioninterface provides eachAPIas a simplemoduleorpackage. TheAPIuses theDefault Accountto contactEcho. For example, theItems APIisecho.itemsand has theREST APImethods.>>> # 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)Default AccountTheDefault Accountis part of theecho.settingsmodule. Set theEchoappkeyandsecretAPI_Keys there.::/usr/lib/python2.x/site-packages/echo/settings.pyClient InterfaceTheClientinterface provides eachAPIas a classinstance. TheClientuses anAccountobject to contactEcho, or the default. For example, theKey-Value Store APIisecho.kvs.Clientand has theKVS APImethods.>>> # 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)Account ObjectsEachClientinstancecan use anAccountobject to contactEcho. This is required to supportmultipleEchoaccounts.>>> 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 RequestsTheItems APIsupportsMUX, ormultiplexedrequests. Severalcountandsearchrequests can be combined into oneRESTcall. Theitems.muxmethod sends a list ofMuxRequestobjects toEcho. See theEchomuxmethod documentation for the output format.>>> 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)Echo Query Language BuilderThere is anobject-orientedEcho Query Language APIto build query strings. Anecho.eql.Queryobject may be passed to theItems APImethodseql.items.countandeql.items.searchrather than query text. Addecho.eql.filtersto build on the query terms and produce a completeEQLquery string.EQL Syntax LimitationsThisEQL Builderdoes not guaranteethat thewholeEQL text is valid. Eachtermis valid alone butEcho StreamServerstill may reject the EQL string.EQL syntaxrules limit how aQueryand itsfilterscan be constructed. Print theecho.eql.Queryobject to inspect its query string andreorderfilter terms as necessary.Query Method APIBuild anecho.eql.Queryobject using method calls. Addecho.eql.filters.QueryFilterobjects to limit the results. MostQueryFilterobjects can benegatedto exclude the term.>>> 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"Query Operator APIAddfiltersto anecho.eql.Queryobject using boolean operators. Read theecho.eql.filtersdocumentation for more details.>>> 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 Operatorsoperatorexampledescriptionplus +q + rAddfilter r to query q.minus -q - rNegatefilter r on query q.and &q1 & q2Combine queries q1andq2.pipe |q1 | q2Select query q1orq2.echo.eql.filters Operatorsoperatorexampledescriptionminus --rNegatefilter r.and &r1 & r2Combine filters r1andr2.pipe |r1 | r2Apply filter r1orr2.