Anywise let you write your application anywise
Project description
Anywise
Anywise let you write your application anywise.
Source Code: https://github.com/raceychan/anywise
Documentation: On its way here...
Goals
- isolating bussiness logic from input ports
- let you write less code than other wise
- promote best practices and clean code
- runtime-performance
Philosophy
- Non-intrusive
- dead simple
- minimalist
Quck Start
from anywise import Anywise, handler_registry, inject
class UserCommand: ...
class CreateUser(UserCommand): ...
class UserEvent: ...
class UserCreated(UserEvent): ...
userhandler = handler_registry(UserCommand)
userlistener = listener_registry(UserEvent)
@userhandler
async def create_user(
command: CreateUser,
anywise: Anywise,
service: UserService = inject(user_service_factory)
):
await service.create_user(command.username, command.user_email)
await anywise.publish(UserCreated(command.username, command.user_email))
@userlistener
async def notify_user(event: UserCreated, service: EmailSender):
await service.send_greeting(command.user_email)
# at your client code
async def main():
anywise = AnyWise()
anywise.include([userhandler, userlistener])
command = CreateUser()
result = await anywise.send(command)
Tutorial
register handler with HandlerRegistry
userhandler = handler_registry(UserCommand)
userhanlder(hanlder_func)
use HandlerRegistry to decorate / register a function or a class as handlers of a command.
when a function is registered, anywise will can through its signature, if any param is annotated as a subclass of the base command type, it will be registered as a handler of the command.
when a class is registered, anywise will scan through its pulic methods, then repeat the steps to functions.
use CommandGuard to intercept handler call
from anywise import AnyWise, GuardRegistry, handler_registry
guard_registry = GuardRegistry()
user_registry = handler_registry(UserCommand)
@user_registry
async def handler_create(create_user: CreateUser, context: dict[str, ty.Any]):
assert context["processed_by"]
return "done"
@user_registry
async def handler_update(update_user: UpdateUser, context: dict[str, ty.Any]):
return "done"
@guard_registry.pre_handle
async def mark(command: UserCommand, context: dict[str, ty.Any]) -> None:
if not context.get("processed_by"):
context["processed_by"] = ["1"]
else:
context["processed_by"].append("1")
in this case, mark will be called before handler_update or handler_create gets called.
Features
- builtin dependency injection
- handler guards
- framework integration
- remote handler
FAQ
On its way here...
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 anywise-0.1.1.tar.gz.
File metadata
- Download URL: anywise-0.1.1.tar.gz
- Upload date:
- Size: 37.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c7183dc7ea45a772a4d8658ab6d32f0f8548968e17f52ca13b6f6a48da97014
|
|
| MD5 |
52b54441c9d64285fa8e5f504ddf8169
|
|
| BLAKE2b-256 |
cde173bc392dd7edab8b87139dbd2d081dd4f43adf3df692f6421c559a874913
|
File details
Details for the file anywise-0.1.1-py3-none-any.whl.
File metadata
- Download URL: anywise-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e89cc3b2ed983577735bfd58e8f6c8fa3fb64ff86f263207d8b86fbe61e4978e
|
|
| MD5 |
2d66383929b2eee656eaed3963962ec8
|
|
| BLAKE2b-256 |
a2d3d34404bf83db65f0c204f1c5eb2b3abc21ed9d94f81ea8aceb66c63f3984
|