Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

silvanus-0.1.1b1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

silvanus-0.1.1b1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file silvanus-0.1.1b1.tar.gz.

File metadata

  • Download URL: silvanus-0.1.1b1.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

Hashes for silvanus-0.1.1b1.tar.gz
Algorithm Hash digest
SHA256 226c9dc6acc241e7c26dfbaa5d85cd87b9a4871a33b2d282e3be9d4a1ce409e9
MD5 08e1ccd36652cd1b89e6ab0ee1717ae0
BLAKE2b-256 0f5d9c40813f1606894d9dccce611a5d3d6e6cff84b2de914b463bfe14a34379

See more details on using hashes here.

File details

Details for the file silvanus-0.1.1b1-py3-none-any.whl.

File metadata

  • Download URL: silvanus-0.1.1b1-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

Hashes for silvanus-0.1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4404988a7b83555edfd573c1fa878ae2fdb58154ae4fc897543d59a067cb842
MD5 c3f611a51bc4c0d67c71723f183ce741
BLAKE2b-256 1ac2905b00dcf2641de9535cd9f7e1fa5e69281591b7b43d27af5d142d1bbbf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page