Registry / workflow / mode-streaming

mode-streaming

JSON →
library0.4.1pypypiunverified

Mode-streaming is a Python library built on top of AsyncIO, designed to simplify asynchronous service-based programming. It allows users to define, start, stop, restart, and supervise services, forming a graph of dependencies. This project is a community-maintained fork of the original 'Mode' project, with a focus on continuous releases, code quality, and support for modern Python versions. The current version is 0.4.1.

pip install -U mode-streaming
INSTALL
IMPORT
SIG · MODE-STREAMING
M
mode-streaming
workflowpythonv0.4.1
Install
2.1s avg
Import
322ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.341s · 22.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.304s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Service
from mode import Service
Base class for defining asynchronous services.
Worker
from mode import Worker
Used to run Mode services from the command line, providing logging, blocking detection, and remote debugging.

This example demonstrates how to define a basic `Service` with a periodic background task and run it using `mode.Worker`. A service can define `on_start`, `on_stop`, and timed tasks using the `@Service.timer` decorator. For command-line execution, `Worker(Service(), loglevel='info').execute_from_commandline()` is typically used.

import asyncio from mode import Service, Worker class MyService(Service): async def on_start(self) -> None: print("MyService started!") self.add_background_task(self.my_periodic_task) @Service.timer(1.0) async def my_periodic_task(self) -> None: print("Periodic task running...") async def on_stop(self) -> None: print("MyService stopped.") async def main(): service = MyService() worker = Worker(service, loglevel="info") # In a real application, you'd execute from command line # For quickstart, manually manage lifecycle (or use execute_from_commandline) try: await worker.start() await asyncio.sleep(3) finally: await worker.stop() if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
breakingVersion 0.3.6 was yanked due to missing functionality, and 0.4.0 was released to mitigate 'backward-breaking incompatibilities'. Users upgrading from versions prior to 0.4.0 should carefully review the changelog for potential breaking changes.
fix
Review release notes for versions between your current version and 0.4.0. Test thoroughly after upgrading.
affects: <0.4.0
gotchaWhen integrating `mode-streaming` with blocking frameworks like Django or Flask, it's crucial to apply monkey-patching libraries like `gevent` or `eventlet` at the very top of your application's entry point. Failing to do so before other imports can lead to unexpected behavior or deadlocks.
fix
Place `import gevent.monkey; gevent.monkey.patch_all()` or similar `eventlet` patching code as the first lines in your main application module.
affects: All
gotchaIn versions prior to 0.4.1, the `Service` class could attempt to get an event loop during its initialization phase, potentially leading to issues if no event loop was yet set. This was addressed in version 0.4.1.
fix
Upgrade to version 0.4.1 or later to avoid this specific initialization issue.
affects: <0.4.1
Upgrade
Version history
0.4.1latest on PyPI · released Apr 15, 2024
Audit
Dependencies
pydotoptionalOptional dependency for visualizing service dependency graphs.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
mode-streaming — pip install mode-streaming · libregistry