Skip to main content

Pyouter

Pyouter is a tasks router by hierarchy and layered tasks, which may come from command line or http restful api

Deepwki: https://deepwiki.com/fanfeilong/pyouter

pyouter

INSTALL

install pyouter

pip install pyouter

examples

minimal example code for pyouoter:

from typing import Any
from pyouter.app import App
from pyouter.router import Router

import json
import asyncio
import time


async def hello(config, options):
    print("hello function")
    
def hello_sync(config, options):
    print("hello sync")

class Hello:
    def __init__(self, value) -> None:
        self.value = value
    
    # Router class SHOULD provider method: `run(self, config, options)`
    async def run(self, config, options) -> Any:
        self.config = config
        self.options = options
        await self.inner()
    
    async def inner(self):
        print(f"run Hello, {self.value}")
        await asyncio.sleep(2)
        print(f"hello class object, self.options.debug:{self.options.debug}, sleep 2s")
        if self.options.debug:
            print(f'debug, {self.value}')
            
class Hello_Sync:
    def __init__(self, value) -> None:
        self.value = value
    
    # Router class SHOULD provider method: `run(self, config, options)`
    def run(self, config, options) -> Any:
        self.config = config
        self.options = options
        self.inner()
    
    def inner(self):
        print(f"run Hello_Sync, {self.value}")
        time.sleep(self.value)
        print(f"hello class object, self.options.debug:{self.options.debug}, sleep {self.value}s")
        if self.options.debug:
            print(f'debug, {self.value}')

if __name__=="__main__":
    '''
    Usage:
        ## execute:
        * python test.py test.hello.func
        * python test.py test.hello.obj
        * python test.py test
        
        ## dump router path only:
        * python test.py test.hello -i
        * python test.py test.hello --insepect
        
        ## dump router path and execute:
        * python test.py test.hello -v
        * python test.py test.hello --view

        ## browse and run in a local web ui:
        * python test.py --web
        * python test.py test.hello --web --no-browser
    '''
    
    app = App(
        config='config.json',
    )
    
    app.option(
        '-d', '--debug',
        dest='debug',
        action="store_true",
        help='debug'
    )
    
    app.use(
        router=Router(
            test=Router(
                hello=Router(
                    func=hello,
                    obj=Hello("world"),
                    obj2=Hello_Sync(10)
                ),
                hello2=hello,
                hello3=Router(
                    func=hello_sync,
                    obj=Hello("world"),
                    obj2=Hello_Sync(20),
                )
            )
        )
    )
    
    app.run()
    
    

local web

https://cursor.com/artifacts/v/art-1cdde7f3-5756-49a3-97ac-2d54dc193da9

Open the current router in a browser. The server binds to 127.0.0.1:8765 and uses only the Python standard library.

python test.py --web
python test.py --web --port 9000
python test.py test.hello --web --no-browser

The left column is the route tree. The right panel shows the selected node's status, a map of the nearby routes, and the logs captured from that node's standard output and standard error. Click a node to inspect it. Use ▶, double-click, or 执行 to run it. Running a router runs its children, same as the command line.

app.web() starts the same page from Python. --host defaults to localhost; binding another interface exposes task execution on that interface.

What's new

0.1.2

  • add a local web ui (--web) to browse, visualize, and run routers

0.1.0

  • fix executor bug

0.0.9

  • improve -v, --view, -i, --insepect option for path debug

0.0.8

  • add app.option support
  • improve App(config=), support config patth
  • add aysnc support
  • will execute all routers pallarent by using async ThreadPoolExecutor

0.0.7

  • add pyouter self completion of bash and fish

0.0.6

  • fixed bug in fish completion install

0.0.5

  • pass config if need

0.04

  • custom parser

0.0.3

  • support pyouter completion
  • pyouter as entry points of package

0.0.2

  • rename plugin to pyouter

0.0.1

  • project init
  • add pypi settings
  • add installer

Metadata

Release files for pyouter 0.1.2

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

Source distribution (sdist)

Source distribution for pyouter 0.1.2
File Size Uploaded Provenance Actions
pyouter-0.1.2.tar.gz 29.0 kB Without provenance Details for pyouter-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 61.1 kB

Release files / pyouter-0.1.2.tar.gz

Download URL pyouter-0.1.2.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
59285f6d7a653c036b08734376338fd8aba4858bf765eff940a8be6aa7244577
BLAKE2b-256 checksum
How to use checksums
246de797ab8a59e6b5547e65612ebd3e978603e999ee532b8a017dd3063bb04a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / pyouter-0.1.2-py3-none-any.whl

Download URL pyouter-0.1.2-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8285b1b9763097c921b81e321b5d9c2da9c42aac4f994e5166457c948acd5d98
BLAKE2b-256 checksum
How to use checksums
57868cd15d2ac7aaddb50aca45524b8e8cd6be95a9ebe2e771f24ade8bed9d7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Security for pyouter 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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