Skip to main content

A Python implementation of the Service Object pattern, inspired by Ruby's SimpleCommand gem

Project description

py-service-object

Header

PyPi

A Python implementation of the Service Object pattern, inspired by Ruby's SimpleCommand gem.

Installation

pip install py-service-object

Usage

from py_service_object import ServiceObject

class CreateUser(ServiceObject):
    def __init__(self, user_params):
        self.user_params = user_params
        super().__init__()

    def call(self):
        try:
            user = User.create(self.user_params)
            return user
        except Exception as e:
            self.errors.append({"message": str(e)})
            return self

Using the ServiceObject

service = CreateUser(user_params)
service.call()

if service.success:
    user = service.result
else:
    errors = service.errors

Features

  • Encapsulates business logic in dedicated classes
  • Built-in error handling
  • Result caching
  • Clean and consistent interface
  • Type hints support

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

py_service_object-0.1.2.tar.gz (155.7 kB view details)

Uploaded Source

Built Distribution

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

py_service_object-0.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file py_service_object-0.1.2.tar.gz.

File metadata

  • Download URL: py_service_object-0.1.2.tar.gz
  • Upload date:
  • Size: 155.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for py_service_object-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6d9b5d92b19787cdc957a3fc33ff331dc9fa73bcbdd749a4c2c067f628a5ab60
MD5 0689030ee33aa6c88bd678916dd02024
BLAKE2b-256 a7e6a9f43c8ceb6d55ba980d36db78ad50ce8b64919f34f3382bbcd6768c0667

See more details on using hashes here.

File details

Details for the file py_service_object-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for py_service_object-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b2a6c25ffa17c397283961b71c39274eb070b1232c2ccc4a4153f703e6077dc
MD5 a0191d9ab2939d472e31823a6019d076
BLAKE2b-256 a659d97e916b2b5f94131f4eebd86e93d33f385739af54fa347de367e36dc8a4

See more details on using hashes here.

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