Skip to main content

Anywise

Anywise provides a universal and flexible API for your application by abstracting function calls into message passing, make it easy to build scalable, maintainable, and testable applications.

  • Eliminates direct dependencies on implementation details.
  • Improves development speed, reduces testing complexity, and enhances the reusability of the application as a whole.
  • Promotes best practices and loose coupling.

Features

  • minimal change to existing code, easy to adopt.
  • integrated dependency injection system, automatically inject dependency at runtime.
  • type-based message system
  • strong support to AOP, middlewares, decorators, etc.

Documentation: https://raceychan.github.io/anywise/

Source Code: https://github.com/raceychan/anywise


Install

pip install anywise

Quck Start

Let start with defining messages:

from anywise import Anywise, MessageRegistry, use

class UserCommand: ...
class CreateUser(UserCommand): ...
class UserEvent: ...
class UserCreated(UserEvent): ...

Next step, Register command handler and event listeners.

handler/listener

for simplicity, we will use function-based handler here

from anywise import MessageRegistr, BaseGuard
registry = MessageRegistry(command_base=UserCommand, event_base=UserEvent)

async def create_user(
    command: CreateUser, 
    anywise: Anywise, 
    service: UserService = use(user_service_factory)
):
    await users.signup(command.username, command.user_email)
    await anywise.publish(UserCreated(command.username, command.user_email))

async def notify_user(event: UserCreated, service: EmailSender):
    await service.send_greeting(command.user_email)

class IPContext(TypeDict):
    ip: str

class IPLimiter(BaseGuard):
    def __init__(self, throttle_list: tuple[str], white_lst: WhiteList):
        self._lst = throttle_list
        self._white_lst = white_lst

    async def __call__(self, command: UserCommand, context: IPContext):
        if not await self._white_lst.should_pass(command.user_id):
            if context["ip"] in self._lst:
                return ThrottleResponse()

registry.register(IPLimiter, create_user, notify_user)

NOTE: you can also use registry as a decorator to register handler/listeners.

Message Source

Message source is where you can your message from.

Here we use fastapi as our message source, but it can be other choices.

from anywise import Anywise
from anywise.integration.fastapi import FastWise

@app.post("/users")
async def signup(command: CreateUser, anywise: FastWise) -> User:
    return await anywise.send(command)

Metadata

Release files for anywise 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anywise 0.1.9
File Size Uploaded Provenance
anywise-0.1.9.tar.gz 87.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for anywise 0.1.9
File Interpreter ABI Platform
anywise-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 113.0 kB

Release files / anywise-0.1.9.tar.gz

Download URL anywise-0.1.9.tar.gz
Size 87.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0ef762ecfc14645a65e04fbc97b804c165057f6a14ef5756fe76b12b9bf8edc4
BLAKE2b-256 checksum
How to use checksums
41979d9bd47f0918f41eb69d3d77b8c7e32b88a9b397c8c8b5cc8cb1315e9ce4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Release files / anywise-0.1.9-py3-none-any.whl

Download URL anywise-0.1.9-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06315002d9f9c4fd80d04536c5285d69a7fb667a5dd8e85f75d08e775898536d
BLAKE2b-256 checksum
How to use checksums
3c742fefc129966add5bed36d271da68cf12a916059fdb08b282d6c6a4f26c92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Security for anywise 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page