rbacx


Namerbacx JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryRBAC/ABAC policy engine for Python with policy sets, condition DSL, and hot reload
upload_time2025-09-08 23:50:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
license MIT License Copyright (c) 2025 RBACX (Cheater121) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords rbac abac policy authorization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RBACX

<!-- 
[![CI](https://github.com/Cheater121/rbacx/actions/workflows/ci.yml/badge.svg)](https://github.com/Cheater121/rbacx/actions/workflows/ci.yml)
[![Docs](https://img.shields.io/badge/docs-website-blue)](https://cheater121.github.io/rbacx/)
-->
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
<!-- After publishing to PyPI:
[![PyPI](https://img.shields.io/pypi/v/rbacx)](https://pypi.org/project/rbacx/)
[![Python](https://img.shields.io/pypi/pyversions/rbacx)](https://pypi.org/project/rbacx/)
-->

Universal **RBAC/ABAC** policy engine for Python with a clean core, policy sets, a compact condition DSL (including time ops), and adapters for common web frameworks.

## Features
- Algorithms: `deny-overrides` (default), `permit-overrides`, `first-applicable`
- Conditions: `==`, `!=`, `<`, `<=`, `>`, `>=`, `contains`, `in`, `hasAll`, `hasAny`, `startsWith`, `endsWith`, `before`, `after`, `between`
- Explainability: `decision`, `reason`, `rule_id`/`last_rule_id`, `obligations`
- Policy sets: combine multiple policies with the same algorithms
- Hot reload: file/HTTP/S3 sources with ETag and a polling manager
- Types & lint: mypy-friendly core, Ruff-ready

## Installation
```bash
pip install rbacx
```

## Quickstart
```python
from rbacx.core.engine import Guard
from rbacx.core.model import Subject, Action, Resource, Context

policy = {
    "algorithm": "deny-overrides",
    "rules": [
        {
            "id": "doc_read",
            "effect": "permit",
            "actions": ["read"],
            "resource": {"type": "doc", "attrs": {"visibility": ["public", "internal"]}},
            "condition": {"hasAny": [ {"attr": "subject.roles"}, ["reader", "admin"] ]},
            "obligations": [{"mfa": True}]
        },
        {"id": "doc_deny_archived", "effect": "deny", "actions": ["*"], "resource": {"type": "doc", "attrs": {"archived": True}}},
    ],
}

g = Guard(policy)

d = g.evaluate_sync(
    subject=Subject(id="u1", roles=["reader"]),
    action=Action("read"),
    resource=Resource(type="doc", id="42", attrs={"visibility": "public"}),
    context=Context(attrs={"mfa": True}),
)

assert d.allowed is True
assert d.effect == "permit"
print(d.reason, d.rule_id)  # "matched", "doc_read"
```

### Decision schema
- `decision`: `"permit"` or `"deny"`
- `reason`: `"matched"`, `"explicit_deny"`, `"action_mismatch"`, `"resource_mismatch"`, `"condition_mismatch"`, `"condition_type_mismatch"`, `"no_match"`
- `rule_id` / `last_rule_id`
- `obligations`: list passed to the obligation checker

### Policy sets
```python
from rbacx.core.policyset import decide as decide_policyset

policyset = {"algorithm":"deny-overrides", "policies":[ policy, {"rules":[...]} ]}
result = decide_policyset(policyset, {"subject":..., "action":"read", "resource":...})
```

## Hot reloading
```python
from rbacx.core.engine import Guard
from rbacx.storage import FilePolicySource   # from rbacx.storage import HotReloader if you prefer
from rbacx.store.manager import PolicyManager

guard = Guard(policy={})
mgr = PolicyManager(guard, FilePolicySource("policy.json"))
mgr.poll_once()        # initial load
mgr.start_polling(10)  # background polling thread
```

## Packaging
- We ship `py.typed` so type checkers pick up annotations.
- Standard PyPA flow: `python -m build`, then `twine upload` to (Test)PyPI.

## License
MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rbacx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "rbac, abac, policy, authorization",
    "author": null,
    "author_email": "Cheater121 <cheater1211@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ce/78/95d0e7dd6a618a0d6400a19707669ab608c74e2768c5f31fc9c729e50c18/rbacx-0.1.0.tar.gz",
    "platform": null,
    "description": "# RBACX\n\n<!-- \n[![CI](https://github.com/Cheater121/rbacx/actions/workflows/ci.yml/badge.svg)](https://github.com/Cheater121/rbacx/actions/workflows/ci.yml)\n[![Docs](https://img.shields.io/badge/docs-website-blue)](https://cheater121.github.io/rbacx/)\n-->\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n<!-- After publishing to PyPI:\n[![PyPI](https://img.shields.io/pypi/v/rbacx)](https://pypi.org/project/rbacx/)\n[![Python](https://img.shields.io/pypi/pyversions/rbacx)](https://pypi.org/project/rbacx/)\n-->\n\nUniversal **RBAC/ABAC** policy engine for Python with a clean core, policy sets, a compact condition DSL (including time ops), and adapters for common web frameworks.\n\n## Features\n- Algorithms: `deny-overrides` (default), `permit-overrides`, `first-applicable`\n- Conditions: `==`, `!=`, `<`, `<=`, `>`, `>=`, `contains`, `in`, `hasAll`, `hasAny`, `startsWith`, `endsWith`, `before`, `after`, `between`\n- Explainability: `decision`, `reason`, `rule_id`/`last_rule_id`, `obligations`\n- Policy sets: combine multiple policies with the same algorithms\n- Hot reload: file/HTTP/S3 sources with ETag and a polling manager\n- Types & lint: mypy-friendly core, Ruff-ready\n\n## Installation\n```bash\npip install rbacx\n```\n\n## Quickstart\n```python\nfrom rbacx.core.engine import Guard\nfrom rbacx.core.model import Subject, Action, Resource, Context\n\npolicy = {\n    \"algorithm\": \"deny-overrides\",\n    \"rules\": [\n        {\n            \"id\": \"doc_read\",\n            \"effect\": \"permit\",\n            \"actions\": [\"read\"],\n            \"resource\": {\"type\": \"doc\", \"attrs\": {\"visibility\": [\"public\", \"internal\"]}},\n            \"condition\": {\"hasAny\": [ {\"attr\": \"subject.roles\"}, [\"reader\", \"admin\"] ]},\n            \"obligations\": [{\"mfa\": True}]\n        },\n        {\"id\": \"doc_deny_archived\", \"effect\": \"deny\", \"actions\": [\"*\"], \"resource\": {\"type\": \"doc\", \"attrs\": {\"archived\": True}}},\n    ],\n}\n\ng = Guard(policy)\n\nd = g.evaluate_sync(\n    subject=Subject(id=\"u1\", roles=[\"reader\"]),\n    action=Action(\"read\"),\n    resource=Resource(type=\"doc\", id=\"42\", attrs={\"visibility\": \"public\"}),\n    context=Context(attrs={\"mfa\": True}),\n)\n\nassert d.allowed is True\nassert d.effect == \"permit\"\nprint(d.reason, d.rule_id)  # \"matched\", \"doc_read\"\n```\n\n### Decision schema\n- `decision`: `\"permit\"` or `\"deny\"`\n- `reason`: `\"matched\"`, `\"explicit_deny\"`, `\"action_mismatch\"`, `\"resource_mismatch\"`, `\"condition_mismatch\"`, `\"condition_type_mismatch\"`, `\"no_match\"`\n- `rule_id` / `last_rule_id`\n- `obligations`: list passed to the obligation checker\n\n### Policy sets\n```python\nfrom rbacx.core.policyset import decide as decide_policyset\n\npolicyset = {\"algorithm\":\"deny-overrides\", \"policies\":[ policy, {\"rules\":[...]} ]}\nresult = decide_policyset(policyset, {\"subject\":..., \"action\":\"read\", \"resource\":...})\n```\n\n## Hot reloading\n```python\nfrom rbacx.core.engine import Guard\nfrom rbacx.storage import FilePolicySource   # from rbacx.storage import HotReloader if you prefer\nfrom rbacx.store.manager import PolicyManager\n\nguard = Guard(policy={})\nmgr = PolicyManager(guard, FilePolicySource(\"policy.json\"))\nmgr.poll_once()        # initial load\nmgr.start_polling(10)  # background polling thread\n```\n\n## Packaging\n- We ship `py.typed` so type checkers pick up annotations.\n- Standard PyPA flow: `python -m build`, then `twine upload` to (Test)PyPI.\n\n## License\nMIT\n",
    "bugtrack_url": null,
    "license": "\n        MIT License\n        \n        Copyright (c) 2025 RBACX (Cheater121)\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "RBAC/ABAC policy engine for Python with policy sets, condition DSL, and hot reload",
    "version": "0.1.0",
    "project_urls": {
        "Changelog": "https://github.com/Cheater121/rbacx/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/Cheater121/rbacx",
        "Issues": "https://github.com/Cheater121/rbacx/issues",
        "Repository": "https://github.com/Cheater121/rbacx"
    },
    "split_keywords": [
        "rbac",
        " abac",
        " policy",
        " authorization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2d71b3a28eff75bb3c6d75c2da83d22d87fb987422ebd3472f0ce1f4ca44381d",
                "md5": "eca2235e4edf6c13e49eb02a5a1e3553",
                "sha256": "dffdb3bfad60ba813a3759797061e0691dd57b7dc6fe38bb653d97d5e1e039f8"
            },
            "downloads": -1,
            "filename": "rbacx-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eca2235e4edf6c13e49eb02a5a1e3553",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 82748,
            "upload_time": "2025-09-08T23:50:10",
            "upload_time_iso_8601": "2025-09-08T23:50:10.971784Z",
            "url": "https://files.pythonhosted.org/packages/2d/71/b3a28eff75bb3c6d75c2da83d22d87fb987422ebd3472f0ce1f4ca44381d/rbacx-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ce7895d0e7dd6a618a0d6400a19707669ab608c74e2768c5f31fc9c729e50c18",
                "md5": "882dec4e7dc94aab1ff4db6582782eb5",
                "sha256": "d3b09d579da1ecc69c9b25f80ba9dc54b881558c21486bb058f2efd22e2359f3"
            },
            "downloads": -1,
            "filename": "rbacx-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "882dec4e7dc94aab1ff4db6582782eb5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 63082,
            "upload_time": "2025-09-08T23:50:14",
            "upload_time_iso_8601": "2025-09-08T23:50:14.350325Z",
            "url": "https://files.pythonhosted.org/packages/ce/78/95d0e7dd6a618a0d6400a19707669ab608c74e2768c5f31fc9c729e50c18/rbacx-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-08 23:50:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Cheater121",
    "github_project": "rbacx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rbacx"
}
        
Elapsed time: 2.19629s