Merge branch '15888-remove-py2-from-test' into master
[arvados.git] / doc / sdk / python / events.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Python
5 title: Subscribing to database events
6 ...
7 {% comment %}
8 Copyright (C) The Arvados Authors. All rights reserved.
9
10 SPDX-License-Identifier: CC-BY-SA-3.0
11 {% endcomment %}
12
13 Arvados applications can subscribe to a live event stream from the database.  Events are described in the "Log resource.":{{site.baseurl}}/api/methods/logs.html
14
15 {% codeblock as python %}
16 #!/usr/bin/env python3
17
18 import arvados
19 import arvados.events
20
21 # 'ev' is a dict containing the log table record describing the change.
22 def on_message(ev):
23     if ev.get("event_type") == "create" and ev.get("object_kind") == "arvados#collection":
24         print "A new collection was created: %s" % ev["object_uuid"]
25
26 api = arvados.api("v1")
27 ws = arvados.events.subscribe(api, [], on_message)
28 ws.run_forever()
29 {% endcodeblock %}