Elegant service objects for Python.
Project description
unimog
Elegant service objects for Python.
A robust and flexible framework that facilitates composable business logic and ensures uniform error handling for various business logic actions. The fundamental concept revolves around the idea that a single action should perform a specific task, and these actions can be seamlessly organized into groups. Notably, these groups and actions can be intricately nested, forming complex Directed Acyclic Graphs (DAGs).
To enhance readability and maintainability, we leverage the concept of service objects to encapsulate intricate business logic in an easily understandable format. Establishing a normalized interface for all service calls not only streamlines the overall architecture but also enables the chaining of service calls. This consistent approach to handling errors across the entire framework ensures a standardized and predictable error-handling mechanism, contributing to the reliability of the system.
Usage
pip install unimog
Action
import gzip
from dataclasses import dataclass
from unimog import Action, Context
@dataclass
class Input(Context):
text: str
@dataclass
class Output(Input):
compressed_text: str
class CompressText(Action):
def perform(self):
compressed_text = gzip.compress(self.input.text)
self.output.compressed_text = compressed_text
result = CompressText(Input, Output)(text="Hello, World!")
result.is_success() # True
result.compressed_text # b'\x1f\x8b\x08\x00r\x92\xb7e…
Organizer
import gzip
from dataclasses import dataclass
from unimog import Action, Context, Organizer
@dataclass
class MyContext(Context):
text: str = None
compressed_text: str = None
class CompressText(Action):
def perform(self):
compressed_text = gzip.compress(self.input.text)
self.output.compressed_text = compressed_text
class DecompressText(Action):
def perform(self):
text = gzip.decompress(self.input.compressed_text)
self.output.text = text
CompressAndDecompressText = Organizer(
CompressText(MyContext, MyContext),
DecompressText(MyContext, MyContext)
)
result = CompressAndDecompressText(text="Hello, World!")
result.is_success() # True
result.text # "Hello, World!"
Contributing
Tests
python -m pytest
Release
Bump version number accordingly (semantic versioning).
poetry build
poetry publish
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
File details
Details for the file unimog-0.2.0.tar.gz
.
File metadata
- Download URL: unimog-0.2.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.3 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2626a08241cd4fce64ffb56babf6b39985270e1c1a8f0f03346de94c00530990 |
|
MD5 | a195f30dc25f121d127f85ef9af7f3d3 |
|
BLAKE2b-256 | afc657e342ade22cfcc5af9c2b4c3c0a41f1a1f4c706582c376bd9c50fe90485 |
File details
Details for the file unimog-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: unimog-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.3 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7793d6710bcffd69a1f0bb6a7ea56e03ac4e1b227c3032fbf923b58e07f9f8a4 |
|
MD5 | 8b2d55ba4c5c539ad8491d77a22208b4 |
|
BLAKE2b-256 | 68ee63f0ed130a439a89edf0716800d0341e50cba451baa5aeda58b2d8da3bde |