Skip to main content

ormar Adapter for PyCasbin

Repo

GitHub Workflow Status Codecov Code Climate maintainability Dependabot

GitHub

GitHub tag (latest SemVer) GitHub tag (latest by date) GitHub last commit

PyPI

PyPI - Version PyPI - Python Versions PyPI - Python Wheel PyPI - Format PyPI - Status PyPI - Downloads PyPI - License

ormar Adapter is the ormar adapter for PyCasbin. With this library, Casbin can load policy from ormar supported database or save policy to it.

Based on Officially Supported Databases, The current supported databases are:

  • PostgreSQL
  • MySQL
  • SQLite

Installation

pip install ormar_casbin_adapter

or

poetry add ormar-casbin-adapter

Simple Example

import casbin
import databases
import ormar
from ormar_casbin_adapter import DatabasesAdapter
import sqlalchemy

database = Database("sqlite://", force_rollback=True)
metadata = sqlalchemy.MetaData()


class CasbinRule(ormar.Model):
    class Meta:
        database = database
        metadata = metadata
        tablename = "casbin_rules"

    id: int = ormar.Integer(primary_key=True)
    ptype: str = ormar.String(max_length=255)
    v0: str = ormar.String(max_length=255)
    v1: str = ormar.String(max_length=255)
    v2: str = ormar.String(max_length=255, nullable=True)
    v3: str = ormar.String(max_length=255, nullable=True)
    v4: str = ormar.String(max_length=255, nullable=True)
    v5: str = ormar.String(max_length=255, nullable=True)


adapter = DatabasesAdapter(model=CasbinRule)

e = casbin.Enforcer("path/to/model.conf", adapter, True)

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 data1ormar_casbin_adapter
    pass
else:
    # deny the request, show an error
    pass

Getting Help

License

This project is licensed under the Apache 2.0 license.

Metadata

Release files for ormar-casbin-adapter 0.0.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 ormar-casbin-adapter 0.0.2
File Size Uploaded
ormar-casbin-adapter-0.0.2.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ormar-casbin-adapter 0.0.2
File Interpreter ABI Platform
ormar_casbin_adapter-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / ormar-casbin-adapter-0.0.2.tar.gz

Download URL ormar-casbin-adapter-0.0.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
18e49ceb2f0546cf80a21b0b01648c6edd50d9de76032e0ae90676a71796ac3f
BLAKE2b-256 checksum
How to use checksums
54f8ed934a14c9472fcd14dbeef0bd381dd48592807f99ba7a0b3bc671dd5f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0

Release files / ormar_casbin_adapter-0.0.2-py3-none-any.whl

Download URL ormar_casbin_adapter-0.0.2-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4511b89540d24a5b32f67683bc59f557e61e9e512f3e6f0846bd63c80a20a2cb
BLAKE2b-256 checksum
How to use checksums
48be8153f9c540538f6a2fadca9d7aa2e583f45c7458e72ee820e258c1f14d72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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