Bazario
Bazario is a lightweight, expressive library for routing requests and notifications to the right handlers with ease. Designed for modular applications, it simplifies your codebase while staying powerful and flexible.
🚀 Quick Start
Installation
Install Bazario with pip:
pip install bazario
Define Your Logic
1. Create a Request and its Handler
Define what you want to do with a Request and specify how it’s handled:
# application/requests/create_user.py
from bazario import Request, RequestHandler
class CreateUserRequest(Request[str]):
def __init__(self, username: str):
self.username = username
class CreateUserHandler(RequestHandler[CreateUserRequest, str]):
def handle(self, request: CreateUserRequest) -> str:
return f"User {request.username} created!"
2. Create a Notification and its Handler
Use Notification to broadcast events:
# application/notifications/user_created.py
from bazario import Notification, NotificationHandler
class UserCreatedNotification(Notification):
def __init__(self, user_id: str):
self.user_id = user_id
class UserCreatedHandler(NotificationHandler[UserCreatedNotification]):
def handle(self, notification: UserCreatedNotification) -> None:
print(f"Notification: User {notification.user_id} was created.")
Bring It All Together
Set up your Dispatcher to handle requests and notifications seamlessly:
# bootstap/ioc.py
from bazario import Dispatcher, Resolver, Sender, Publisher
from bazario.resolvers.your_di_framework import YourDIFrameworkResolver
from your_di_framework import Container
def provide_registry() -> Registry:
registry = Registry()
registry.add_request_handler(CreateUserRequest, CreateUserHandler)
registry.add_notification_handlers(UserCreatedNotification, UserCreatedHandler)
return registry
def provide_resolver(container: Container) -> Resolver:
return YourDIFrameworkResolver(container)
def provide_dispatcher(registry: Registry, resolver: Resolver) -> Dispatcher:
return Dispatcher(resolver, registry)
def provide_container() -> Container:
container = Container()
container.register(Registry, provide_registry)
container.register(Resolver, provide_resolver)
container.register(Dispatcher, provide_dispatcher)
container.register_aliases(Dispatcher, aliases=[Sender, Publisher])
return container
# presentation/rest/users.py
from your_framework import post
from your_di_framework import inject
from bazario import Sender, Publisher
from application.requests.create_user import CreateUserRequest
from application.notifications.user_created import UserCreatedNotification
@post("/")
@inject
def create_user(sender: Sender, publisher: Publisher) -> None:
response = sender.send(CreateUserRequest("john_doe"))
print(response) # Output: User john_doe created!
publisher.publish(UserCreatedNotification("123")) # Output: Notification: User 123 was created.
✨ Key Features
- Request Handling: A streamlined mechanism for handling requests with clear separation of responsibilities.
- Event Handling: Unified event publication and handling (Notifications) supporting both standard and async/await syntax while maintaining efficient in-memory processing.
- Modular Architecture: Clear separation of business logic, ports, and infrastructure, simplifying development and maintenance.
- IoC Container Integration: Support for DI frameworks enabling easy dependency management and modular configuration.
- Testability: Use of abstractions to easily mock infrastructure adapters for unit testing.
- Asynchronous Support: The bazario.asyncio package enables asynchronous handling, providing flexibility for applications requiring async logic.
- Dependency Separation: Controllers delegate handler resolution to Bazario, focusing solely on request parsing. This improves separation of responsibilities and enhances code maintainability.
- Pipeline Behaviors: Flexible middleware system for implementing cross-cutting concerns like logging, validation, and error handling without modifying handler logic.
- Configurable Processing Chain: Ability to create custom processing pipelines for both requests and notifications, enabling sophisticated pre- and post-processing workflows.
Bazario is optimized for synchronous in-memory processing and handler routing, making it ideal for applications requiring modularity, simplicity, and flexible handler management.
Metadata
Release files for bazario 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bazario-0.4.2.tar.gz | 9.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bazario-0.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.6 kB
Release files / bazario-0.4.2.tar.gz
| Download URL | bazario-0.4.2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
207dd745eba63f35bea8204f438f830538eaba59a0533ee3f8c42bbf698e11da
|
|
BLAKE2b-256 checksum How to use checksums |
392dfba167e1e2cdcb7a37a46047e5b43e5152ce6b86402eda4db938f4b45375
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.
Transparency logRelease files / bazario-0.4.2-py3-none-any.whl
| Download URL | bazario-0.4.2-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
156805fb7fa5ecdf07b713d87413af48753ccbda8b363567e31beef2c43e9b9d
|
|
BLAKE2b-256 checksum How to use checksums |
9757f5bfbafda1d4d4174c39fbdd45851e3caa2276b1047e88f6a5cec45d0e42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.
Transparency logSecurity for bazario 0.4.2
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for bazario-0.4.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.
Transparency logA 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.