Skip to main content

PyWica - Async Wica Python API

pipeline status coverage report

Table of Contents

Introduction

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

Installation

Install with pip

pip install asyncwica

Quick-start Guide

Here are some simple examples to get you started:

import asyncio
import time


async def simple_example():
    """A simple example of how to use AsyncWicaStream. Run it in main by uncommenting it! """

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

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

    async def stop_stream():
        await asyncio.sleep(10)
        print(await wica_stream.destroy())

    await asyncio.gather(run_stream(), stop_stream())

async def example_using_with():
    """ An example using the compound statement async with and another method to exit the event loop. Run it in main by uncommenting it!"""
    async with WicaStream(base_url="http://student08/ca/streams", channels=["MMAC3:STR:2"]) as stream:
        i:int = 0
        async for message in stream.subscribe():
            i+=1
            print(message)
            if i == 25:
                break

async def multistream_example():
    """ An example of how to run multiple streams at once using aiostream. Run it in main by uncommenting it! """
    from aiostream import stream
    streams = []
    async def run_streams():
        for _ in range(10):
            wica_stream = WicaStream(base_url="http://student08/ca/streams", channels=["MMAC3:STR:2"])
            streams.append(wica_stream)
            await wica_stream.create()

        print("Doing someting else before starting the stream...")
        await asyncio.sleep(5)

        subscribed_streams = []

        for wica_stream in streams:
            print(f"Subscribing to stream {wica_stream.id}")
            subscribed_streams.append(wica_stream.subscribe())


        combine = stream.merge(*subscribed_streams)
        async with combine.stream() as streamer:
            async for item in streamer:
                print(item)
                continue


    async def stop_streams():
        await asyncio.sleep(25)
        for wica_stream in streams:
            print(await wica_stream.destroy())


    await asyncio.gather(run_streams(), stop_streams())


async def main():
    #await simple_example()
    #await example_using_with()
    #await multistream_example()
    pass

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
  • Fully Async (blocking versions available in main branch)

Check out the wiki for more info!

Dependencies

Contribute

To contribute, simply clone the project. You can uses pip -r requirements.txt or the make file to set up 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 contract 'niklas.laufkoetter@psi.ch'

Metadata

Release files for asyncwica 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncwica 1.3.0
File Size Uploaded
asyncwica-1.3.0.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncwica 1.3.0
File Interpreter ABI Platform
asyncwica-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 54.1 kB

Release files / asyncwica-1.3.0.tar.gz

Download URL asyncwica-1.3.0.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
120b5cd7ee458ffa007081b5b38bdadbe8e6af7dcf91f57b81d0216c9fb8b046
BLAKE2b-256 checksum
How to use checksums
77e99f86b77f8e3013d1bb01fb8252bcc7ce6bc4e4ebf96c0bc8a7faf76901bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.11.1 Linux/3.10.0-1160.71.1.el7.x86_64

Release files / asyncwica-1.3.0-py3-none-any.whl

Download URL asyncwica-1.3.0-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61ec416edd8ca92a5641e470487eb24440c0f810bc00ffecd7089eda17527204
BLAKE2b-256 checksum
How to use checksums
4dad11701c28e94fb42f9d78fa820af1f461b65cf5ca12d7bad129faeae2700e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.11.1 Linux/3.10.0-1160.71.1.el7.x86_64

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page