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, Type
from saleyo import MixinOperation, ToolChain
class MyOperation(MixinOperation[Any]):
def mixin(self, target: Type, toolchain: ToolChain = ...) -> None:
...
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
saleyo-1.0.2.tar.gz
(9.4 kB
view details)
Built Distribution
saleyo-1.0.2-py3-none-any.whl
(12.6 kB
view details)
File details
Details for the file saleyo-1.0.2.tar.gz
.
File metadata
- Download URL: saleyo-1.0.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 963bf9cf382310f9903df6c52b3b4ff658bea7537dd6ac6f25a0f8133523c702 |
|
MD5 | 4c2581a67afd32fbb052c2ccfe8c8cb8 |
|
BLAKE2b-256 | ae05d69eb1124f445bf2999d42d9b329127511c1b614dcc51e5748fed6ce30f5 |
File details
Details for the file saleyo-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: saleyo-1.0.2-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bcea80118f3ab49c102b05a5cc6df6d93be27bbb2714a7c0ae54c9ed3a278b6 |
|
MD5 | 177e624c8f108ffa83579be39e55c700 |
|
BLAKE2b-256 | e0136267edff713d00c1f61462ee4145269d6ddc8a0ced54a50fadebf5b0fe28 |