{"id":28564250,"url":"https://github.com/raceychan/anywise","last_synced_at":"2025-06-10T13:32:22.527Z","repository":{"id":263630876,"uuid":"891019537","full_name":"raceychan/anywise","owner":"raceychan","description":"A modern type-based messaging framework in python, designed for the ease of architecture evolvement.","archived":false,"fork":false,"pushed_at":"2025-01-26T18:58:41.000Z","size":1659,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T08:48:13.428Z","etag":null,"topics":["cqrs","eventdriven","eventsourcing","microservice","python"],"latest_commit_sha":null,"homepage":"https://lihil.cc/anywise/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raceychan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-19T15:31:18.000Z","updated_at":"2025-03-19T12:41:13.000Z","dependencies_parsed_at":"2024-12-17T20:22:11.722Z","dependency_job_id":"6b362b9d-6080-4c57-a45e-1a763eaa494c","html_url":"https://github.com/raceychan/anywise","commit_stats":null,"previous_names":["raceychan/anywise"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raceychan%2Fanywise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raceychan%2Fanywise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raceychan%2Fanywise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raceychan%2Fanywise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raceychan","download_url":"https://codeload.github.com/raceychan/anywise/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raceychan%2Fanywise/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259084899,"owners_count":22803104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cqrs","eventdriven","eventsourcing","microservice","python"],"created_at":"2025-06-10T13:30:46.800Z","updated_at":"2025-06-10T13:32:22.518Z","avatar_url":"https://github.com/raceychan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anywise\n\nAnywise provides an universal and flexible API for your application by abstracting function calls into message passing, \nmake it easy to build scalable, maintainable, and testable applications.\n\n- Eliminates direct dependencies on implementation details.\n- Improves development speed, reduces testing complexity, and enhances the reusability of the application as a whole.\n- Promotes best practices and loose coupling.\n\n\n## Features\n\n- minimal change to existing code, easy to adopt.\n- integrated dependency injection system, automatically inject dependency at runtime.\n- type-based message system\n- strong support to AOP, middlewares, decorators, etc. \n\n---\n\nDocumentation: https://raceychan.github.io/anywise/\n\nSource Code: https://github.com/raceychan/anywise\n\n---\n\n## Install\n\n```py\npip install anywise\n```\n\n## Quck Start\n\nLet start with defining messages:\n\n```py\nfrom anywise import Anywise, MessageRegistry, use\n\nclass UserCommand: ...\nclass CreateUser(UserCommand): ...\nclass UserEvent: ...\nclass UserCreated(UserEvent): ...\n```\n\nNext step, Register command handler and event listeners.\n\n### handler/listener\n\nfor simplicity, we will use `function-based` handler here\n\n```py\nfrom anywise import MessageRegistr, BaseGuard\nregistry = MessageRegistry(command_base=UserCommand, event_base=UserEvent)\n\nasync def create_user(\n    command: CreateUser, \n    anywise: Anywise, \n    service: UserService = use(user_service_factory)\n):\n    await users.signup(command.username, command.user_email)\n    await anywise.publish(UserCreated(command.username, command.user_email))\n\nasync def notify_user(event: UserCreated, service: EmailSender):\n    await service.send_greeting(command.user_email)\n\nclass IPContext(TypeDict):\n    ip: str\n\nclass IPLimiter(BaseGuard):\n    def __init__(self, throttle_list: tuple[str], white_lst: WhiteList):\n        self._lst = throttle_list\n        self._white_lst = white_lst\n\n    async def __call__(self, command: UserCommand, context: IPContext):\n        if not await self._white_lst.should_pass(command.user_id):\n            if context[\"ip\"] in self._lst:\n                return ThrottleResponse()\n\nregistry.register(IPLimiter, create_user, notify_user)\n```\n\nNOTE: you can also use `registry` as a decorator to register handler/listeners.\n\n### Message Source\n\nMessage source is where you can your message from.\n\nHere we use fastapi as our message source, but it can be other choices.\n\n```py\nfrom anywise import Anywise\nfrom anywise.integration.fastapi import FastWise\n\n@app.post(\"/users\")\nasync def signup(command: CreateUser, anywise: FastWise) -\u003e User:\n    return await anywise.send(command)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraceychan%2Fanywise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraceychan%2Fanywise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraceychan%2Fanywise/lists"}