casbin-databases-adapter


Namecasbin-databases-adapter JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/officialpycasbin/casbin-databases-adapter
SummaryThis is an Adapter for PyCasbin that implemented using Databases connection to achieve async process
upload_time2024-10-27 00:24:36
maintainerNone
docs_urlNone
authorIsa Setiawan Abdurrazaq
requires_python>=3.3
licenseApache 2.0
keywords casbin asynccasbin async databases casbin-adapter rbac access control abac acl permission
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Databases Casbin Adapter

[![GitHub Actions](https://github.com/officialpycasbin/casbin-databases-adapter/workflows/build/badge.svg?branch=master)](https://github.com/officialpycasbin/casbin-databases-adapter/actions)
[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/casbin-databases-adapter/badge.svg?branch=master)](https://coveralls.io/github/officialpycasbin/casbin-databases-adapter?branch=master)
[![Version](https://img.shields.io/pypi/v/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
[![Download](https://img.shields.io/pypi/dm/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
[![License](https://img.shields.io/pypi/l/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)

This is an Adapter for [PyCasbin](https://github.com/casbin/pycasbin) that implemented using [Databases](https://www.encode.io/databases) connection to achieve async process

## Installation

```
pip install casbin_databases_adapter
```

## Simple Example

```python
import casbin_databases_adapter
import casbin
from databases import Database
import sqlalchemy
from sqlalchemy import Table, Column, String, Integer
from sqlalchemy.sql.ddl import CreateTable
import asyncio

DATABASE_URL = "sqlite+aiosqlite:///example.db"

async def create_casbin_rule_table(db: Database):
    metadata = sqlalchemy.MetaData()
    table = Table(
        "casbin_rules",
        metadata,
        Column("id", Integer, primary_key=True),
        Column("ptype", String(255)),
        Column("v0", String(255)),
        Column("v1", String(255)),
        Column("v2", String(255)),
        Column("v3", String(255)),
        Column("v4", String(255)),
        Column("v5", String(255)),
    )
    q = CreateTable(table)
    await db.execute(query=str(q))
    return table

async def main():
    database = Database(DATABASE_URL)
    await database.connect()
    casbin_rule_table = await create_casbin_rule_table(database)
    adapter = casbin_databases_adapter.DatabasesAdapter(db=database, table=casbin_rule_table)
    
    e = casbin.Enforcer('path/to/model.conf', adapter)
    
    sub = "alice"  # the user that wants to access a resource.
    obj = "data1"  # the resource that is going to be accessed.
    act = "read"  # the operation that the user performs on the resource.
    
    if e.enforce(sub, obj, act):
        # permit alice to read data1
        pass
    else:
        # deny the request, show an error
        pass

# run the main function
asyncio.run(main())
```

### Getting Help

- [PyCasbin](https://github.com/casbin/pycasbin)

### License

This project is licensed under the [Apache 2.0 license](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/officialpycasbin/casbin-databases-adapter",
    "name": "casbin-databases-adapter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.3",
    "maintainer_email": null,
    "keywords": "casbin, asynccasbin, async, databases, casbin-adapter, rbac, access control, abac, acl, permission",
    "author": "Isa Setiawan Abdurrazaq",
    "author_email": "isasetiawan@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3a/21/d6ee80f18fbe63a67d0e121635e66d2e64c811353d432e5aab514eeed5f5/casbin_databases_adapter-1.3.0.tar.gz",
    "platform": null,
    "description": "# Databases Casbin Adapter\n\n[![GitHub Actions](https://github.com/officialpycasbin/casbin-databases-adapter/workflows/build/badge.svg?branch=master)](https://github.com/officialpycasbin/casbin-databases-adapter/actions)\n[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/casbin-databases-adapter/badge.svg?branch=master)](https://coveralls.io/github/officialpycasbin/casbin-databases-adapter?branch=master)\n[![Version](https://img.shields.io/pypi/v/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)\n[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)\n[![Download](https://img.shields.io/pypi/dm/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)\n[![License](https://img.shields.io/pypi/l/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)\n\nThis is an Adapter for [PyCasbin](https://github.com/casbin/pycasbin) that implemented using [Databases](https://www.encode.io/databases) connection to achieve async process\n\n## Installation\n\n```\npip install casbin_databases_adapter\n```\n\n## Simple Example\n\n```python\nimport casbin_databases_adapter\nimport casbin\nfrom databases import Database\nimport sqlalchemy\nfrom sqlalchemy import Table, Column, String, Integer\nfrom sqlalchemy.sql.ddl import CreateTable\nimport asyncio\n\nDATABASE_URL = \"sqlite+aiosqlite:///example.db\"\n\nasync def create_casbin_rule_table(db: Database):\n    metadata = sqlalchemy.MetaData()\n    table = Table(\n        \"casbin_rules\",\n        metadata,\n        Column(\"id\", Integer, primary_key=True),\n        Column(\"ptype\", String(255)),\n        Column(\"v0\", String(255)),\n        Column(\"v1\", String(255)),\n        Column(\"v2\", String(255)),\n        Column(\"v3\", String(255)),\n        Column(\"v4\", String(255)),\n        Column(\"v5\", String(255)),\n    )\n    q = CreateTable(table)\n    await db.execute(query=str(q))\n    return table\n\nasync def main():\n    database = Database(DATABASE_URL)\n    await database.connect()\n    casbin_rule_table = await create_casbin_rule_table(database)\n    adapter = casbin_databases_adapter.DatabasesAdapter(db=database, table=casbin_rule_table)\n    \n    e = casbin.Enforcer('path/to/model.conf', adapter)\n    \n    sub = \"alice\"  # the user that wants to access a resource.\n    obj = \"data1\"  # the resource that is going to be accessed.\n    act = \"read\"  # the operation that the user performs on the resource.\n    \n    if e.enforce(sub, obj, act):\n        # permit alice to read data1\n        pass\n    else:\n        # deny the request, show an error\n        pass\n\n# run the main function\nasyncio.run(main())\n```\n\n### Getting Help\n\n- [PyCasbin](https://github.com/casbin/pycasbin)\n\n### License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE).\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "This is an Adapter for PyCasbin that implemented using Databases connection to achieve async process",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/officialpycasbin/casbin-databases-adapter"
    },
    "split_keywords": [
        "casbin",
        " asynccasbin",
        " async",
        " databases",
        " casbin-adapter",
        " rbac",
        " access control",
        " abac",
        " acl",
        " permission"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d05ed94599dbec3bc61b591907782df37475cc1d98cbae01862c0a3730b1414",
                "md5": "1ab167a8ed4f4e07169609519a35787e",
                "sha256": "3e12bd4552c57989388106777d6407278e62e9e29ad5976cd62640a37e73922c"
            },
            "downloads": -1,
            "filename": "casbin_databases_adapter-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1ab167a8ed4f4e07169609519a35787e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.3",
            "size": 7995,
            "upload_time": "2024-10-27T00:24:34",
            "upload_time_iso_8601": "2024-10-27T00:24:34.511736Z",
            "url": "https://files.pythonhosted.org/packages/4d/05/ed94599dbec3bc61b591907782df37475cc1d98cbae01862c0a3730b1414/casbin_databases_adapter-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a21d6ee80f18fbe63a67d0e121635e66d2e64c811353d432e5aab514eeed5f5",
                "md5": "2d50abb6b74e3073750be5458fa10523",
                "sha256": "37ace2ee91af5df3ffbde51f55d2f044d0479ea19828f30ab7648d5739d42c24"
            },
            "downloads": -1,
            "filename": "casbin_databases_adapter-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2d50abb6b74e3073750be5458fa10523",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.3",
            "size": 8253,
            "upload_time": "2024-10-27T00:24:36",
            "upload_time_iso_8601": "2024-10-27T00:24:36.715954Z",
            "url": "https://files.pythonhosted.org/packages/3a/21/d6ee80f18fbe63a67d0e121635e66d2e64c811353d432e5aab514eeed5f5/casbin_databases_adapter-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-27 00:24:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "officialpycasbin",
    "github_project": "casbin-databases-adapter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "casbin-databases-adapter"
}
        
Elapsed time: 7.55281s