======================================== Using Python with LiveView REST API ======================================== This sample demonstrates the LiveView REST API using simple Python scripts. The sample Python code is designed to be run from a console terminal, while the Hello LiveView sample is assumed to be running on the default port. These Python samples illustrate different features of the LiveView REST API: lvlisttables.py Lists all tables, or optionally all information about a given table, in the LDM. lvsnapquery.py Performs snapshot queries. lvlivequery.py Performs live queries. lvpublish.py Takes input from the console and publishes it to a table. Each sample has help available by suppling the option "--help" The Python samples all use the Python package "requests". The live query sample additionally uses "sseclient-py". One way to get these packages is: pip install --user Load this sample into Studio as described in the topic, "Loading LiveView Samples into Studio Workspace". From StreamBase Studio on Windows, go to the Help menu > Help Contents > TIBCO LiveView Documentation > Start Here > Getting Started with LiveView Server. On Linux, load the following path into your web browser: /opt/tibco/sb-cep/n.m/doc/lvindex.html Then open the Start Here document from the home page link. Also load the Hello LiveView sample into Studio. This sample provides a simple instance of LiveView where the primary data table, ItemsSales, is automatically filled with a feed simulation. To use the Python samples, first run the Hello LiveView sample. Follow these steps: 1. If you have run the Hello LiveView sample before, and have changed the port on which the sample runs, change it back to the default port, 10000. 2. To start the Hello LiveView server in Studio, you can: - In the LiveView Project Viewer, click the green Run button in the upper right. - Right-click any of the lvconf table configuration files in the Package Explorer view, or right-click the project folder itself, and select Run As > LiveView Project. Wait for a message in the Console view that begins "All tables have been loaded..." 3. In Studio, select the sample_lv-Python project and right click. Select "StreamBase -> Open StreamBase Command Prompt Here". In that console, type: Python lvlisttables.py Found 10 tables: LVTables - Information about Tables including description, capabilities, and table space LVTableColumns - Table Column information including field names, types and descriptions ItemsInventory - Live view of total inventory dollar exposure at current pricing, aggregated by category ItemsSales - Live view of all items sold over time, quantity in stock and the last sold price LVAlerts - Default LiveView Alerts table that Alert Rule Publish Actions populate LiveViewStatistics - LiveView table statistics LVSessions - Session information including remote host, recent activity LVSessionQueries - Session Query information including predicate and performance information LVSessionPublishers - Session Publisher information including table and performance information LVAlertRulesStatus - Recent alert rules status table Next try: $ Python lvsnapquery.py -t ItemsSales begin_snapshot: category, quantityRemaining, Item, lastSoldPrice, transactionTime, transactionID Add: [u'electronics', 420, u'Earphones', 14.0, 1502820473231L, 8734] Add: [u'electronics', 66, u'Cellphone', 90.0, 1502820474231L, 8735] . . . Add: [u'clothes', 16, u'Leather Jacket', 30.0, 1502820719298L, 8980] Add: [u'clothes', 15, u'Dress Shoe', 31.0, 1502820720299L, 8981] end_snapshot Found 248 rows You can also supply a LiveQL query: Python lvsnapquery.py -t ItemsSales -q "select count() as Total,category from ItemsSales group by category" begin_snapshot: category, Total Add: [u'electronics', 56] Add: [u'book', 53] Add: [u'automotive', 49] Add: [u'clothes', 80] Add: [u'toy', 60] end_snapshot Found 5 rows Try with lvlivequery.py Python lvlivequery.py -t ItemsSales begin_snapshot: category, quantityRemaining, Item, lastSoldPrice, transactionTime, transactionID add: [u'electronics', 0, u'Music Player', 45.0, 1502821373475L, 9634] add: [u'automotive', 131, u'Fuzzy Dice', 20.0, 1502821374475L, 9635] . . . add: [u'clothes', 12, u'Prom Dress', 51.0, 1502821654567L, 9915] add: [u'book', 100, u'Oliver Twist', 9.0, 1502821655568L, 9916] {u'type': u'end_snapshot'} add: [u'electronics', 180, u'Charger', 12.0, 1502821656568L, 9917] add: [u'electronics', 400, u'Earphones', 16.0, 1502821657568L, 9918] . . .