Skip to main content

A simple authorization API for Python.

Project description

A simple authorization API for Python.


First, mix the UserMixin and ResourceMixin with your User class and the resources you want to provide authorization for.

from moat import ResourceMixin, UserMixin

class Post(ResourceMixin):

    def type(self):
        return self.__class__.__name__

    def identifier(self):

class User(UserMixin):

    def identifier(self):

Now implement the methods specified in the base Repository class to retrieve the permissions from the datastore. Pass in an instance of the repository to the main Moat class.

Now you can check whether a user is actually authorized to do certain things:

from moat import Moat, Permissions
from moat.repositories import MockRepository

moat = Moat(MockRepository())

# Now you can check if a user has a specific permission for a certain object.
moat.has(, user, post)
moat.has(Permission.write, user, post)

# Remove the permission
moat.remove(Permission.write, user, post)

# Set the permission, again
moat.set(Permission.write, user, post)

# Or get all the ids of type of resources the user has permissions for
moat.all(, user, Post)

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
moat-0.1.0.tar.gz (2.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page