Skip to main content

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

Project description

Saleyo

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

Getting Start

pip install saleyo

Basic Tutorial

Declear a Mixin class

from saleyo import Mixin

class Foo:...


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

Use MixinOperation

from typing import Any
from saleyo import Mixin
from saleyo.operation import 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[None]):
        return InvokeEvent.from_call(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 Operation

from typing import Any, Type
from saleyo.base.template import MixinOperation
from saleyo.base.toolchain import ToolChain

class MyOperation(MixinOperation[Any]):
    def mixin(self, target: Type, 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-0.1.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

saleyo-0.1.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saleyo-0.1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.12.5.dev21+gb4da6e0e CPython/3.10.12

File hashes

Hashes for saleyo-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fb1a08da34079f3f8b14df416accfabffd89682d6faeea205a33143a56442911
MD5 900a9efd1e1930cddcee6cb64381c283
BLAKE2b-256 503cc81d5edc21b63ea78b9a297275260451a77572d2c9bd7bc3ce763515b7b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: saleyo-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.12.5.dev21+gb4da6e0e CPython/3.10.12

File hashes

Hashes for saleyo-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19b662ea36b2f9fe4d0c887104493c53b1b6231938d3dd452eac20f0d2fc6c6f
MD5 b6ce650400eb5924391beee3df620ef3
BLAKE2b-256 b6c496e944f17959cc4dae7c3feced69932d3c040cbc5ca33db3cccf09bb26fb

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