Skip to main content
Services contain business logic. Keep routes thin, services fat.
services/user_service.py

Transactions

@transactional commits when the method returns and rolls back when it raises. Because exceptions already map to HTTP responses, a validation failure rolls back the transaction and returns a 400 without any explicit handling.

Injecting a service into a route

Singleton services

For expensive initialization you want to happen once rather than per request:

Generating a service