{"id":43709934,"url":"https://github.com/hirokiky/django-keeper","last_synced_at":"2026-02-05T06:30:40.147Z","repository":{"id":57420578,"uuid":"90509812","full_name":"hirokiky/django-keeper","owner":"hirokiky","description":"Authorization library for Django, with ACL, not depends on models.","archived":false,"fork":false,"pushed_at":"2025-11-26T08:08:25.000Z","size":78,"stargazers_count":51,"open_issues_count":7,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-29T07:57:21.155Z","etag":null,"topics":["authorization","django","permissions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hirokiky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-05-07T04:56:33.000Z","updated_at":"2025-11-26T08:08:30.000Z","dependencies_parsed_at":"2023-01-30T18:01:00.407Z","dependency_job_id":null,"html_url":"https://github.com/hirokiky/django-keeper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hirokiky/django-keeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokiky%2Fdjango-keeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokiky%2Fdjango-keeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokiky%2Fdjango-keeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokiky%2Fdjango-keeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hirokiky","download_url":"https://codeload.github.com/hirokiky/django-keeper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokiky%2Fdjango-keeper/sbom","scorecard":{"id":465322,"data":{"date":"2025-08-11","repo":{"name":"github.com/hirokiky/django-keeper","commit":"6055d2cb6e75b876c22b017205f1b5269a4126b2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/hirokiky/django-keeper/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/hirokiky/django-keeper/tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/hirokiky/django-keeper/tests.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/tests.yml:41","Warn: pipCommand not pinned by hash: .github/workflows/tests.yml:42","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/tests.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T12:20:39.849Z","repository_id":57420578,"created_at":"2025-08-19T12:20:39.849Z","updated_at":"2025-08-19T12:20:39.849Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29114910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T05:31:32.482Z","status":"ssl_error","status_checked_at":"2026-02-05T05:31:29.075Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authorization","django","permissions"],"created_at":"2026-02-05T06:30:40.074Z","updated_at":"2026-02-05T06:30:40.135Z","avatar_url":"https://github.com/hirokiky.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-keeper\n\nAuthorization library for Django, not depends on models.\n\n* Won't depend on models\n* Won't depend on datastores\n* Won't depend on Django's permission system\n* Won't depend on Django's User model\n\nSupported versions:\n\n* Python 3.8\n* Python 3.9\n* Python 3.10\n* Python 3.11\n* Python 3.12\n* Python 3.13\n* Django 2.2\n* Django 3.0\n* Django 3.1\n* Django 3.2\n* Django 4.1\n* Django 4.2\n* Django 5.0\n* Django 5.1\n* Django 5.2\n\n## Install\n\n```bash\n$ pip install django-keeper\n```\n\nAnd add to INSTALLED_APPS\n\n```python\nINSTALLED_APPS = [\n    ...\n    'keeper',\n]\n```\n\n## At A Glance\n\nDeclarative permission mapping for models.\n\n```python\nfrom django.conf import settings\nfrom keeper.security import Allow\nfrom keeper.operators import Everyone, Authenticated, IsUser\n\n\nclass Issue(models.Model):\n    author = models.ForeignKey(settings.AUTH_USER_MODEL)\n    ...\n\n    def __acl__(self):\n        return [\n            (Allow, Everyone, 'view'),\n            (Allow, Authenticated, 'add_comment'),\n            (Allow, IsUser(self.author), 'edit'),\n        ]\n\n```\n\nInstances of model allow:\n\n* Every requests to view\n* Autheticated requests to add comments\n* it's author to edit\n\nThen, apply `@keeper` for views.\n\n```python\nfrom keeper.views import keeper\n\n\n# Model Permissions\n@keeper(\n    'view',\n    model=Issue,\n    mapper=lambda request, issue_id: {'id': issue_id},\n)\ndef issue_detail(request, issue_id):\n    \"\"\" View requires 'view' permission of Issue model\n\n    * An issue object will be retrieved\n    * keeper will check whether the rquests has 'view' permission for the issue\n\n    The third argument function can return keyword argument to retrieve the issue object.\n    \"\"\"\n    request.k_context  # Will be instance of the issue object\n    ...\n\n\n\n@keeper(\n    'add_comment',\n    model=Issue,\n    mapper=lambda request, issue_id: {'id': issue_id},\n)\ndef add_comment(request, issue_id):\n    ...\n\n```\n\n## Global Permission\n\nNot just for model permissions `django-keeper` can handle global permissions.\n\nFirst, write class having `__acl__` method in models.py.\n\n```python\nclass Root:\n    def __acl__(self):\n        return [\n            (Allow, Authenticated, 'view_dashboard'),\n            (Allow, Authenticated, 'add_issue'),\n        ]\n```\n\nIt's not necessary to put it in `models.py`,\nbut easy to understand.\n\nAnd specify it in settings.\n\n```python\nKEEPER_GLOBAL_CONTEXT = 'myapp.models.Root'\n```\n\nThen you can use global permission in views.\nSimply just apply `@keeper` and permission names.\n\n```python\n@keeper('add_issue')\ndef issue_list(request):\n    \"\"\" View requires 'add_issue' permission of Root Context\n    \"\"\"\n\n```\n\n## Operators\n\nOperators is just `Callable[[HttpRequest], bool]`.\nBy default django-keeper has these operators:\n\n* `keeper.operators.Everyone`\n* `keeper.operators.Authenticated`\n* `keeper.operators.IsUser`\n* `keeper.operators.Staff`\n\nAlso you can create your own operators easily.\n\n```python\nfrom keeper.operators import Authenticated, Operator\n\n\nclass IsIP(Operator):\n    def __init__(self, ip):\n        self.ip = ip\n        \n    def __call__(self, request):\n        return request.META.get('REMOTE_ADDR') == self.ip\n\n\nclass BelongsTeam(Authenticated):\n    def __init__(self, team, role):\n        self.team = team\n\n    def __call__(self, request):\n        if not super().__call__(request):\n            return False\n        return  request.user.team == self.team\n```\n\nUse it in ACL\n\n```python\nclass Article(models.Model):\n    team = models.ForeignKey(Team)\n    \n    def __acl__(self):\n        return [\n            (Allow, Everyone, 'view'),\n            (Allow, BelongsTeam(self.team), 'edit'),\n            (Allow, IsIP(settings.COMPANY_IP_ADDRESS), 'edit'),\n        ]\n```\n\n### Combining operators\n\nYou can use bitwise operators to combine multiple \"Operators\".\n\n\n```python\nclass Article(models.Model):\n    def __acl__(self):\n        return [\n            (Allow, Authenticated() \u0026 IsIP(settings.COMPANY_IP_ADDRESS), 'view'),\n        ]\n```\n\nThere operators can be used\n\n* `a \u0026 b`\n* `a | b`\n* `a ^ b`\n* `~a`\n\n## On Fail Actions\n\nYou can change actions when requests can't pass ACLs.\n\n```python\nfrom keeper.views import keeper, login_required\n\n@keeper(\n    'view_articles',\n    on_fail=login_required(),\n)\ndef dashboard(request):\n    ...\n```\n\nThis view will behave just like `@login_required` decorator of Django\nwhen requests don't have 'view' permission.\n\nAlso you can use other actions.\n\n* `keeper.views.login_required`\n* `keeper.views.permission_denied`\n* `keeper.views.not_found`\n* `keeper.views.redirect`\n\n## Use in template\n\nHandling permissions in templates is also supported.\n\n```django\n{% load keeper %}\n\n{% has_permission issue 'edit' as can_edit %}\n\n{% if can_edit %}\n    \u003ca href=\"...\"\u003eEdit\u003c/a\u003e\n{% endif %}\n```\n\nWhen checking global permission, use `has_global_permission`.\n\n```django\n{% load keeper %}\n\n{% has_global_permission 'add_issue' as can_add_issue %}\n\n{% if can_add_issue %}\n    \u003ca href=\"...\"\u003eNew Issue\u003c/a\u003e\n{% endif %}\n```\n\n## With Django Core\n\nAdd the authentication backend:\n\n```python\nAUTHENTICATION_BACKENDS = (\n    'keeper.permissions.ObjectPermissionBackend',\n    'django.contrib.auth.backends.ModelBackend',\n)\n```\n\nNow `User.has_perm` method will consider permissions of django-keeper.\n\n## Alternative\n\n* [django-guardian](https://github.com/django-guardian/django-guardian)\n    * It depends on databases\n    * Not way to handle global permissions, not just for a model\n* [django-rules](https://github.com/dfunckt/django-rules)\n    * Basiaclly, rules is used with Django's permissions, but keeper isn't (basiacally).\n    * rules doesn't support view decorators or mixins for it's \"rules\" system (for Django's permission, yes).\n## FAQ\n\n* Can I filter models by using ACL?\n    * Not supported\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirokiky%2Fdjango-keeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhirokiky%2Fdjango-keeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirokiky%2Fdjango-keeper/lists"}