Python command line tasks router
Project description
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
INSTALL
install pyouter
pip install pyouter
- advanced: install for shell completion support
examples
- src/tests/test.py
- depends: src/tests/config.json
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
'''
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()
What's new
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
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
pyouter-0.1.1.tar.gz
(10.0 kB
view details)
File details
Details for the file pyouter-0.1.1.tar.gz.
File metadata
- Download URL: pyouter-0.1.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da57384ed9b61170b18488d9e7e4f08cb5800e68e2f0706a742f77307bc58e5a
|
|
| MD5 |
98b20e1fef5d3a368e701757feaa4d87
|
|
| BLAKE2b-256 |
d6e0d2ce3f31bbbba97ed9ac2191cb7cc9e03db5ee3e95c4b2218cb459418840
|