Excel RTD servers, in Python

Receive real-time data from RTD (RealTimeData) servers in any Python program, without Excel. The same engine that powers calc-rtd for LibreOffice Calc, usable on its own.

pip install calc-rtd
Free, MIT license. Windows for real RTD servers; the simulated source runs anywhere. Python 3.9+.
from calc_rtd import RtdSession

with RtdSession() as rtd:
    rtd.subscribe("Vendor.ProgID", ["ACME", "LAST"])
    for update in rtd.updates():
        print(update.value)

Three ways to receive data

Pick the one that fits your program. They can be mixed in the same session.

  1. Iterate over updates

    A loop that gets every change as it arrives.

    for update in rtd.updates(timeout=30):
        if update.error:
            print("problem:", update.error)
        else:
            print(update.value)
  2. Read the latest value

    Each subscription keeps its most recent value.

    acme = rtd.subscribe("calcrtd.sim", ["walk", "ACME", 38.5])
    acme.wait(timeout=10)      # first value
    print(acme.value)          # always the latest
  3. Callbacks

    A function called for every update of one topic.

    def on_price(update):
        if update.value > 40:
            print("ACME above 40:", update.value)
    
    rtd.subscribe("calcrtd.sim", ["walk", "ACME", 38.5],
                  callback=on_price)
    rtd.run_for(60)

Try it without any RTD server

The ProgID calcrtd.sim is a simulated source built into the library: a clock, counters, random numbers and random walks. Every example uses it by default, so you can run them on any machine, then switch to your vendor's ProgID and topics.

rtd.subscribe("calcrtd.sim", ["clock"])

Check a server from the command line

Paste a formula that works in Excel. It prints every update and exits with code 0 if any arrived:

python -m calc_rtd "=RTD(Vendor.ProgID;;ACME;LAST)" --seconds 30

Recipes

Complete scripts, run by the project's tests on every commit.

print_updates.pyPrint every update of formulas given on the command line.
log_to_csv.pyAppend time, topic and value to a CSV file.
latest_values.pyPoll the latest values once a second.
alert_callback.pyReact to a value with a callback.
to_pandas.pyCollect updates into a pandas DataFrame, one row per second.

Good to know

  • Windows and bitness. RTD servers are COM components. When the server is a DLL, use a Python with the same bitness (32/64-bit) as the Excel it was installed for.
  • Not elevated. Run your program at the same privilege level as the application that feeds the RTD server.
  • Threads. A session runs the servers on its own background thread, so you can use it from any thread of your program.
  • Some servers only accept Excel. Vendors may tie their RTD server to their own Excel add-in.
  • Your data vendor's terms of use still apply. Taking data out of a terminal into your own programs is often more restricted than displaying it in a spreadsheet.