Skip to main content

Saleyo is a lightwight scalable Python AOP framework, easy to use and integrate.

Project description

Saleyo

Saleyo is a lightwight scalable Python AOP framework, easy to use and integrate.

Getting Start

pip install saleyo

Basic Tutorial

Declear a Mixin class

If you don't like decorators, you can pass arguments to operations and call the mixin method manually.

from saleyo import Mixin

class Foo:...


@Mixin(target = Foo)
class MixinFoo:...

Use MixinOperation

Here is a simple demo.

from typing import Any
from saleyo import Mixin, Accessor, OverWrite, Post, Pre, Intercept, InvokeEvent


class Foo:
    __private = "private varible"

    def demo(self):
        pass


@Mixin(target=Foo)
class MixinFoo:
    # Will add a varible named `__private` to Foo and it has the same address with `_Foo__private`
    private: Accessor[str] = Accessor("__private")

    # Will Add the `func` to `Foo`
    @OverWrite
    def func(self):
        print("hello saleyo")

    # Will intercept the demo method and redirect to `lambda: print("hello world")`
    @Intercept.configure(target_name="demo")
    @staticmethod
    def intercept_demo(_: InvokeEvent):
        return InvokeEvent(lambda: print("hello world"))

    # Will call before `demo` call
    @Pre.configure(target_name="demo")
    def pre_demo(*arg):
        print("pre hello world")

    # Will call after `demo` call
    @Post.configure(target_name="demo")
    def post_demo(*arg):
        print("post hello world")


foo: Any = (
    Foo()
)  # Add the typing hint to avoid the error message from some IDE plugins.

print(foo.__private)  # Also `print(MixinFoo.private.value)`
foo.func()
foo.demo()

>>> private varible
>>> hello saleyo
>>> pre hello world
>>> hello world
>>> post hello world

Custom ToolChain

ToolChain determines the ability to modify the class.

from saleyo import Mixin, GCToolChain, Arguments, Pre


@Mixin(target=str, toolchain=GCToolChain)
class MixinStr:
    @Pre.configure(target_name="format")
    def pre_format(self, *args) -> Arguments[...]:
        print(f"input args: {args}")
        return Arguments(self, "saleyo")


print("hello world {}".format("python"))

>>> input args: ('python',)
>>> hello world saleyo

Custom Operation

The default operations can't satify you? Why not try define a operation yourself!

from typing import Any
from saleyo import MixinOperation, ToolChain
from saleyo.base.typing import MixinAble

class MyOperation(MixinOperation[Any]):
    def mixin(self, target: MixinAble, toolchain: ToolChain = ...) -> None:
        ...

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

saleyo-1.0.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

saleyo-1.0.3-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file saleyo-1.0.3.tar.gz.

File metadata

  • Download URL: saleyo-1.0.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.13.1.dev2+g6779fbdb CPython/3.10.12 Linux/6.5.0-1016-azure

File hashes

Hashes for saleyo-1.0.3.tar.gz
Algorithm Hash digest
SHA256 03b8ed941b511a94c1faf1514d936f570aefa509cda9d0deb9acce55a04c7ec0
MD5 da27e7817794f7bb6336255e93111740
BLAKE2b-256 9a69f7f9a02ae11c60b8476234b60f129fd6ef296fe59fd74297cc8a75092290

See more details on using hashes here.

File details

Details for the file saleyo-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: saleyo-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.13.1.dev2+g6779fbdb CPython/3.10.12 Linux/6.5.0-1016-azure

File hashes

Hashes for saleyo-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7fa29f2028d4db75e0f630b3568a796ecb8d45a52377bc94f88d5bb4a92c3e1a
MD5 0d39ada6ce450881fa57f82bc48f8f2a
BLAKE2b-256 9e959bab01a039771552199dce9b5b2141006214a1bb1a2739ac3023a203a5a1

See more details on using hashes here.

Supported by

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