Service objects are plain old Python objects (POPOs) that encapsulate a service or interactions with a system. They are usually kept in a separate file named services.py or utils.py.
For example, checking a web service is sometimes dumped into a model method as follows:
class Profile(models.Model): ... def is_superhero(self): url = "http://api.herocheck.com/?q={0}".format( self.user.username) return webclient.get(url)
This method can be refactored to use a service object as follows:
from .services import SuperHeroWebAPI def is_superhero(self): return SuperHeroWebAPI.is_hero(self.user.username)
The service object can now be defined in services.py as follows:
API_URL = "http://api.herocheck.com/?q={0}" class SuperHeroWebAPI: ...