A simple async python API to access wica-http SSE.
Project description
Py-Wica Async
Table of Contents
- Introduction
- Installation
- Quick-start Guid
- Documentation
- Dependencies
- Contribute
- Project Changes and Tagged Releases
- Developer Notes
- Contact
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
import asyncio
import time
from asyncwica import AsyncWicaStream
async def async_simple_example():
"""A simple example of how to use AsyncWicaStream. Run it in main by uncommenting it! """
wica_stream = AsyncWicaStream(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 async_multistream_example():
""" An example of how to run multiple streams at once.
Use aiostream to run it! Run it by uncommenting it in main.
"""
from aiostream import stream
streams = []
async def run_streams():
for _ in range(10):
wica_stream = AsyncWicaStream(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 async_simple_example()
#await async_multistream_example()
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 mor info!
Dependencies
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 contract 'niklas.laufkoetter@psi.ch'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncwica-1.0.1.tar.gz
(19.9 kB
view hashes)
Built Distribution
asyncwica-1.0.1-py3-none-any.whl
(20.3 kB
view hashes)
Close
Hashes for asyncwica-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 307e478604dc9b470feb98cd7ed15467a313ca2f3be0ec0619dd82b397c4a285 |
|
MD5 | 6531d18c2ea827f0a186d1eae14df5fa |
|
BLAKE2b-256 | 3bc9a89e6f8cce7f2c1916af622ac4102d0072f0dceec1487f2d98bdd30eb003 |