Skip to main content

Django RAM

Role based user access management for Django.

Requirements

  • Python 3.6+
  • Django 4.1, 4.0, 3.2, 3.1, 3.0

Installation

pip install django-ram

Optionally install with rest framework support:

pip install django-ram[rest_framework]

Add django_ram' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
    ...
    'django_ram',
]
./manage.py migrate

Overview

User Model

Add the RolesMixin to your user model.

from django_ram.models import RolesMixin


class CustomUser(AbstractUser, RolesMixin):
    pass

Also remember to configure AUTH_USER_MODEL in your settings.py module.

Declarative Roles

some_app/roles.py

from django_ram.definition import RoleDefinition


class AdminRole(RoleDefinition):
    name = "Admin"
    description = "System administrator."


class AuthorRole(RoleDefinition):
    name = "Author"
    description = "A writer of a book, article, or document."

Roles will be created (or updated) post migration to reflect role definitions in roles.py files.

Role names have to be globally unique.

Django Admin

Register the admin class (or subclass it to expand functionality.)

from django.contrib import admin
from django_ram.admin import UserAdmin

...

admin.site.register(YourUserModel, UserAdmin)

Rest Framework Support

from django_ram.rest_framework import HasRoleBasePermission, has_role
from some_app.roles import AuthorRole


class HasAuthorRole(HasRoleBasePermission):
    role_definition = AuthorRole


class PublicationViewSet(viewsets.ModelViewset):
    permission_classes = [
        has_role(AuthorRole),
        #  Is equivelant to:
        HasAuthorRole,
    ]

Metadata

Release files for django-ram 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ram 0.1.2
File Size Uploaded Provenance
django-ram-0.1.2.tar.gz 18.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ram 0.1.2
File Interpreter ABI Platform
django_ram-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.9 kB

Release files / django-ram-0.1.2.tar.gz

Download URL django-ram-0.1.2.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
50dd91401b5483ee24d2fcbf65112650bff38161698f2efcaeeee03c9bd791cd
BLAKE2b-256 checksum
How to use checksums
c67a4507f28c87e80c42492774469767d71015f0c5c2825b63fef047e94bbfa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.9.6 requests/2.28.2 setuptools/62.6.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.10.10

Release files / django_ram-0.1.2-py3-none-any.whl

Download URL django_ram-0.1.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c47ab9588f7495d02a779f705f9d2e229c1917e12f2b9ace4e81e4309a559df3
BLAKE2b-256 checksum
How to use checksums
359bbd7b558de03b25cffbcf4da3eb77f94d579d5a8c9cffbea2ea7031e2d9af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.9.6 requests/2.28.2 setuptools/62.6.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.10.10

Security for django-ram 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page