Skip to main content

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


Download files

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

Source Distribution

unimog-0.3.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

unimog-0.3.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file unimog-0.3.0.tar.gz.

File metadata

  • Download URL: unimog-0.3.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0

File hashes

Hashes for unimog-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a06afb82a2160dd82d0a8b37a2834760538a643d77007f68173928fd5cf16b57
MD5 3deb64310f919c72d3e2db7f8faccc4a
BLAKE2b-256 331444fc6c2c5e504b401e58d7f0b5a39ebf03fe63e61d8aad60458cac424341

See more details on using hashes here.

File details

Details for the file unimog-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: unimog-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0

File hashes

Hashes for unimog-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59116f9a68b7b4f395e106f67e68415f9cba4d040b12bc1f79e3ba7eeb796276
MD5 764f86109dfcb586ff51f655d5fd94e0
BLAKE2b-256 df8e7412dce6b0e2227db46a80d504e7af7f877e9c71e09e08470b28ace57059

See more details on using hashes here.

Supported by

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