Skip to main content

A simple python API to access wica-http SSE.

Project description

PyWica - Wica Python API

coverage report pipeline status

Table of Contents

Introduction

This project/package aims to provide a simple python interface to the wica-http server. Check out the async branch to get the async version of the package

Installation

Install with pip

pip install wica

Quick-start Guide

import asyncio
import time

from wica import WicaStream


async def simple_example_blocking_io():
    """A simple example of how to use WicaStream.

    In this example we are using asyncio, but you could use any other concurrency or parallel processing package,
    you just need the ability to interrupt the stream somehow!
    Check out the async version of this package!
    """

    wica_stream = WicaStream(base_url="http://student08/ca/streams", channels=["MMAC3:STR:2"])

    def run_stream():
        wica_stream.create()
        for message in wica_stream.subscribe():
            print(message)

    def stop_stream():
        print("Starting to wait")
        time.sleep(5)
        print(wica_stream.destroy())

    # The following functions put the blocking functions into their own thread.
    async def thread_run_stream():
        return await asyncio.to_thread(run_stream)

    async def thread_stop_stream():
        return await asyncio.to_thread(stop_stream)

    return await asyncio.gather(thread_run_stream(), thread_stop_stream())

async def main():
    await simple_example_blocking_io()

if __name__ == "__main__":
    asyncio.run(main())

Documentation

Current Features:

  • Custom Client to handle be able to extract last line of SSE with timestamp and message type.
  • Simple functions to create, delete and subscribe to streams
  • Blocking IO (non-blocking versions available in async branch)

Check out the wiki for more info!

Dependencies

  • requests

Contribute

To contribute, simply clone the project.

Project Changes and Tagged Releases

  • See the Changelog file for further information
  • project releases are available in pypi

Developer Notes

Currently None

Contact

If you have any questions pleas contact 'niklas.laufkoetter@psi.ch'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wica-1.0.6.tar.gz (20.1 kB view hashes)

Uploaded Source

Built Distribution

wica-1.0.6-py3-none-any.whl (32.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page