A Python implementation of the Service Object pattern, inspired by Ruby's SimpleCommand gem
Project description
py-service-object
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
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
py_service_object-0.1.2.tar.gz
(155.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d9b5d92b19787cdc957a3fc33ff331dc9fa73bcbdd749a4c2c067f628a5ab60
|
|
| MD5 |
0689030ee33aa6c88bd678916dd02024
|
|
| BLAKE2b-256 |
a7e6a9f43c8ceb6d55ba980d36db78ad50ce8b64919f34f3382bbcd6768c0667
|
File details
Details for the file py_service_object-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_service_object-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b2a6c25ffa17c397283961b71c39274eb070b1232c2ccc4a4153f703e6077dc
|
|
| MD5 |
a0191d9ab2939d472e31823a6019d076
|
|
| BLAKE2b-256 |
a659d97e916b2b5f94131f4eebd86e93d33f385739af54fa347de367e36dc8a4
|