Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python authorization libraries decide whether an authenticated user may perform an action on a resource. A policy engine evaluates each request against roles, attributes, or relationships stored in a policy model. These libraries let apps and AI agents enforce permissions in one place instead of scattering checks through the code.
Popularity
OpenFGA has the most monthly downloads among dedicated authorization libraries in this comparison, at 3.2M.
def instances_user_has_any_permission_for(self, user, actions):
if user.is_active and user.is_superuser:
# active superusers can perform any action (including unrecognised ones) # on any instance return self.model._default_manager.all()
elif "change" in actions or "delete" in actions:
if user.has_perm(self._get_permission_name("change")):
# user can edit all instances return self.model._default_manager.all()
elif user.has_perm(self._get_permission_name("add")):
# user can edit their own instances return self.model._default_manager.filter(
**{self.owner_field_name: user}
)
else:
# user has no permissions at all on this model return self.model._default_manager.none()
else:
# action is either not recognised, or is the 'add' action which is # not meaningful for existing instances. As such, non-superusers # cannot perform it on any existing instances. return self.model._default_manager.none()
def _enforce(self, scope: Scope, receive: Receive) -> bool:
"""
Enforce a request
:param user: user will be sent to enforcer
:param request: ASGI Request
:return: Enforce Result
"""
request = Request(scope, receive)
path = request.url.path
method = request.method
if 'user' not in scope:
raise RuntimeError("Casbin Middleware must work with an Authentication Middleware")
assert isinstance(request.user, BaseUser)
user = request.user.display_name if request.user.is_authenticated else 'anonymous'
return self.enforcer.enforce(user, path, method)
def filter_queryset(self, request, queryset, view):
# We want to defer this import until runtime, rather than import-time. # See https://github.com/encode/django-rest-framework/issues/4608 # (Also see #1624 for why we need to make this import explicitly) from guardian.shortcuts import get_objects_for_user
user = request.user
permission = self.perm_format % {
'app_label': queryset.model._meta.app_label,
'model_name': queryset.model._meta.model_name,
}
return get_objects_for_user(
user, permission, queryset,
**self.shortcut_kwargs)
FAQ
PyCasbin suits apps that want role or attribute policies in a config file. OpenFGA and Authzed suit relationship-based permissions shared across services. django-guardian suits Django apps that need per-object permissions.
Role-based access control grants permissions through roles assigned to users. Attribute-based access control evaluates attributes of the user, the resource, and the request, such as department or time of day.
Authentication confirms who a user is. Authorization decides what that user may do after sign-in.
SpiceDB is an open-source permissions database inspired by Google Zanzibar. Authzed is its Python client library.
OpenFGA is an open-source authorization engine inspired by Google Zanzibar. Its Python SDK writes relationship tuples and checks permissions.
Relationship-based access control grants access from relationships between objects, such as a user who owns a folder. OpenFGA and SpiceDB both implement this model.
For coding agents
Found your authorization library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.