This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Are you permissions making too much noise all the time? Are your permissions
stomping all over your actual code? Are your permission decorators clawing
at your line count all the time? Think there's no answer? There is! Flask-Allows.

Flask-Allows is an authorization tool for Flask inspired by
`django-rest-framework <https:"" tomchristie="" django-rest-framework="">`'s
permissioning system and `rest_condition <https:"" caxap="" rest_condition="">`'s
ability to compose simple requirements into more complex ones.


Flask-Allows provides a simple route decorator that accepts a list of requirements,
which can be any callable that accept an identity and the current request.

.. code:: Python

from flask_allows import Allows
from flask import g, request
from .myapp import app

allows = Allows(identity_loader=lambda: g.user)

def is_staff(ident, request):
return ident.permlevel == 'staff'

def staff_only():
return "Welcome to the staff lounge"

Flask-Allows also provides a Permission class that can act as either a boolean
or a context manager. This depends on flask-allows being previously configured
on the current application.

.. code:: Python

from flask import render_template
from flask_allows import Permission
from .myapp import app
from .requirements import is_staff

def index():
if Permission(is_staff):
return render_template('staff_index.html')
return render_template('user_index.html')

def do_stuff():
with Permission(is_staff):

When using `Permission` as a context manager, if the loaded identity doesn't
meet the requirements, an exception is thrown immediately. However, when used
as a boolean, it simply returns True or False.

It's also possible to provide an already loaded user to `Permission` by passing
it via the `identity` keyword.

More Advanced Stuff

flask-allows provides a small toolkit for crafting more complex requirements.
One of these is the base `Requirement` class:

.. code:: Python

from flask_allows import Requirement
from .models import Forum, Group

class CanAccessForum(Requirement):
def fulfill(self, identity, request):
forum_id = self.determine_forum_id(request)
user_group_ids = self.get_user_group_ids(user)

q = Forum.query.with_entities( == forum_id, Forum.groups.any(

return q is not None

def determine_forum(self, request):
# do something complicated to determine the forum_id
return request.view_args['forum_id']

def user_group_ids(self, user):
if user.is_anonymous():
return [Group.get_guest_group().id]
return [ for gr in user.groups]

When providing a class based requirement to be fulfilled, you must
instantiate it in case there's any setup that needs to be performed.

.. code:: Python

def forum(forum_id):

def forum(forum_id):

Or if you have many simple requirements that need to be composed into a more
complex requirement, this is provided as well:

.. code:: Python

from flask_allows import And, Or Not
from .requirements import is_staff, read_only, is_member

@allows.requires(Or(is_staff, And(readonly, is_member)))
def something():

Why not Flask-Principal?

I have nothing against Flask-Principal, I just found that it didn't work for
what I needed without adding an extra layer around it.
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
flask-allows-0.1.0.tar.gz (7.7 kB) Copy SHA256 Checksum SHA256 Source Aug 20, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting