Skip to main content

Role and permission management for Django projects.

Project description

django-minosse

Role-based access control for Django, without the extra database tables.

django-minosse lets you define roles as Python classes, sync them to Django's built-in Group model, and protect views with decorators or mixins — all on top of the django.contrib.auth machinery you already have.


Requirements

  • Python 3.12+
  • Django 5.0+

Installation

pip install django-minosse

or with uv:

uv add django-minosse

Add "minosse" to INSTALLED_APPS, alongside the standard auth and contenttypes apps that are already present in every Django project:

INSTALLED_APPS = [
    ...
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "minosse",
    ...
]

Run python manage.py migrate at least once so the auth tables exist before calling sync() or get_group().

Quick start

1. Define roles

# myapp/roles.py
from minosse.roles import AbstractRole, RoleRegistry

registry = RoleRegistry()

@registry.register
class EditorRole(AbstractRole):
    group_name = "Editors"
    available_permissions = {
        "can_publish": True,
        "can_edit": True,
        "can_delete": False,
    }

@registry.register
class ViewerRole(AbstractRole):
    group_name = "Viewers"
    available_permissions = {
        "can_view_reports": True,
    }

2. Sync roles to the database

from myapp.roles import registry

registry.sync()   # call from a management command or AppConfig.ready()

3. Protect views

Function-based views:

from django.contrib.auth.decorators import login_required
from minosse.decorator import role_required, permission_required
from .roles import EditorRole

@login_required
@role_required(EditorRole)
def editor_dashboard(request):
    ...

@login_required
@permission_required("auth.can_publish")
def publish_article(request, pk):
    ...

Class-based views:

from django.views.generic import TemplateView
from minosse.mixin import RoleRequiredMixin, PermissionRequiredMixin
from .roles import EditorRole

class EditorDashboardView(RoleRequiredMixin, TemplateView):
    required_role_class = EditorRole
    template_name = "editor/dashboard.html"

class PublishView(PermissionRequiredMixin, TemplateView):
    required_permission_codename = "auth.can_publish"
    template_name = "editor/publish.html"

4. Manage role membership

# Assign / remove
EditorRole.add_user_to_role(user)
EditorRole.remove_user_from_role(user)

# Check
if EditorRole.user_has_role(user):
    ...

Features

  • Define roles as Python classes with declarative permission sets
  • Sync roles and permissions to Django's Group / Permission models
  • Protect function-based views with @role_required and @permission_required
  • Protect class-based views with RoleRequiredMixin and PermissionRequiredMixin
  • Check roles and permissions in templates with |can and |is filters
  • Register roles centrally via RoleRegistry for bulk sync

Documentation

Full documentation is available in the docs/ directory and can be served locally:

make docs-serve

License

MIT

Project details


Download files

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

Source Distribution

django_minosse-1.1.2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_minosse-1.1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django_minosse-1.1.2.tar.gz.

File metadata

  • Download URL: django_minosse-1.1.2.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_minosse-1.1.2.tar.gz
Algorithm Hash digest
SHA256 0767ecf7a381eef4c45671eff477ecbf188927abf08247fb0bea2e4ee8e5d031
MD5 1816597504282fef5ecc8f2cdb537a8b
BLAKE2b-256 ab54e57279358aca09ce4e082c5f4a8951bb56916bc40c185cdbcb778295ebc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_minosse-1.1.2.tar.gz:

Publisher: publish.yml on fundor333/django-minosse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_minosse-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: django_minosse-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_minosse-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 53cefccfb7f8b929747eb82c3f1cbbc651d69b15e54c236f570b180e883a06d8
MD5 bf76d03a2791e1ce16a45b5ae20ff6e1
BLAKE2b-256 7c3201c69628c473cc828a35945f2cf38ea82932841e741ad28fcc9e03a3aaa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_minosse-1.1.2-py3-none-any.whl:

Publisher: publish.yml on fundor333/django-minosse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page