Skip to main content

Add your description here

Project description

Plummy 💧

A lightweight, modern Python micro-framework for building clean, testable, and scalable event-driven applications using a Chain of Responsibility and Ports and Adapters (Hexagonal) architecture.

CI PyPI version codecov


Overview

Plummy provides a set of simple, reusable building blocks to help you structure your application according to Domain-Driven Design (DDD) and Hexagonal Architecture principles. It's designed to keep your core business logic (the "hexagon") pure and isolated from external technical details like SQS, APIs, or databases (the "adapters").

The core idea is to build your application as a pipeline of independent, single-responsibility handlers that pass an event down a chain, allowing each handler to decide if it should process the event.

Key Features

  • Clean Architecture: Enforces a clear separation between your domain, application, and infrastructure layers.
  • Decoupled Components: Uses protocols (Ports) and dependency injection to ensure your business logic is independent of external technologies.
  • Functional & Testable: Encourages writing business logic as simple, pure functions that are easy to unit test.
  • Flexible Pipelines: Built around a Chain of Responsibility pattern to create extensible event-processing pipelines.

Installation

Install plummy directly from PyPI:

pip install plummy

How to Use Plummy

Here's how to build a simple event-processing pipeline with plummy.

1. Define Your Business Logic (Pure Functions)

First, write your business logic as simple, standalone functions. These functions should have no knowledge of the plummy framework.

# your_app/services.py

# A function to check if the event should be handled
def can_process_new_order(data: dict) -> bool:
    return data.get("type") == "NEW_ORDER"

# A function that contains the core business logic
def process_new_order(data: dict) -> dict:
    print(f"Processing order {data['order_id']}...")
    data["status"] = "PROCESSED"
    return data

2. Adapt Your Logic into a Processor

Use the FunctionalProcessor adapter to package your functions into a component that the framework can understand.

# your_app/processors.py
from plummy import FunctionalProcessor
from .services import can_process_new_order, process_new_order

# Adapt your functions into a "Processor"
order_processor = FunctionalProcessor(
    can_handle=can_process_new_order,
    process=process_new_order
)

3. Assemble the Pipeline with Handlers

Use StepHandler to create a "step" in your pipeline for each processor. Then, link the steps together.

# your_app/pipeline.py
from plummy.handlers import StepHandler
from .processors import order_processor
# ... import other processors for other steps

# Create a pipeline step for each processor
order_processing_step = StepHandler(processor=order_processor)
# another_step = StepHandler(processor=another_processor)

# Link them together to form the chain
pipeline_start = order_processing_step
# order_processing_step.set_next(another_step)

# The 'pipeline_start' is now your application's entry point.

4. Run the Pipeline

Pass your event data to the start of the pipeline.

# your_app/main.py
from .pipeline import pipeline_start

def main_entry_point(event: dict):
    """This could be your AWS Lambda handler or an API endpoint."""
    return pipeline_start.handle(event)

# --- Example ---
new_order_event = {"type": "NEW_ORDER", "order_id": "123"}
result = main_entry_point(new_order_event)

print(result)
# Output: {'type': 'NEW_ORDER', 'order_id': '123', 'status': 'PROCESSED'}

🚀 Development & Contribution

Follow these steps to set up the plummy project for local development.

Prerequisites

  • Python 3.10+
  • uv (recommended) or pip

Setup Instructions

1. Create and Activate the Virtual Environment

Navigate to the project root and run:

uv venv
source .venv/bin/activate

2. Install Dependencies

Install the project in editable mode, including all development dependencies:

uv pip install -e ".[dev]"

3. Running Tests

To run the full test suite, use pytest:

pytest

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plummy-0.1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plummy-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file plummy-0.1.1.tar.gz.

File metadata

  • Download URL: plummy-0.1.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for plummy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d8288348e1686872fdf0ab296bcfc4f50d788cbe6a92c55fb4a439e23f108e14
MD5 338a655663d4552f5408c1b7efa04a9c
BLAKE2b-256 c675e0573333a18ac9b68b0fafcb359ef68c03df2e9f0d5e5b7d1a02cd7b606a

See more details on using hashes here.

Provenance

The following attestation bundles were made for plummy-0.1.1.tar.gz:

Publisher: python-publish.yml on GuillermoLB/plummy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plummy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: plummy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for plummy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35c1938cf5c5193a1e3db8e747ec82e86f28235dc6d7d4a3a6568e76e30592ea
MD5 af9c738923f3df84f7d052900c7203fa
BLAKE2b-256 dd87102f3db37448a4019b14cf72c3324ad72e6fb61668eb73d651d14b242d0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for plummy-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on GuillermoLB/plummy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page