A simple library for routing with a tree-like structure
Project description
SILVANUS
The simple library for different routing with a tree-like structure
Implementation example
Silvanus is created as a low-level library that simplifies the construction of productive, user-friendly, functional and customizable frameworks on top of. These can be different options (data buses, web, etc.), therefore, for an example of how it might look, there is silvahttp.
Paradigms:
- Each element is changeable almost beyond recognition, but a combination of them is possible due to common protocols that are well described out of the box.
- Many things are done out of the box (for example, the almost universal SimpleRouter and its two RouterIterators, which implement both the data queue interface with filters and the data bus interface with filters )
- The most universal protocols, which is why it is recommended to write small wrappers on top of routing for frameworks.
Usage
First:
pip install silvanus
Later:
data queue interface with filters using FirstTrueRouterIterator, and data bus interface with filters using AllTrueRouterIterator
import asyncio
from dataclasses import dataclass
from silvanus.routing.simple import SimpleRouter
from silvanus.strategy.routers import FirstTrueRouterIterator, AllTrueRouterIterator
from silvanus.structures import RoutingData
@dataclass(frozen=True)
class SimpleFilter: # Our custom simple filter
value: int
async def __call__(self, data: RoutingData) -> bool:
return data.request_data.get("value", None) == self.value
# silvanus supports all data types as a result of routing,
# but the most useful for frameworks will be the return of functions.
def some_handler(text: str) -> str:
return text * 2
router = SimpleRouter()
router1 = SimpleRouter([SimpleFilter(value=10)], data="wrong")
router2 = SimpleRouter([SimpleFilter(value=15), ], data=some_handler)
router3 = SimpleRouter([SimpleFilter(value=15), ], data="yes!")
router.add_routers([router1, router2, router3])
async def main():
result = await router.route(
data=RoutingData(
request_data={"value": 15}
),
iterator=FirstTrueRouterIterator() # get only first True result
)
assert result("silvanus-") == "silvanus-silvanus-" # our some_handler
result_2 = await router.route(
data=RoutingData(
request_data={"value": 15}
),
iterator=AllTrueRouterIterator() # get all True result
)
assert result_2[0](result_2[1]) == "yes!yes!" # our some_handler and text from second data
asyncio.run(main())
Examples:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file silvanus-0.1.1b0.tar.gz.
File metadata
- Download URL: silvanus-0.1.1b0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2db2039db085d7e99997f45648e318212663e2583717c2808f70415a660f288c
|
|
| MD5 |
a8563fa556645211154508753c47bbe7
|
|
| BLAKE2b-256 |
750027c69205b17ea0fd22fed86e5ab769cea9a81f5708cf261205ac99afd792
|
File details
Details for the file silvanus-0.1.1b0-py3-none-any.whl.
File metadata
- Download URL: silvanus-0.1.1b0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59077a3b34e4f0fd8bc73eafc7fdc3f87020d14aee500fe9afb53eb7a4a196a
|
|
| MD5 |
808e986467a8bc675a76ab900aa5bd6e
|
|
| BLAKE2b-256 |
3b73477e63c5a7920452c51007a7dd1c4e66cf3f7daf55ce344eef934adc2950
|