Skip to the content.

More detail on publishing streams using Python. See publish for alternatives.

Publishing using Python

pip install microprediction

BYO scheduling

If you are happy scheduling things yourself by whatever means, just use MicroWriter.set() to publish.

from microprediction import MicroWriter
mw = MicroWriter(write_key='YOUR WRITE KEY HERE')
mw.set(name='my_stream.json',value=3.14157) 

MicroPoll

Alternatively, use MicroPoll as illustrated by traffic_speed.py.

from microprediction.polling import MicroPoll
from microprediction.live.nyc_traffic import verrazano_speed
poller = MicroPoll(write_key='YOUR KEY HERE',
                     name='verrazano_speed.json',
                     func=verrazano_speed,
                     interval=15)
poller.run()

Here interval is in minutes. The argument func should be a function returning a float, and you can supply func_args if needed.

MicroChangePoll

It often pays to publish changes to live quantities, rather than absolute values, as this obviates the need for algorithms to precisely anticipate publishing times. The class MicroChangePoll can help and is illustrated by traffic_speed_changes.py. Note the suspension and resumption logic.

MultiChangePoll

See faang.py for an illustration of using slightly more advanced functionality provided in polling.py, including the use of a change_func to create streams that are functionals of changes in values.

After you publish

Video tutorials

Reminder: write keys

You can use a colab notebook to burn a new WRITE_KEY.

-+-

Documentation map