{"id":6003,"library":"mode-streaming","title":"mode-streaming","description":"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.","status":"active","version":"0.4.1","language":"en","source_language":"en","source_url":"https://github.com/faust-streaming/mode","tags":["asyncio","services","streaming","concurrency","framework","microservices"],"install":[{"cmd":"pip install -U mode-streaming","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Optional dependency for visualizing service dependency graphs.","package":"pydot","optional":true}],"imports":[{"note":"Base class for defining asynchronous services.","symbol":"Service","correct":"from mode import Service"},{"note":"Used to run Mode services from the command line, providing logging, blocking detection, and remote debugging.","symbol":"Worker","correct":"from mode import Worker"}],"quickstart":{"code":"import asyncio\nfrom mode import Service, Worker\n\nclass MyService(Service):\n    async def on_start(self) -> None:\n        print(\"MyService started!\")\n        self.add_background_task(self.my_periodic_task)\n\n    @Service.timer(1.0)\n    async def my_periodic_task(self) -> None:\n        print(\"Periodic task running...\")\n\n    async def on_stop(self) -> None:\n        print(\"MyService stopped.\")\n\nasync def main():\n    service = MyService()\n    worker = Worker(service, loglevel=\"info\")\n    # In a real application, you'd execute from command line\n    # For quickstart, manually manage lifecycle (or use execute_from_commandline)\n    try:\n        await worker.start()\n        await asyncio.sleep(3)\n    finally:\n        await worker.stop()\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Review release notes for versions between your current version and 0.4.0. Test thoroughly after upgrading.","message":"Version 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.","severity":"breaking","affected_versions":"<0.4.0"},{"fix":"Place `import gevent.monkey; gevent.monkey.patch_all()` or similar `eventlet` patching code as the first lines in your main application module.","message":"When 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to version 0.4.1 or later to avoid this specific initialization issue.","message":"In 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.","severity":"gotcha","affected_versions":"<0.4.1"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}