Skip to main content

Django-Caps

Pypi | Read the doc

Django-Caps provides capability based object permission system for Django applications and Django Rest Framework.

This project is inspired by Capn’Proto documentation (interesting paper).

A capability is a provided permission to a specific object. It can be shared a limited amount of time. Users never directly access the targeted object, but through a access that defines allowed capabilities for it.

In short, why use capabilities?

Documentation: https://oxylus-tech.github.io/django-caps/

Features

Here is what we provide:

  • Capability based object permissions system: objects can be shared with specific permissions to user/group. The object is then accessed by this shared object rather than directly (except for its owner).

  • Access sharing: Objects’ accesses can be shared with granular control on permissions.

  • Integration: authentication/permission backend is provided both for Django and Django Rest Framework. Views, viewsets and serializers too.

  • Agents: users can act under different profiles, as a user or group. The accesses always target other agents.

Among other things:

  • Database id obfuscation: object internal id are never exposed to the outside world. Instead uuid are used to reference them in API and urls. This mitigate attacks on predictive id.

Short example

Lets create an object:

# models.py
from django.db import models
from django.utils.translation import gettext_lazy as _

from caps.models import Owned

__all__ = ("Post",)

# Create our example model.
class Post(Owned):
    title = models.CharField(_("Title"), max_length=64)
    content = models.TextField(_("Content"))
    # ... other fields

    # Allowed permissions with allowed reshare depth
    root_grants = {
        "app.view_post": 2, # can be shared then reshared
        "app.change_post": 1, # can be shared once
        "app.delete_post": 0, # can not be shared
    }

Small examples of Django-Caps’ API usage:

from datetime import timedelta

from django.contrib.auth.models import User, Permission
from django.utils import timezone as tz

from caps.models import Agent
from .models import Post

# User has 1-1 relation with an agent
user = User.objects.all()[0]
user_1 = User.objects.all()[1]

# Create the post
post = Post.objects.create(owner=user.agent, title="Some title", content="Some content")

# Share the post to agent 1 with default grants
access = post.share(user_1.agent)
assert access.grants == {"app.view_post": 1, "app.change_post": 0}

# Get objects for user_1
objs = Post.objects.available(user_1.agent)

The views/viewsets will handle permission check depending on the action being requested.

For concrete usage, see the docs! 😉

Metadata

Release files for django-caps 0.0.6

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-caps 0.0.6
File Size Uploaded Provenance
django_caps-0.0.6.tar.gz 284.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-caps 0.0.6
File Interpreter ABI Platform
django_caps-0.0.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 322.1 kB

Release files / django_caps-0.0.6.tar.gz

Download URL django_caps-0.0.6.tar.gz
Size 284.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1067656d368454fbfa71cfe9959904fc9da7fb0ef1e0330d41b61c2947013526
BLAKE2b-256 checksum
How to use checksums
25918ebbd6fe69728c4641453b2d18300cf8347b0e0a3ee5fec871b917c80a98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / django_caps-0.0.6-py2.py3-none-any.whl

Download URL django_caps-0.0.6-py2.py3-none-any.whl
Size 37.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
213427b8c25b1e1587b3ebce714e266e7f8531411381357e67f4627db5120e21
BLAKE2b-256 checksum
How to use checksums
f2703b9aefd28b037706721ce9b609910394f7aa2bf55e7f0db31fab6c6bf03c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for django-caps 0.0.6

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