Authorization is an unstructured problem. Writing code to decide who can do what in your app can cover a broad set of cases. The most structure that typically gets applied to this problem area is a set of if statements and roles, but in reality, there are a lot more patterns and structure that we can apply.
Oso is an open source system for building authorization into applications. It's a bit like SQLAlchemy in that it provides a structured approached to authorization, much like SQLAlchemy does for data modeling and access. Oso cofounder/CTO, Sam Scott, gave a talk providing a mental model for authorization and showing how to apply it using Oso, Python and SQLAlchemy - watch the recording below.