Metadata-Version: 2.1
Name: streamx
Version: 0.0.1
Summary: This package provides a modern, easy-to-use, and versatile solution for working with streams of data in an asynchronous fashion
Home-page: https://github.com/MasonFlint44/streamx
Author: Mason Flint
Author-email: masonflint44@gmail.com
Project-URL: Bug Tracker, https://github.com/MasonFlint44/streamx/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Object Brokering
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE

# Streamx

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

The simple solution for sharing async data streams in Python.

## Installation

```bash
pip install streamx
```

## Usage

### Creating a stream

```python
from streamx import AsyncStream

stream = AsyncStream[int]()
```

### Pushing items into a stream

You can push items into a stream using the push method. This method is a coroutine, so you'll need to await it. All listening tasks will receive each item.

```python
await stream.push(1)
await stream.push(2)
await stream.push(3)
```

### Consuming a stream

To consume a stream, you can use the listen method. This method returns an async iterator, so you can use it with an async for loop. Many tasks can listen to the same stream at the same time, and each task will receive each item pushed into the stream while it is listening.

```python
with stream.listen() as listener:
    async for item in listener:
        print(item)
```

### Closing a Stream

Once you're done pushing data into a stream, you should close it to signal to consumers that there will be no more data. This signals to exit the async for loop, and prevents any new consumers from listening to the stream.

```python
await stream.close()
```

### Example

```python
import asyncio

from streamx import AsyncStream


async def main():
    stream = AsyncStream[int]()

    async def producer():
        for i in range(5):
            await stream.push(i)
            await asyncio.sleep(1)
        await stream.close()

    async def consumer():
        with stream.listen() as listener:
            async for item in listener:
                print(item)

    await asyncio.gather(producer(), consumer(), consumer())


asyncio.run(main())
```
